@angular/cdk 21.0.0-next.8 → 21.0.0-rc.0
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/_adev_assets/cdk_drag_drop.json +13 -12
- package/_adev_assets/cdk_testing.json +15 -25
- package/_adev_assets/cdk_testing_protractor.json +1 -1
- package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
- package/_adev_assets/cdk_testing_testbed.json +1 -1
- package/fesm2022/_a11y-module-chunk.mjs +755 -869
- package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
- package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
- package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_array-chunk.mjs +1 -1
- package/fesm2022/_array-chunk.mjs.map +1 -1
- package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
- package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
- package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
- package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
- package/fesm2022/_data-source-chunk.mjs +2 -8
- package/fesm2022/_data-source-chunk.mjs.map +1 -1
- package/fesm2022/_directionality-chunk.mjs +54 -54
- package/fesm2022/_directionality-chunk.mjs.map +1 -1
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_element-chunk.mjs +6 -17
- package/fesm2022/_element-chunk.mjs.map +1 -1
- package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
- package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
- package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
- package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_focus-monitor-chunk.mjs +376 -566
- package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
- package/fesm2022/_id-generator-chunk.mjs +36 -27
- package/fesm2022/_id-generator-chunk.mjs.map +1 -1
- package/fesm2022/_keycodes-chunk.mjs +9 -9
- package/fesm2022/_keycodes-chunk.mjs.map +1 -1
- package/fesm2022/_list-key-manager-chunk.mjs +248 -336
- package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_overlay-module-chunk.mjs +2534 -2948
- package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
- package/fesm2022/_passive-listeners-chunk.mjs +10 -22
- package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
- package/fesm2022/_platform-chunk.mjs +42 -65
- package/fesm2022/_platform-chunk.mjs.map +1 -1
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_scrolling-chunk.mjs +44 -85
- package/fesm2022/_scrolling-chunk.mjs.map +1 -1
- package/fesm2022/_selection-model-chunk.mjs +138 -209
- package/fesm2022/_selection-model-chunk.mjs.map +1 -1
- package/fesm2022/_shadow-dom-chunk.mjs +21 -35
- package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
- package/fesm2022/_style-loader-chunk.mjs +50 -37
- package/fesm2022/_style-loader-chunk.mjs.map +1 -1
- package/fesm2022/_test-environment-chunk.mjs +2 -14
- package/fesm2022/_test-environment-chunk.mjs.map +1 -1
- package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
- package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_typeahead-chunk.mjs +52 -74
- package/fesm2022/_typeahead-chunk.mjs.map +1 -1
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
- package/fesm2022/a11y.mjs +351 -449
- package/fesm2022/a11y.mjs.map +1 -1
- package/fesm2022/accordion.mjs +254 -192
- package/fesm2022/accordion.mjs.map +1 -1
- package/fesm2022/bidi.mjs +121 -64
- package/fesm2022/bidi.mjs.map +1 -1
- package/fesm2022/cdk.mjs +1 -2
- package/fesm2022/cdk.mjs.map +1 -1
- package/fesm2022/clipboard.mjs +208 -186
- package/fesm2022/clipboard.mjs.map +1 -1
- package/fesm2022/coercion-private.mjs +4 -8
- package/fesm2022/coercion-private.mjs.map +1 -1
- package/fesm2022/coercion.mjs +11 -29
- package/fesm2022/coercion.mjs.map +1 -1
- package/fesm2022/dialog.mjs +660 -808
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/drag-drop.mjs +3347 -4286
- package/fesm2022/drag-drop.mjs.map +1 -1
- package/fesm2022/keycodes.mjs +4 -8
- package/fesm2022/keycodes.mjs.map +1 -1
- package/fesm2022/layout.mjs +44 -26
- package/fesm2022/layout.mjs.map +1 -1
- package/fesm2022/listbox.mjs +841 -895
- package/fesm2022/listbox.mjs.map +1 -1
- package/fesm2022/menu.mjs +1942 -1858
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/observers-private.mjs +88 -106
- package/fesm2022/observers-private.mjs.map +1 -1
- package/fesm2022/observers.mjs +262 -184
- package/fesm2022/observers.mjs.map +1 -1
- package/fesm2022/overlay.mjs +72 -68
- package/fesm2022/overlay.mjs.map +1 -1
- package/fesm2022/platform.mjs +43 -54
- package/fesm2022/platform.mjs.map +1 -1
- package/fesm2022/portal.mjs +402 -560
- package/fesm2022/portal.mjs.map +1 -1
- package/fesm2022/private.mjs +38 -10
- package/fesm2022/private.mjs.map +1 -1
- package/fesm2022/scrolling.mjs +1323 -1400
- package/fesm2022/scrolling.mjs.map +1 -1
- package/fesm2022/stepper.mjs +758 -590
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/table.mjs +2327 -2319
- package/fesm2022/table.mjs.map +1 -1
- package/fesm2022/testing-selenium-webdriver.mjs +252 -325
- package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
- package/fesm2022/testing-testbed.mjs +592 -709
- package/fesm2022/testing-testbed.mjs.map +1 -1
- package/fesm2022/testing.mjs +368 -889
- package/fesm2022/testing.mjs.map +1 -1
- package/fesm2022/text-field.mjs +459 -388
- package/fesm2022/text-field.mjs.map +1 -1
- package/fesm2022/tree.mjs +1483 -1731
- package/fesm2022/tree.mjs.map +1 -1
- package/overlay/_index.scss +28 -0
- package/overlay-prebuilt.css +1 -1
- package/package.json +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/types/_harness-environment-chunk.d.ts +1 -2
- package/types/_overlay-module-chunk.d.ts +59 -7
- package/types/_portal-directives-chunk.d.ts +2 -18
- package/types/accordion.d.ts +3 -1
- package/types/dialog.d.ts +1 -1
- package/types/overlay.d.ts +6 -2
- package/types/portal.d.ts +1 -1
|
@@ -4,356 +4,268 @@ import { Typeahead } from './_typeahead-chunk.mjs';
|
|
|
4
4
|
import { hasModifierKey } from './keycodes.mjs';
|
|
5
5
|
import { PAGE_DOWN, PAGE_UP, END, HOME, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, TAB } from './_keycodes-chunk.mjs';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* This class manages keyboard events for selectable lists. If you pass it a query list
|
|
9
|
-
* of items, it will set the active item correctly when arrow events occur.
|
|
10
|
-
*/
|
|
11
7
|
class ListKeyManager {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* when focus is shifted off of the list.
|
|
48
|
-
*/
|
|
49
|
-
tabOut = new Subject();
|
|
50
|
-
/** Stream that emits whenever the active item of the list manager changes. */
|
|
51
|
-
change = new Subject();
|
|
52
|
-
/**
|
|
53
|
-
* Sets the predicate function that determines which items should be skipped by the
|
|
54
|
-
* list key manager.
|
|
55
|
-
* @param predicate Function that determines whether the given item should be skipped.
|
|
56
|
-
*/
|
|
57
|
-
skipPredicate(predicate) {
|
|
58
|
-
this._skipPredicateFn = predicate;
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Configures wrapping mode, which determines whether the active item will wrap to
|
|
63
|
-
* the other end of list when there are no more items in the given direction.
|
|
64
|
-
* @param shouldWrap Whether the list should wrap when reaching the end.
|
|
65
|
-
*/
|
|
66
|
-
withWrap(shouldWrap = true) {
|
|
67
|
-
this._wrap = shouldWrap;
|
|
68
|
-
return this;
|
|
8
|
+
_items;
|
|
9
|
+
_activeItemIndex = signal(-1, ...(ngDevMode ? [{
|
|
10
|
+
debugName: "_activeItemIndex"
|
|
11
|
+
}] : []));
|
|
12
|
+
_activeItem = signal(null, ...(ngDevMode ? [{
|
|
13
|
+
debugName: "_activeItem"
|
|
14
|
+
}] : []));
|
|
15
|
+
_wrap = false;
|
|
16
|
+
_typeaheadSubscription = Subscription.EMPTY;
|
|
17
|
+
_itemChangesSubscription;
|
|
18
|
+
_vertical = true;
|
|
19
|
+
_horizontal;
|
|
20
|
+
_allowedModifierKeys = [];
|
|
21
|
+
_homeAndEnd = false;
|
|
22
|
+
_pageUpAndDown = {
|
|
23
|
+
enabled: false,
|
|
24
|
+
delta: 10
|
|
25
|
+
};
|
|
26
|
+
_effectRef;
|
|
27
|
+
_typeahead;
|
|
28
|
+
_skipPredicateFn = item => item.disabled;
|
|
29
|
+
constructor(_items, injector) {
|
|
30
|
+
this._items = _items;
|
|
31
|
+
if (_items instanceof QueryList) {
|
|
32
|
+
this._itemChangesSubscription = _items.changes.subscribe(newItems => this._itemsChanged(newItems.toArray()));
|
|
33
|
+
} else if (isSignal(_items)) {
|
|
34
|
+
if (!injector && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
35
|
+
throw new Error('ListKeyManager constructed with a signal must receive an injector');
|
|
36
|
+
}
|
|
37
|
+
this._effectRef = effect(() => this._itemsChanged(_items()), ...(ngDevMode ? [{
|
|
38
|
+
debugName: "_effectRef",
|
|
39
|
+
injector
|
|
40
|
+
}] : [{
|
|
41
|
+
injector
|
|
42
|
+
}]));
|
|
69
43
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
44
|
+
}
|
|
45
|
+
tabOut = new Subject();
|
|
46
|
+
change = new Subject();
|
|
47
|
+
skipPredicate(predicate) {
|
|
48
|
+
this._skipPredicateFn = predicate;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
withWrap(shouldWrap = true) {
|
|
52
|
+
this._wrap = shouldWrap;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
withVerticalOrientation(enabled = true) {
|
|
56
|
+
this._vertical = enabled;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
withHorizontalOrientation(direction) {
|
|
60
|
+
this._horizontal = direction;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
withAllowedModifierKeys(keys) {
|
|
64
|
+
this._allowedModifierKeys = keys;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
withTypeAhead(debounceInterval = 200) {
|
|
68
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
69
|
+
const items = this._getItemsArray();
|
|
70
|
+
if (items.length > 0 && items.some(item => typeof item.getLabel !== 'function')) {
|
|
71
|
+
throw Error('ListKeyManager items in typeahead mode must implement the `getLabel` method.');
|
|
72
|
+
}
|
|
77
73
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
this._typeaheadSubscription.unsubscribe();
|
|
75
|
+
const items = this._getItemsArray();
|
|
76
|
+
this._typeahead = new Typeahead(items, {
|
|
77
|
+
debounceInterval: typeof debounceInterval === 'number' ? debounceInterval : undefined,
|
|
78
|
+
skipPredicate: item => this._skipPredicateFn(item)
|
|
79
|
+
});
|
|
80
|
+
this._typeaheadSubscription = this._typeahead.selectedItem.subscribe(item => {
|
|
81
|
+
this.setActiveItem(item);
|
|
82
|
+
});
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
cancelTypeahead() {
|
|
86
|
+
this._typeahead?.reset();
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
withHomeAndEnd(enabled = true) {
|
|
90
|
+
this._homeAndEnd = enabled;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
withPageUpDown(enabled = true, delta = 10) {
|
|
94
|
+
this._pageUpAndDown = {
|
|
95
|
+
enabled,
|
|
96
|
+
delta
|
|
97
|
+
};
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
setActiveItem(item) {
|
|
101
|
+
const previousActiveItem = this._activeItem();
|
|
102
|
+
this.updateActiveItem(item);
|
|
103
|
+
if (this._activeItem() !== previousActiveItem) {
|
|
104
|
+
this.change.next(this._activeItemIndex());
|
|
86
105
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
106
|
+
}
|
|
107
|
+
onKeydown(event) {
|
|
108
|
+
const keyCode = event.keyCode;
|
|
109
|
+
const modifiers = ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'];
|
|
110
|
+
const isModifierAllowed = modifiers.every(modifier => {
|
|
111
|
+
return !event[modifier] || this._allowedModifierKeys.indexOf(modifier) > -1;
|
|
112
|
+
});
|
|
113
|
+
switch (keyCode) {
|
|
114
|
+
case TAB:
|
|
115
|
+
this.tabOut.next();
|
|
116
|
+
return;
|
|
117
|
+
case DOWN_ARROW:
|
|
118
|
+
if (this._vertical && isModifierAllowed) {
|
|
119
|
+
this.setNextItemActive();
|
|
120
|
+
break;
|
|
121
|
+
} else {
|
|
122
|
+
return;
|
|
105
123
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this._typeaheadSubscription = this._typeahead.selectedItem.subscribe(item => {
|
|
113
|
-
this.setActiveItem(item);
|
|
114
|
-
});
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
/** Cancels the current typeahead sequence. */
|
|
118
|
-
cancelTypeahead() {
|
|
119
|
-
this._typeahead?.reset();
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Configures the key manager to activate the first and last items
|
|
124
|
-
* respectively when the Home or End key is pressed.
|
|
125
|
-
* @param enabled Whether pressing the Home or End key activates the first/last item.
|
|
126
|
-
*/
|
|
127
|
-
withHomeAndEnd(enabled = true) {
|
|
128
|
-
this._homeAndEnd = enabled;
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Configures the key manager to activate every 10th, configured or first/last element in up/down direction
|
|
133
|
-
* respectively when the Page-Up or Page-Down key is pressed.
|
|
134
|
-
* @param enabled Whether pressing the Page-Up or Page-Down key activates the first/last item.
|
|
135
|
-
* @param delta Whether pressing the Home or End key activates the first/last item.
|
|
136
|
-
*/
|
|
137
|
-
withPageUpDown(enabled = true, delta = 10) {
|
|
138
|
-
this._pageUpAndDown = { enabled, delta };
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
setActiveItem(item) {
|
|
142
|
-
const previousActiveItem = this._activeItem();
|
|
143
|
-
this.updateActiveItem(item);
|
|
144
|
-
if (this._activeItem() !== previousActiveItem) {
|
|
145
|
-
this.change.next(this._activeItemIndex());
|
|
124
|
+
case UP_ARROW:
|
|
125
|
+
if (this._vertical && isModifierAllowed) {
|
|
126
|
+
this.setPreviousItemActive();
|
|
127
|
+
break;
|
|
128
|
+
} else {
|
|
129
|
+
return;
|
|
146
130
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const keyCode = event.keyCode;
|
|
154
|
-
const modifiers = ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'];
|
|
155
|
-
const isModifierAllowed = modifiers.every(modifier => {
|
|
156
|
-
return !event[modifier] || this._allowedModifierKeys.indexOf(modifier) > -1;
|
|
157
|
-
});
|
|
158
|
-
switch (keyCode) {
|
|
159
|
-
case TAB:
|
|
160
|
-
this.tabOut.next();
|
|
161
|
-
return;
|
|
162
|
-
case DOWN_ARROW:
|
|
163
|
-
if (this._vertical && isModifierAllowed) {
|
|
164
|
-
this.setNextItemActive();
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
case UP_ARROW:
|
|
171
|
-
if (this._vertical && isModifierAllowed) {
|
|
172
|
-
this.setPreviousItemActive();
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
case RIGHT_ARROW:
|
|
179
|
-
if (this._horizontal && isModifierAllowed) {
|
|
180
|
-
this._horizontal === 'rtl' ? this.setPreviousItemActive() : this.setNextItemActive();
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
case LEFT_ARROW:
|
|
187
|
-
if (this._horizontal && isModifierAllowed) {
|
|
188
|
-
this._horizontal === 'rtl' ? this.setNextItemActive() : this.setPreviousItemActive();
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
case HOME:
|
|
195
|
-
if (this._homeAndEnd && isModifierAllowed) {
|
|
196
|
-
this.setFirstItemActive();
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
case END:
|
|
203
|
-
if (this._homeAndEnd && isModifierAllowed) {
|
|
204
|
-
this.setLastItemActive();
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
case PAGE_UP:
|
|
211
|
-
if (this._pageUpAndDown.enabled && isModifierAllowed) {
|
|
212
|
-
const targetIndex = this._activeItemIndex() - this._pageUpAndDown.delta;
|
|
213
|
-
this._setActiveItemByIndex(targetIndex > 0 ? targetIndex : 0, 1);
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
case PAGE_DOWN:
|
|
220
|
-
if (this._pageUpAndDown.enabled && isModifierAllowed) {
|
|
221
|
-
const targetIndex = this._activeItemIndex() + this._pageUpAndDown.delta;
|
|
222
|
-
const itemsLength = this._getItemsArray().length;
|
|
223
|
-
this._setActiveItemByIndex(targetIndex < itemsLength ? targetIndex : itemsLength - 1, -1);
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
default:
|
|
230
|
-
if (isModifierAllowed || hasModifierKey(event, 'shiftKey')) {
|
|
231
|
-
this._typeahead?.handleKey(event);
|
|
232
|
-
}
|
|
233
|
-
// Note that we return here, in order to avoid preventing
|
|
234
|
-
// the default action of non-navigational keys.
|
|
235
|
-
return;
|
|
131
|
+
case RIGHT_ARROW:
|
|
132
|
+
if (this._horizontal && isModifierAllowed) {
|
|
133
|
+
this._horizontal === 'rtl' ? this.setPreviousItemActive() : this.setNextItemActive();
|
|
134
|
+
break;
|
|
135
|
+
} else {
|
|
136
|
+
return;
|
|
236
137
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
/** The active item. */
|
|
245
|
-
get activeItem() {
|
|
246
|
-
return this._activeItem();
|
|
247
|
-
}
|
|
248
|
-
/** Gets whether the user is currently typing into the manager using the typeahead feature. */
|
|
249
|
-
isTyping() {
|
|
250
|
-
return !!this._typeahead && this._typeahead.isTyping();
|
|
251
|
-
}
|
|
252
|
-
/** Sets the active item to the first enabled item in the list. */
|
|
253
|
-
setFirstItemActive() {
|
|
254
|
-
this._setActiveItemByIndex(0, 1);
|
|
255
|
-
}
|
|
256
|
-
/** Sets the active item to the last enabled item in the list. */
|
|
257
|
-
setLastItemActive() {
|
|
258
|
-
this._setActiveItemByIndex(this._getItemsArray().length - 1, -1);
|
|
259
|
-
}
|
|
260
|
-
/** Sets the active item to the next enabled item in the list. */
|
|
261
|
-
setNextItemActive() {
|
|
262
|
-
this._activeItemIndex() < 0 ? this.setFirstItemActive() : this._setActiveItemByDelta(1);
|
|
263
|
-
}
|
|
264
|
-
/** Sets the active item to a previous enabled item in the list. */
|
|
265
|
-
setPreviousItemActive() {
|
|
266
|
-
this._activeItemIndex() < 0 && this._wrap
|
|
267
|
-
? this.setLastItemActive()
|
|
268
|
-
: this._setActiveItemByDelta(-1);
|
|
269
|
-
}
|
|
270
|
-
updateActiveItem(item) {
|
|
271
|
-
const itemArray = this._getItemsArray();
|
|
272
|
-
const index = typeof item === 'number' ? item : itemArray.indexOf(item);
|
|
273
|
-
const activeItem = itemArray[index];
|
|
274
|
-
// Explicitly check for `null` and `undefined` because other falsy values are valid.
|
|
275
|
-
this._activeItem.set(activeItem == null ? null : activeItem);
|
|
276
|
-
this._activeItemIndex.set(index);
|
|
277
|
-
this._typeahead?.setCurrentSelectedItemIndex(index);
|
|
278
|
-
}
|
|
279
|
-
/** Cleans up the key manager. */
|
|
280
|
-
destroy() {
|
|
281
|
-
this._typeaheadSubscription.unsubscribe();
|
|
282
|
-
this._itemChangesSubscription?.unsubscribe();
|
|
283
|
-
this._effectRef?.destroy();
|
|
284
|
-
this._typeahead?.destroy();
|
|
285
|
-
this.tabOut.complete();
|
|
286
|
-
this.change.complete();
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* This method sets the active item, given a list of items and the delta between the
|
|
290
|
-
* currently active item and the new active item. It will calculate differently
|
|
291
|
-
* depending on whether wrap mode is turned on.
|
|
292
|
-
*/
|
|
293
|
-
_setActiveItemByDelta(delta) {
|
|
294
|
-
this._wrap ? this._setActiveInWrapMode(delta) : this._setActiveInDefaultMode(delta);
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Sets the active item properly given "wrap" mode. In other words, it will continue to move
|
|
298
|
-
* down the list until it finds an item that is not disabled, and it will wrap if it
|
|
299
|
-
* encounters either end of the list.
|
|
300
|
-
*/
|
|
301
|
-
_setActiveInWrapMode(delta) {
|
|
302
|
-
const items = this._getItemsArray();
|
|
303
|
-
for (let i = 1; i <= items.length; i++) {
|
|
304
|
-
const index = (this._activeItemIndex() + delta * i + items.length) % items.length;
|
|
305
|
-
const item = items[index];
|
|
306
|
-
if (!this._skipPredicateFn(item)) {
|
|
307
|
-
this.setActiveItem(index);
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
138
|
+
case LEFT_ARROW:
|
|
139
|
+
if (this._horizontal && isModifierAllowed) {
|
|
140
|
+
this._horizontal === 'rtl' ? this.setNextItemActive() : this.setPreviousItemActive();
|
|
141
|
+
break;
|
|
142
|
+
} else {
|
|
143
|
+
return;
|
|
310
144
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
*/
|
|
325
|
-
_setActiveItemByIndex(index, fallbackDelta) {
|
|
326
|
-
const items = this._getItemsArray();
|
|
327
|
-
if (!items[index]) {
|
|
328
|
-
return;
|
|
145
|
+
case HOME:
|
|
146
|
+
if (this._homeAndEnd && isModifierAllowed) {
|
|
147
|
+
this.setFirstItemActive();
|
|
148
|
+
break;
|
|
149
|
+
} else {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
case END:
|
|
153
|
+
if (this._homeAndEnd && isModifierAllowed) {
|
|
154
|
+
this.setLastItemActive();
|
|
155
|
+
break;
|
|
156
|
+
} else {
|
|
157
|
+
return;
|
|
329
158
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
159
|
+
case PAGE_UP:
|
|
160
|
+
if (this._pageUpAndDown.enabled && isModifierAllowed) {
|
|
161
|
+
const targetIndex = this._activeItemIndex() - this._pageUpAndDown.delta;
|
|
162
|
+
this._setActiveItemByIndex(targetIndex > 0 ? targetIndex : 0, 1);
|
|
163
|
+
break;
|
|
164
|
+
} else {
|
|
165
|
+
return;
|
|
335
166
|
}
|
|
167
|
+
case PAGE_DOWN:
|
|
168
|
+
if (this._pageUpAndDown.enabled && isModifierAllowed) {
|
|
169
|
+
const targetIndex = this._activeItemIndex() + this._pageUpAndDown.delta;
|
|
170
|
+
const itemsLength = this._getItemsArray().length;
|
|
171
|
+
this._setActiveItemByIndex(targetIndex < itemsLength ? targetIndex : itemsLength - 1, -1);
|
|
172
|
+
break;
|
|
173
|
+
} else {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
if (isModifierAllowed || hasModifierKey(event, 'shiftKey')) {
|
|
178
|
+
this._typeahead?.handleKey(event);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this._typeahead?.reset();
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
}
|
|
185
|
+
get activeItemIndex() {
|
|
186
|
+
return this._activeItemIndex();
|
|
187
|
+
}
|
|
188
|
+
get activeItem() {
|
|
189
|
+
return this._activeItem();
|
|
190
|
+
}
|
|
191
|
+
isTyping() {
|
|
192
|
+
return !!this._typeahead && this._typeahead.isTyping();
|
|
193
|
+
}
|
|
194
|
+
setFirstItemActive() {
|
|
195
|
+
this._setActiveItemByIndex(0, 1);
|
|
196
|
+
}
|
|
197
|
+
setLastItemActive() {
|
|
198
|
+
this._setActiveItemByIndex(this._getItemsArray().length - 1, -1);
|
|
199
|
+
}
|
|
200
|
+
setNextItemActive() {
|
|
201
|
+
this._activeItemIndex() < 0 ? this.setFirstItemActive() : this._setActiveItemByDelta(1);
|
|
202
|
+
}
|
|
203
|
+
setPreviousItemActive() {
|
|
204
|
+
this._activeItemIndex() < 0 && this._wrap ? this.setLastItemActive() : this._setActiveItemByDelta(-1);
|
|
205
|
+
}
|
|
206
|
+
updateActiveItem(item) {
|
|
207
|
+
const itemArray = this._getItemsArray();
|
|
208
|
+
const index = typeof item === 'number' ? item : itemArray.indexOf(item);
|
|
209
|
+
const activeItem = itemArray[index];
|
|
210
|
+
this._activeItem.set(activeItem == null ? null : activeItem);
|
|
211
|
+
this._activeItemIndex.set(index);
|
|
212
|
+
this._typeahead?.setCurrentSelectedItemIndex(index);
|
|
213
|
+
}
|
|
214
|
+
destroy() {
|
|
215
|
+
this._typeaheadSubscription.unsubscribe();
|
|
216
|
+
this._itemChangesSubscription?.unsubscribe();
|
|
217
|
+
this._effectRef?.destroy();
|
|
218
|
+
this._typeahead?.destroy();
|
|
219
|
+
this.tabOut.complete();
|
|
220
|
+
this.change.complete();
|
|
221
|
+
}
|
|
222
|
+
_setActiveItemByDelta(delta) {
|
|
223
|
+
this._wrap ? this._setActiveInWrapMode(delta) : this._setActiveInDefaultMode(delta);
|
|
224
|
+
}
|
|
225
|
+
_setActiveInWrapMode(delta) {
|
|
226
|
+
const items = this._getItemsArray();
|
|
227
|
+
for (let i = 1; i <= items.length; i++) {
|
|
228
|
+
const index = (this._activeItemIndex() + delta * i + items.length) % items.length;
|
|
229
|
+
const item = items[index];
|
|
230
|
+
if (!this._skipPredicateFn(item)) {
|
|
336
231
|
this.setActiveItem(index);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
337
234
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
235
|
+
}
|
|
236
|
+
_setActiveInDefaultMode(delta) {
|
|
237
|
+
this._setActiveItemByIndex(this._activeItemIndex() + delta, delta);
|
|
238
|
+
}
|
|
239
|
+
_setActiveItemByIndex(index, fallbackDelta) {
|
|
240
|
+
const items = this._getItemsArray();
|
|
241
|
+
if (!items[index]) {
|
|
242
|
+
return;
|
|
344
243
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
244
|
+
while (this._skipPredicateFn(items[index])) {
|
|
245
|
+
index += fallbackDelta;
|
|
246
|
+
if (!items[index]) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
this.setActiveItem(index);
|
|
251
|
+
}
|
|
252
|
+
_getItemsArray() {
|
|
253
|
+
if (isSignal(this._items)) {
|
|
254
|
+
return this._items();
|
|
255
|
+
}
|
|
256
|
+
return this._items instanceof QueryList ? this._items.toArray() : this._items;
|
|
257
|
+
}
|
|
258
|
+
_itemsChanged(newItems) {
|
|
259
|
+
this._typeahead?.setItems(newItems);
|
|
260
|
+
const activeItem = this._activeItem();
|
|
261
|
+
if (activeItem) {
|
|
262
|
+
const newIndex = newItems.indexOf(activeItem);
|
|
263
|
+
if (newIndex > -1 && newIndex !== this._activeItemIndex()) {
|
|
264
|
+
this._activeItemIndex.set(newIndex);
|
|
265
|
+
this._typeahead?.setCurrentSelectedItemIndex(newIndex);
|
|
266
|
+
}
|
|
356
267
|
}
|
|
268
|
+
}
|
|
357
269
|
}
|
|
358
270
|
|
|
359
271
|
export { ListKeyManager };
|