@vaadin/a11y-base 24.9.0-beta1 → 24.9.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/a11y-base",
3
- "version": "24.9.0-beta1",
3
+ "version": "24.9.0-rc1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,14 +32,14 @@
32
32
  "dependencies": {
33
33
  "@open-wc/dedupe-mixin": "^1.3.0",
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/component-base": "24.9.0-beta1",
35
+ "@vaadin/component-base": "24.9.0-rc1",
36
36
  "lit": "^3.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@vaadin/chai-plugins": "24.9.0-beta1",
40
- "@vaadin/test-runner-commands": "24.9.0-beta1",
39
+ "@vaadin/chai-plugins": "24.9.0-rc1",
40
+ "@vaadin/test-runner-commands": "24.9.0-rc1",
41
41
  "@vaadin/testing-helpers": "^1.1.0",
42
42
  "sinon": "^18.0.0"
43
43
  },
44
- "gitHead": "5f6e6e33217fef06e5d5cc52baa4d760969ef1e4"
44
+ "gitHead": "cfe9424405716297d9f1eee425d5a059b2f636f8"
45
45
  }
@@ -73,18 +73,24 @@ export const DelegateFocusMixin = dedupeMixin(
73
73
  if (this.autofocus && !this.disabled) {
74
74
  requestAnimationFrame(() => {
75
75
  this.focus();
76
- this.setAttribute('focus-ring', '');
77
76
  });
78
77
  }
79
78
  }
80
79
 
81
80
  /**
81
+ * @param {FocusOptions=} options
82
82
  * @protected
83
83
  * @override
84
84
  */
85
- focus() {
85
+ focus(options) {
86
86
  if (this.focusElement && !this.disabled) {
87
87
  this.focusElement.focus();
88
+
89
+ // Set focus-ring attribute on programmatic focus by default
90
+ // unless explicitly disabled by `{ focusVisible: false }`.
91
+ if (!(options && options.focusVisible === false)) {
92
+ this.setAttribute('focus-ring', '');
93
+ }
88
94
  }
89
95
  }
90
96
 
@@ -54,6 +54,21 @@ export const FocusMixin = dedupeMixin(
54
54
  }
55
55
  }
56
56
 
57
+ /**
58
+ * @param {FocusOptions=} options
59
+ * @protected
60
+ * @override
61
+ */
62
+ focus(options) {
63
+ super.focus(options);
64
+
65
+ // Set focus-ring attribute on programmatic focus by default
66
+ // unless explicitly disabled by `{ focusVisible: false }`.
67
+ if (!(options && options.focusVisible === false)) {
68
+ this.setAttribute('focus-ring', '');
69
+ }
70
+ }
71
+
57
72
  /**
58
73
  * Override to change how focused and focus-ring attributes are set.
59
74
  *
@@ -32,12 +32,12 @@ export declare class KeyboardDirectionMixinClass {
32
32
  /**
33
33
  * Focus the item at given index. Override this method to add custom logic.
34
34
  */
35
- protected _focus(index: number, navigating: boolean): void;
35
+ protected _focus(index: number, options: FocusOptions, navigating: boolean): void;
36
36
 
37
37
  /**
38
38
  * Focus the given item. Override this method to add custom logic.
39
39
  */
40
- protected _focusItem(item: Element, navigating: boolean): void;
40
+ protected _focusItem(item: Element, options: FocusOptions, navigating: boolean): void;
41
41
 
42
42
  /**
43
43
  * Returns whether the item is focusable. By default,
@@ -38,13 +38,17 @@ export const KeyboardDirectionMixin = (superclass) =>
38
38
  return false;
39
39
  }
40
40
 
41
- /** @protected */
42
- focus() {
41
+ /**
42
+ * @param {FocusOptions=} options
43
+ * @protected
44
+ * @override
45
+ */
46
+ focus(options) {
43
47
  const items = this._getItems();
44
48
  if (Array.isArray(items)) {
45
49
  const idx = this._getAvailableIndex(items, 0, null, (item) => !isElementHidden(item));
46
50
  if (idx >= 0) {
47
- this._focus(idx);
51
+ this._focus(idx, options);
48
52
  }
49
53
  }
50
54
  }
@@ -114,7 +118,7 @@ export const KeyboardDirectionMixin = (superclass) =>
114
118
 
115
119
  if (idx >= 0) {
116
120
  event.preventDefault();
117
- this._focus(idx, true);
121
+ this._focus(idx, { focusVisible: true }, true);
118
122
  }
119
123
  }
120
124
 
