@vaadin/a11y-base 25.0.0-alpha17 → 25.0.0-alpha18

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": "25.0.0-alpha17",
3
+ "version": "25.0.0-alpha18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -31,14 +31,14 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@open-wc/dedupe-mixin": "^1.3.0",
34
- "@vaadin/component-base": "25.0.0-alpha17",
34
+ "@vaadin/component-base": "25.0.0-alpha18",
35
35
  "lit": "^3.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@vaadin/chai-plugins": "25.0.0-alpha17",
39
- "@vaadin/test-runner-commands": "25.0.0-alpha17",
38
+ "@vaadin/chai-plugins": "25.0.0-alpha18",
39
+ "@vaadin/test-runner-commands": "25.0.0-alpha18",
40
40
  "@vaadin/testing-helpers": "^2.0.0",
41
41
  "sinon": "^21.0.0"
42
42
  },
43
- "gitHead": "8264c71309907be99368b09414f0f8d7f591e0b9"
43
+ "gitHead": "cb5cafb5687a117ebead1b81e2116991cec13abe"
44
44
  }
@@ -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';
@@ -108,7 +107,12 @@ export const ListMixin = (superClass) =>
108
107
  return this.orientation !== 'horizontal';
109
108
  }
110
109
 
111
- focus() {
110
+ /**
111
+ * @param {FocusOptions=} options
112
+ * @protected
113
+ * @override
114
+ */
115
+ focus(options) {
112
116
  // In initialization (e.g vaadin-select) observer might not been run yet.
113
117
  if (this._observer) {
114
118
  this._observer.flush();
@@ -117,10 +121,10 @@ export const ListMixin = (superClass) =>
117
121
  const items = Array.isArray(this.items) ? this.items : [];
118
122
  const idx = this._getAvailableIndex(items, 0, null, (item) => item.tabIndex === 0 && !isElementHidden(item));
119
123
  if (idx >= 0) {
120
- this._focus(idx);
124
+ this._focus(idx, options);
121
125
  } else {
122
126
  // Call `KeyboardDirectionMixin` logic to focus first non-disabled item.
123
- super.focus();
127
+ super.focus(options);
124
128
  }
125
129
  }
126
130
 
@@ -132,7 +136,7 @@ export const ListMixin = (superClass) =>
132
136
 
133
137
  const slot = this.shadowRoot.querySelector('slot:not([name])');
134
138
  this._observer = new SlotObserver(slot, () => {
135
- this._setItems(this._filterItems(getFlattenedElements(this)));
139
+ this._setItems(this._filterItems([...this.children]));
136
140
  });
137
141
  }
138
142
 
@@ -276,13 +280,13 @@ export const ListMixin = (superClass) =>
276
280
  * @param {number} idx
277
281
  * @protected
278
282
  */
279
- _focus(idx) {
283
+ _focus(idx, options) {
280
284
  this.items.forEach((e, index) => {
281
285
  e.focused = index === idx;
282
286
  });
283
287
  this._setFocusable(idx);
284
288
  this._scrollToItem(idx);
285
- super._focus(idx);
289
+ super._focus(idx, options);
286
290
  }
287
291
 
288
292
  /**
@@ -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