@vaadin/component-base 24.0.0-rc2 → 24.1.0-alpha1
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/index.d.ts +1 -6
- package/index.js +2 -6
- package/package.json +2 -2
- package/src/element-mixin.js +1 -1
- package/src/a11y-announcer.d.ts +0 -10
- package/src/a11y-announcer.js +0 -47
- package/src/active-mixin.d.ts +0 -41
- package/src/active-mixin.js +0 -106
- package/src/delegate-focus-mixin.d.ts +0 -48
- package/src/delegate-focus-mixin.js +0 -228
- package/src/disabled-mixin.d.ts +0 -20
- package/src/disabled-mixin.js +0 -62
- package/src/focus-mixin.d.ts +0 -30
- package/src/focus-mixin.js +0 -93
- package/src/focus-trap-controller.d.ts +0 -39
- package/src/focus-trap-controller.js +0 -155
- package/src/focus-utils.d.ts +0 -51
- package/src/focus-utils.js +0 -260
- package/src/keyboard-direction-mixin.d.ts +0 -41
- package/src/keyboard-direction-mixin.js +0 -192
- package/src/keyboard-mixin.d.ts +0 -40
- package/src/keyboard-mixin.js +0 -85
- package/src/list-mixin.d.ts +0 -57
- package/src/list-mixin.js +0 -354
- package/src/tabindex-mixin.d.ts +0 -36
- package/src/tabindex-mixin.js +0 -78
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2022 - 2023 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import { isElementFocused, isElementHidden } from './focus-utils.js';
|
|
7
|
-
import { KeyboardMixin } from './keyboard-mixin.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A mixin for navigating items with keyboard.
|
|
11
|
-
*
|
|
12
|
-
* @polymerMixin
|
|
13
|
-
* @mixes KeyboardMixin
|
|
14
|
-
*/
|
|
15
|
-
export const KeyboardDirectionMixin = (superclass) =>
|
|
16
|
-
class KeyboardDirectionMixinClass extends KeyboardMixin(superclass) {
|
|
17
|
-
/**
|
|
18
|
-
* @return {Element | null}
|
|
19
|
-
* @protected
|
|
20
|
-
*/
|
|
21
|
-
get focused() {
|
|
22
|
-
return (this._getItems() || []).find(isElementFocused);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @return {boolean}
|
|
27
|
-
* @protected
|
|
28
|
-
*/
|
|
29
|
-
get _vertical() {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** @protected */
|
|
34
|
-
focus() {
|
|
35
|
-
const items = this._getItems();
|
|
36
|
-
if (Array.isArray(items)) {
|
|
37
|
-
const idx = this._getAvailableIndex(items, 0, null, (item) => !isElementHidden(item));
|
|
38
|
-
if (idx >= 0) {
|
|
39
|
-
items[idx].focus();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get the list of items participating in keyboard navigation.
|
|
46
|
-
* By default, it treats all the light DOM children as items.
|
|
47
|
-
* Override this method to provide custom list of elements.
|
|
48
|
-
*
|
|
49
|
-
* @return {Element[]}
|
|
50
|
-
* @protected
|
|
51
|
-
*/
|
|
52
|
-
_getItems() {
|
|
53
|
-
return Array.from(this.children);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Override an event listener from `KeyboardMixin`.
|
|
58
|
-
*
|
|
59
|
-
* @param {!KeyboardEvent} event
|
|
60
|
-
* @protected
|
|
61
|
-
* @override
|
|
62
|
-
*/
|
|
63
|
-
_onKeyDown(event) {
|
|
64
|
-
super._onKeyDown(event);
|
|
65
|
-
|
|
66
|
-
if (event.metaKey || event.ctrlKey) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const { key } = event;
|
|
71
|
-
const items = this._getItems() || [];
|
|
72
|
-
const currentIdx = items.indexOf(this.focused);
|
|
73
|
-
|
|
74
|
-
let idx;
|
|
75
|
-
let increment;
|
|
76
|
-
|
|
77
|
-
const isRTL = !this._vertical && this.getAttribute('dir') === 'rtl';
|
|
78
|
-
const dirIncrement = isRTL ? -1 : 1;
|
|
79
|
-
|
|
80
|
-
if (this.__isPrevKey(key)) {
|
|
81
|
-
increment = -dirIncrement;
|
|
82
|
-
idx = currentIdx - dirIncrement;
|
|
83
|
-
} else if (this.__isNextKey(key)) {
|
|
84
|
-
increment = dirIncrement;
|
|
85
|
-
idx = currentIdx + dirIncrement;
|
|
86
|
-
} else if (key === 'Home') {
|
|
87
|
-
increment = 1;
|
|
88
|
-
idx = 0;
|
|
89
|
-
} else if (key === 'End') {
|
|
90
|
-
increment = -1;
|
|
91
|
-
idx = items.length - 1;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
idx = this._getAvailableIndex(items, idx, increment, (item) => !isElementHidden(item));
|
|
95
|
-
|
|
96
|
-
if (idx >= 0) {
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
this._focus(idx, true);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @param {string} key
|
|
104
|
-
* @return {boolean}
|
|
105
|
-
* @private
|
|
106
|
-
*/
|
|
107
|
-
__isPrevKey(key) {
|
|
108
|
-
return this._vertical ? key === 'ArrowUp' : key === 'ArrowLeft';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @param {string} key
|
|
113
|
-
* @return {boolean}
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
__isNextKey(key) {
|
|
117
|
-
return this._vertical ? key === 'ArrowDown' : key === 'ArrowRight';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Focus the item at given index. Override this method to add custom logic.
|
|
122
|
-
*
|
|
123
|
-
* @param {number} index
|
|
124
|
-
* @param {boolean} navigating
|
|
125
|
-
* @protected
|
|
126
|
-
*/
|
|
127
|
-
_focus(index, navigating = false) {
|
|
128
|
-
const items = this._getItems();
|
|
129
|
-
|
|
130
|
-
this._focusItem(items[index], navigating);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Focus the given item. Override this method to add custom logic.
|
|
135
|
-
*
|
|
136
|
-
* @param {Element} item
|
|
137
|
-
* @param {boolean} navigating
|
|
138
|
-
* @protected
|
|
139
|
-
*/
|
|
140
|
-
_focusItem(item) {
|
|
141
|
-
if (item) {
|
|
142
|
-
item.focus();
|
|
143
|
-
|
|
144
|
-
// Generally, the items are expected to implement `FocusMixin`
|
|
145
|
-
// that would set this attribute based on the `keydown` event.
|
|
146
|
-
// We set it manually to handle programmatic focus() calls.
|
|
147
|
-
item.setAttribute('focus-ring', '');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Returns index of the next item that satisfies the given condition,
|
|
153
|
-
* based on the index of the current item and a numeric increment.
|
|
154
|
-
*
|
|
155
|
-
* @param {Element[]} items - array of items to iterate over
|
|
156
|
-
* @param {number} index - index of the current item
|
|
157
|
-
* @param {number} increment - numeric increment, can be either 1 or -1
|
|
158
|
-
* @param {Function} condition - function used to check the item
|
|
159
|
-
* @return {number}
|
|
160
|
-
* @protected
|
|
161
|
-
*/
|
|
162
|
-
_getAvailableIndex(items, index, increment, condition) {
|
|
163
|
-
const totalItems = items.length;
|
|
164
|
-
let idx = index;
|
|
165
|
-
for (let i = 0; typeof idx === 'number' && i < totalItems; i += 1, idx += increment || 1) {
|
|
166
|
-
if (idx < 0) {
|
|
167
|
-
idx = totalItems - 1;
|
|
168
|
-
} else if (idx >= totalItems) {
|
|
169
|
-
idx = 0;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const item = items[idx];
|
|
173
|
-
|
|
174
|
-
if (!item.hasAttribute('disabled') && this.__isMatchingItem(item, condition)) {
|
|
175
|
-
return idx;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return -1;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Returns true if the item matches condition.
|
|
183
|
-
*
|
|
184
|
-
* @param {Element} item - item to check
|
|
185
|
-
* @param {Function} condition - function used to check the item
|
|
186
|
-
* @return {number}
|
|
187
|
-
* @private
|
|
188
|
-
*/
|
|
189
|
-
__isMatchingItem(item, condition) {
|
|
190
|
-
return typeof condition === 'function' ? condition(item) : true;
|
|
191
|
-
}
|
|
192
|
-
};
|
package/src/keyboard-mixin.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin that manages keyboard handling.
|
|
10
|
-
* The mixin subscribes to the keyboard events while an actual implementation
|
|
11
|
-
* for the event handlers is left to the client (a component or another mixin).
|
|
12
|
-
*/
|
|
13
|
-
export declare function KeyboardMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<KeyboardMixinClass> & T;
|
|
14
|
-
|
|
15
|
-
export declare class KeyboardMixinClass {
|
|
16
|
-
/**
|
|
17
|
-
* A handler for the "Enter" key. By default, it does nothing.
|
|
18
|
-
* Override the method to implement your own behavior.
|
|
19
|
-
*/
|
|
20
|
-
protected _onEnter(event: KeyboardEvent): void;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A handler for the "Escape" key. By default, it does nothing.
|
|
24
|
-
* Override the method to implement your own behavior.
|
|
25
|
-
*/
|
|
26
|
-
protected _onEscape(event: KeyboardEvent): void;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A handler for the `keydown` event. By default, it calls
|
|
30
|
-
* separate methods for handling "Enter" and "Escape" keys.
|
|
31
|
-
* Override the method to implement your own behavior.
|
|
32
|
-
*/
|
|
33
|
-
protected _onKeyDown(event: KeyboardEvent): void;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* A handler for the `keyup` event. By default, it does nothing.
|
|
37
|
-
* Override the method to implement your own behavior.
|
|
38
|
-
*/
|
|
39
|
-
protected _onKeyUp(event: KeyboardEvent): void;
|
|
40
|
-
}
|
package/src/keyboard-mixin.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin that manages keyboard handling.
|
|
10
|
-
* The mixin subscribes to the keyboard events while an actual implementation
|
|
11
|
-
* for the event handlers is left to the client (a component or another mixin).
|
|
12
|
-
*
|
|
13
|
-
* @polymerMixin
|
|
14
|
-
*/
|
|
15
|
-
export const KeyboardMixin = dedupingMixin(
|
|
16
|
-
(superclass) =>
|
|
17
|
-
class KeyboardMixinClass extends superclass {
|
|
18
|
-
/** @protected */
|
|
19
|
-
ready() {
|
|
20
|
-
super.ready();
|
|
21
|
-
|
|
22
|
-
this.addEventListener('keydown', (event) => {
|
|
23
|
-
this._onKeyDown(event);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
this.addEventListener('keyup', (event) => {
|
|
27
|
-
this._onKeyUp(event);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A handler for the `keydown` event. By default, it calls
|
|
33
|
-
* separate methods for handling "Enter" and "Escape" keys.
|
|
34
|
-
* Override the method to implement your own behavior.
|
|
35
|
-
*
|
|
36
|
-
* @param {KeyboardEvent} event
|
|
37
|
-
* @protected
|
|
38
|
-
*/
|
|
39
|
-
_onKeyDown(event) {
|
|
40
|
-
switch (event.key) {
|
|
41
|
-
case 'Enter':
|
|
42
|
-
this._onEnter(event);
|
|
43
|
-
break;
|
|
44
|
-
case 'Escape':
|
|
45
|
-
this._onEscape(event);
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A handler for the `keyup` event. By default, it does nothing.
|
|
54
|
-
* Override the method to implement your own behavior.
|
|
55
|
-
*
|
|
56
|
-
* @param {KeyboardEvent} _event
|
|
57
|
-
* @protected
|
|
58
|
-
*/
|
|
59
|
-
_onKeyUp(_event) {
|
|
60
|
-
// To be implemented.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* A handler for the "Enter" key. By default, it does nothing.
|
|
65
|
-
* Override the method to implement your own behavior.
|
|
66
|
-
*
|
|
67
|
-
* @param {KeyboardEvent} _event
|
|
68
|
-
* @protected
|
|
69
|
-
*/
|
|
70
|
-
_onEnter(_event) {
|
|
71
|
-
// To be implemented.
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* A handler for the "Escape" key. By default, it does nothing.
|
|
76
|
-
* Override the method to implement your own behavior.
|
|
77
|
-
*
|
|
78
|
-
* @param {KeyboardEvent} _event
|
|
79
|
-
* @protected
|
|
80
|
-
*/
|
|
81
|
-
_onEscape(_event) {
|
|
82
|
-
// To be implemented.
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
);
|
package/src/list-mixin.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2017 - 2023 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
-
import type { KeyboardDirectionMixinClass } from './keyboard-direction-mixin.js';
|
|
8
|
-
import type { KeyboardMixinClass } from './keyboard-mixin.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A mixin for list elements, facilitating navigation and selection of items.
|
|
12
|
-
*/
|
|
13
|
-
export declare function ListMixin<T extends Constructor<HTMLElement>>(
|
|
14
|
-
base: T,
|
|
15
|
-
): Constructor<KeyboardDirectionMixinClass> & Constructor<KeyboardMixinClass> & Constructor<ListMixinClass> & T;
|
|
16
|
-
|
|
17
|
-
export declare class ListMixinClass {
|
|
18
|
-
/**
|
|
19
|
-
* Used for mixin detection because `instanceof` does not work with mixins.
|
|
20
|
-
*/
|
|
21
|
-
_hasVaadinListMixin: boolean;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* If true, the user cannot interact with this element.
|
|
25
|
-
* When the element is disabled, the selected item is
|
|
26
|
-
* not updated when `selected` property is changed.
|
|
27
|
-
*/
|
|
28
|
-
disabled: boolean;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The index of the item selected in the items array.
|
|
32
|
-
* Note: Not updated when used in `multiple` selection mode.
|
|
33
|
-
*/
|
|
34
|
-
selected: number | null | undefined;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Define how items are disposed in the dom.
|
|
38
|
-
* Possible values are: `horizontal|vertical`.
|
|
39
|
-
* It also changes navigation keys from left/right to up/down.
|
|
40
|
-
*/
|
|
41
|
-
orientation: 'horizontal' | 'vertical';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The list of items from which a selection can be made.
|
|
45
|
-
* It is populated from the elements passed to the light DOM,
|
|
46
|
-
* and updated dynamically when adding or removing items.
|
|
47
|
-
*
|
|
48
|
-
* The item elements must implement `Vaadin.ItemMixin`.
|
|
49
|
-
*
|
|
50
|
-
* Note: unlike `<vaadin-combo-box>`, this property is read-only,
|
|
51
|
-
* so if you want to provide items by iterating array of data,
|
|
52
|
-
* you have to use `dom-repeat` and place it to the light DOM.
|
|
53
|
-
*/
|
|
54
|
-
readonly items: Element[] | undefined;
|
|
55
|
-
|
|
56
|
-
protected readonly _scrollerElement: HTMLElement;
|
|
57
|
-
}
|