@@ -150,30 +154,27 @@ export const KeyboardDirectionMixin = (superclass) =>
150
154
  * Focus the item at given index. Override this method to add custom logic.
151
155
  *
152
156
  * @param {number} index
157
+ * @param {FocusOptions=} options
153
158
  * @param {boolean} navigating
154
159
  * @protected
155
160
  */
156
- _focus(index, navigating = false) {
161
+ _focus(index, options, navigating = false) {
157
162
  const items = this._getItems();
158
163
 
159
- this._focusItem(items[index], navigating);
164
+ this._focusItem(items[index], options, navigating);
160
165
  }
161
166
 
162
167
  /**
163
168
  * Focus the given item. Override this method to add custom logic.
164
169
  *
165
170
  * @param {Element} item
171
+ * @param {FocusOptions=} options
166
172
  * @param {boolean} navigating
167
173
  * @protected
168
174
  */
169
- _focusItem(item) {
175
+ _focusItem(item, options) {
170
176
  if (item) {
171
- item.focus();
172
-
173
- // Generally, the items are expected to implement `FocusMixin`
174
- // that would set this attribute based on the `keydown` event.
175
- // We set it manually to handle programmatic focus() calls.
176
- item.setAttribute('focus-ring', '');
177
+ item.focus(options);
177
178
  }
178
179
  }
179
180
 
package/src/list-mixin.js CHANGED
@@ -6,7 +6,6 @@
6
6
  import { timeOut } from '@vaadin/component-base/src/async.js';
7
7
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
8
  import { getNormalizedScrollLeft, setNormalizedScrollLeft } from '@vaadin/component-base/src/dir-utils.js';
9
- import { getFlattenedElements } from '@vaadin/component-base/src/dom-utils.js';
10
9
  import { SlotObserver } from '@vaadin/component-base/src/slot-observer.js';
11
10
  import { isElementHidden } from './focus-utils.js';
12
11
  import { KeyboardDirectionMixin } from './keyboard-direction-mixin.js';
@@ -114,7 +113,12 @@ export const ListMixin = (superClass) =>
114
113
  return this.orientation !== 'horizontal';
115
114
  }
116
115
 
117
- focus() {
116
+ /**
117
+ * @param {FocusOptions=} options
118
+ * @protected
119
+ * @override
120
+ */
121
+ focus(options) {
118
122
  // In initialization (e.g vaadin-select) observer might not been run yet.
119
123
  if (this._observer) {
120
124
  this._observer.flush();
@@ -123,10 +127,10 @@ export const ListMixin = (superClass) =>
123
127
  const items = Array.isArray(this.items) ? this.items : [];
124
128
  const idx = this._getAvailableIndex(items, 0, null, (item) => item.tabIndex === 0 && !isElementHidden(item));
125
129
  if (idx >= 0) {
126
- this._focus(idx);
130
+ this._focus(idx, options);
127
131
  } else {
128
132
  // Call `KeyboardDirectionMixin` logic to focus first non-disabled item.
129
- super.focus();
133
+ super.focus(options);
130
134
  }
131
135
  }
132
136
 
@@ -138,7 +142,7 @@ export const ListMixin = (superClass) =>
138
142
 
139
143
  const slot = this.shadowRoot.querySelector('slot:not([name])');
140
144
  this._observer = new SlotObserver(slot, () => {
141
- this._setItems(this._filterItems(getFlattenedElements(this)));
145
+ this._setItems(this._filterItems([...this.children]));
142
146
  });
143
147
  }
144
148
 
@@ -282,13 +286,13 @@ export const ListMixin = (superClass) =>
282
286
  * @param {number} idx
283
287
  * @protected
284
288
  */
285
- _focus(idx) {
289
+ _focus(idx, options) {
286
290
  this.items.forEach((e, index) => {
287
291
  e.focused = index === idx;
288
292
  });
289
293
  this._setFocusable(idx);
290
294
  this._scrollToItem(idx);
291
- super._focus(idx);
295
+ super._focus(idx, options);
292
296
  }
293
297
 
294
298
  /**
@@ -95,12 +95,13 @@ export const TabindexMixin = (superclass) =>
95
95
  * `tabindex` to -1 does not prevent the element from being
96
96
  * programmatically focusable.
97
97
  *
98
+ * @param {FocusOptions=} options
98
99
  * @protected
99
100
  * @override
100
101
  */
101
- focus() {
102
+ focus(options) {
102
103
  if (!this.disabled || this.__shouldAllowFocusWhenDisabled()) {
103
- super.focus();
104
+ super.focus(options);
104
105
  }
105
106
  }
106
107