@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
package/fesm2022/listbox.mjs
CHANGED
|
@@ -15,914 +15,860 @@ import './_list-key-manager-chunk.mjs';
|
|
|
15
15
|
import './_typeahead-chunk.mjs';
|
|
16
16
|
import '@angular/common';
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* An implementation of SelectionModel that internally always represents the selection as a
|
|
20
|
-
* multi-selection. This is necessary so that we can recover the full selection if the user
|
|
21
|
-
* switches the listbox from single-selection to multi-selection after initialization.
|
|
22
|
-
*
|
|
23
|
-
* This selection model may report multiple selected values, even if it is in single-selection
|
|
24
|
-
* mode. It is up to the user (CdkListbox) to check for invalid selections.
|
|
25
|
-
*/
|
|
26
18
|
class ListboxSelectionModel extends SelectionModel {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return super.setSelection(...values);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
19
|
+
multiple;
|
|
20
|
+
constructor(multiple = false, initiallySelectedValues, emitChanges = true, compareWith) {
|
|
21
|
+
super(true, initiallySelectedValues, emitChanges, compareWith);
|
|
22
|
+
this.multiple = multiple;
|
|
23
|
+
}
|
|
24
|
+
isMultipleSelection() {
|
|
25
|
+
return this.multiple;
|
|
26
|
+
}
|
|
27
|
+
select(...values) {
|
|
28
|
+
if (this.multiple) {
|
|
29
|
+
return super.select(...values);
|
|
30
|
+
} else {
|
|
31
|
+
return super.setSelection(...values);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
45
34
|
}
|
|
46
|
-
/** A selectable option in a listbox. */
|
|
47
35
|
class CdkOption {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
listbox
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
36
|
+
get id() {
|
|
37
|
+
return this._id || this._generatedId;
|
|
38
|
+
}
|
|
39
|
+
set id(value) {
|
|
40
|
+
this._id = value;
|
|
41
|
+
}
|
|
42
|
+
_id;
|
|
43
|
+
_generatedId = inject(_IdGenerator).getId('cdk-option-');
|
|
44
|
+
value;
|
|
45
|
+
typeaheadLabel;
|
|
46
|
+
get disabled() {
|
|
47
|
+
return this.listbox.disabled || this._disabled();
|
|
48
|
+
}
|
|
49
|
+
set disabled(value) {
|
|
50
|
+
this._disabled.set(value);
|
|
51
|
+
}
|
|
52
|
+
_disabled = signal(false, ...(ngDevMode ? [{
|
|
53
|
+
debugName: "_disabled"
|
|
54
|
+
}] : []));
|
|
55
|
+
get enabledTabIndex() {
|
|
56
|
+
return this._enabledTabIndex() === undefined ? this.listbox.enabledTabIndex : this._enabledTabIndex();
|
|
57
|
+
}
|
|
58
|
+
set enabledTabIndex(value) {
|
|
59
|
+
this._enabledTabIndex.set(value);
|
|
60
|
+
}
|
|
61
|
+
_enabledTabIndex = signal(undefined, ...(ngDevMode ? [{
|
|
62
|
+
debugName: "_enabledTabIndex"
|
|
63
|
+
}] : []));
|
|
64
|
+
element = inject(ElementRef).nativeElement;
|
|
65
|
+
listbox = inject(CdkListbox);
|
|
66
|
+
destroyed = new Subject();
|
|
67
|
+
_clicked = new Subject();
|
|
68
|
+
ngOnDestroy() {
|
|
69
|
+
this.destroyed.next();
|
|
70
|
+
this.destroyed.complete();
|
|
71
|
+
}
|
|
72
|
+
isSelected() {
|
|
73
|
+
return this.listbox.isSelected(this);
|
|
74
|
+
}
|
|
75
|
+
isActive() {
|
|
76
|
+
return this.listbox.isActive(this);
|
|
77
|
+
}
|
|
78
|
+
toggle() {
|
|
79
|
+
this.listbox.toggle(this);
|
|
80
|
+
}
|
|
81
|
+
select() {
|
|
82
|
+
this.listbox.select(this);
|
|
83
|
+
}
|
|
84
|
+
deselect() {
|
|
85
|
+
this.listbox.deselect(this);
|
|
86
|
+
}
|
|
87
|
+
focus() {
|
|
88
|
+
this.element.focus();
|
|
89
|
+
}
|
|
90
|
+
getLabel() {
|
|
91
|
+
return (this.typeaheadLabel ?? this.element.textContent?.trim()) || '';
|
|
92
|
+
}
|
|
93
|
+
setActiveStyles() {
|
|
94
|
+
if (this.listbox.useActiveDescendant) {
|
|
95
|
+
this.element.scrollIntoView({
|
|
96
|
+
block: 'nearest',
|
|
97
|
+
inline: 'nearest'
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
setInactiveStyles() {}
|
|
102
|
+
_handleFocus() {
|
|
103
|
+
if (this.listbox.useActiveDescendant) {
|
|
104
|
+
this.listbox._setActiveOption(this);
|
|
105
|
+
this.listbox.focus();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
_getTabIndex() {
|
|
109
|
+
if (this.listbox.useActiveDescendant || this.disabled) {
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
return this.isActive() ? this.enabledTabIndex : -1;
|
|
113
|
+
}
|
|
114
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
115
|
+
minVersion: "12.0.0",
|
|
116
|
+
version: "20.2.0-next.2",
|
|
117
|
+
ngImport: i0,
|
|
118
|
+
type: CdkOption,
|
|
119
|
+
deps: [],
|
|
120
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
121
|
+
});
|
|
122
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
123
|
+
minVersion: "16.1.0",
|
|
124
|
+
version: "20.2.0-next.2",
|
|
125
|
+
type: CdkOption,
|
|
126
|
+
isStandalone: true,
|
|
127
|
+
selector: "[cdkOption]",
|
|
128
|
+
inputs: {
|
|
129
|
+
id: "id",
|
|
130
|
+
value: ["cdkOption", "value"],
|
|
131
|
+
typeaheadLabel: ["cdkOptionTypeaheadLabel", "typeaheadLabel"],
|
|
132
|
+
disabled: ["cdkOptionDisabled", "disabled", booleanAttribute],
|
|
133
|
+
enabledTabIndex: ["tabindex", "enabledTabIndex", value => value == null ? undefined : numberAttribute(value)]
|
|
134
|
+
},
|
|
135
|
+
host: {
|
|
136
|
+
attributes: {
|
|
137
|
+
"role": "option"
|
|
138
|
+
},
|
|
139
|
+
listeners: {
|
|
140
|
+
"click": "_clicked.next($event)",
|
|
141
|
+
"focus": "_handleFocus()"
|
|
142
|
+
},
|
|
143
|
+
properties: {
|
|
144
|
+
"id": "id",
|
|
145
|
+
"attr.aria-selected": "isSelected()",
|
|
146
|
+
"attr.tabindex": "_getTabIndex()",
|
|
147
|
+
"attr.aria-disabled": "disabled",
|
|
148
|
+
"class.cdk-option-active": "isActive()"
|
|
149
|
+
},
|
|
150
|
+
classAttribute: "cdk-option"
|
|
151
|
+
},
|
|
152
|
+
exportAs: ["cdkOption"],
|
|
153
|
+
ngImport: i0
|
|
154
|
+
});
|
|
157
155
|
}
|
|
158
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
156
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
157
|
+
minVersion: "12.0.0",
|
|
158
|
+
version: "20.2.0-next.2",
|
|
159
|
+
ngImport: i0,
|
|
160
|
+
type: CdkOption,
|
|
161
|
+
decorators: [{
|
|
162
|
+
type: Directive,
|
|
163
|
+
args: [{
|
|
164
|
+
selector: '[cdkOption]',
|
|
165
|
+
exportAs: 'cdkOption',
|
|
166
|
+
host: {
|
|
167
|
+
'role': 'option',
|
|
168
|
+
'class': 'cdk-option',
|
|
169
|
+
'[id]': 'id',
|
|
170
|
+
'[attr.aria-selected]': 'isSelected()',
|
|
171
|
+
'[attr.tabindex]': '_getTabIndex()',
|
|
172
|
+
'[attr.aria-disabled]': 'disabled',
|
|
173
|
+
'[class.cdk-option-active]': 'isActive()',
|
|
174
|
+
'(click)': '_clicked.next($event)',
|
|
175
|
+
'(focus)': '_handleFocus()'
|
|
176
|
+
}
|
|
177
|
+
}]
|
|
178
|
+
}],
|
|
179
|
+
propDecorators: {
|
|
180
|
+
id: [{
|
|
181
|
+
type: Input
|
|
182
|
+
}],
|
|
183
|
+
value: [{
|
|
184
|
+
type: Input,
|
|
185
|
+
args: ['cdkOption']
|
|
186
|
+
}],
|
|
187
|
+
typeaheadLabel: [{
|
|
188
|
+
type: Input,
|
|
189
|
+
args: ['cdkOptionTypeaheadLabel']
|
|
190
|
+
}],
|
|
191
|
+
disabled: [{
|
|
192
|
+
type: Input,
|
|
193
|
+
args: [{
|
|
194
|
+
alias: 'cdkOptionDisabled',
|
|
195
|
+
transform: booleanAttribute
|
|
196
|
+
}]
|
|
197
|
+
}],
|
|
198
|
+
enabledTabIndex: [{
|
|
199
|
+
type: Input,
|
|
200
|
+
args: [{
|
|
201
|
+
alias: 'tabindex',
|
|
202
|
+
transform: value => value == null ? undefined : numberAttribute(value)
|
|
203
|
+
}]
|
|
204
|
+
}]
|
|
205
|
+
}
|
|
206
|
+
});
|
|
193
207
|
class CdkListbox {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
/** Callback called when the listbox value changes */
|
|
313
|
-
_onChange = () => { };
|
|
314
|
-
/** Emits when an option has been clicked. */
|
|
315
|
-
_optionClicked = defer(() => this.options.changes.pipe(startWith(this.options), switchMap(options => merge(...options.map(option => option._clicked.pipe(map(event => ({ option, event }))))))));
|
|
316
|
-
/** The directionality of the page. */
|
|
317
|
-
_dir = inject(Directionality, { optional: true });
|
|
318
|
-
/** Whether the component is being rendered in the browser. */
|
|
319
|
-
_isBrowser = inject(Platform).isBrowser;
|
|
320
|
-
/** A predicate that skips disabled options. */
|
|
321
|
-
_skipDisabledPredicate = (option) => option.disabled;
|
|
322
|
-
/** A predicate that does not skip any options. */
|
|
323
|
-
_skipNonePredicate = () => false;
|
|
324
|
-
/** Whether the listbox currently has focus. */
|
|
325
|
-
_hasFocus = false;
|
|
326
|
-
/** A reference to the option that was active before the listbox lost focus. */
|
|
327
|
-
_previousActiveOption = null;
|
|
328
|
-
constructor() {
|
|
329
|
-
if (this._isBrowser) {
|
|
330
|
-
const renderer = inject(Renderer2);
|
|
331
|
-
this._cleanupWindowBlur = this.ngZone.runOutsideAngular(() => {
|
|
332
|
-
return renderer.listen('window', 'blur', () => {
|
|
333
|
-
if (this.element.contains(document.activeElement) && this._previousActiveOption) {
|
|
334
|
-
this._setActiveOption(this._previousActiveOption);
|
|
335
|
-
this._previousActiveOption = null;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
ngAfterContentInit() {
|
|
342
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
343
|
-
this._verifyNoOptionValueCollisions();
|
|
344
|
-
this._verifyOptionValues();
|
|
345
|
-
}
|
|
346
|
-
this._initKeyManager();
|
|
347
|
-
// Update the internal value whenever the options or the model value changes.
|
|
348
|
-
merge(this.selectionModel.changed, this.options.changes)
|
|
349
|
-
.pipe(startWith(null), takeUntil(this.destroyed))
|
|
350
|
-
.subscribe(() => this._updateInternalValue());
|
|
351
|
-
this._optionClicked
|
|
352
|
-
.pipe(filter(({ option }) => !option.disabled), takeUntil(this.destroyed))
|
|
353
|
-
.subscribe(({ option, event }) => this._handleOptionClicked(option, event));
|
|
354
|
-
}
|
|
355
|
-
ngOnDestroy() {
|
|
356
|
-
this._cleanupWindowBlur?.();
|
|
357
|
-
this.listKeyManager?.destroy();
|
|
358
|
-
this.destroyed.next();
|
|
359
|
-
this.destroyed.complete();
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Toggle the selected state of the given option.
|
|
363
|
-
* @param option The option to toggle
|
|
364
|
-
*/
|
|
365
|
-
toggle(option) {
|
|
366
|
-
this.toggleValue(option.value);
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Toggle the selected state of the given value.
|
|
370
|
-
* @param value The value to toggle
|
|
371
|
-
*/
|
|
372
|
-
toggleValue(value) {
|
|
373
|
-
if (this._invalid) {
|
|
374
|
-
this.selectionModel.clear(false);
|
|
375
|
-
}
|
|
376
|
-
this.selectionModel.toggle(value);
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Select the given option.
|
|
380
|
-
* @param option The option to select
|
|
381
|
-
*/
|
|
382
|
-
select(option) {
|
|
383
|
-
this.selectValue(option.value);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Select the given value.
|
|
387
|
-
* @param value The value to select
|
|
388
|
-
*/
|
|
389
|
-
selectValue(value) {
|
|
390
|
-
if (this._invalid) {
|
|
391
|
-
this.selectionModel.clear(false);
|
|
392
|
-
}
|
|
393
|
-
this.selectionModel.select(value);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Deselect the given option.
|
|
397
|
-
* @param option The option to deselect
|
|
398
|
-
*/
|
|
399
|
-
deselect(option) {
|
|
400
|
-
this.deselectValue(option.value);
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Deselect the given value.
|
|
404
|
-
* @param value The value to deselect
|
|
405
|
-
*/
|
|
406
|
-
deselectValue(value) {
|
|
407
|
-
if (this._invalid) {
|
|
408
|
-
this.selectionModel.clear(false);
|
|
409
|
-
}
|
|
410
|
-
this.selectionModel.deselect(value);
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Set the selected state of all options.
|
|
414
|
-
* @param isSelected The new selected state to set
|
|
415
|
-
*/
|
|
416
|
-
setAllSelected(isSelected) {
|
|
417
|
-
if (!isSelected) {
|
|
418
|
-
this.selectionModel.clear();
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
if (this._invalid) {
|
|
422
|
-
this.selectionModel.clear(false);
|
|
423
|
-
}
|
|
424
|
-
this.selectionModel.select(...this.options.map(option => option.value));
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Get whether the given option is selected.
|
|
429
|
-
* @param option The option to get the selected state of
|
|
430
|
-
*/
|
|
431
|
-
isSelected(option) {
|
|
432
|
-
return this.isValueSelected(option.value);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Get whether the given option is active.
|
|
436
|
-
* @param option The option to get the active state of
|
|
437
|
-
*/
|
|
438
|
-
isActive(option) {
|
|
439
|
-
return !!(this.listKeyManager?.activeItem === option);
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Get whether the given value is selected.
|
|
443
|
-
* @param value The value to get the selected state of
|
|
444
|
-
*/
|
|
445
|
-
isValueSelected(value) {
|
|
446
|
-
if (this._invalid) {
|
|
447
|
-
return false;
|
|
448
|
-
}
|
|
449
|
-
return this.selectionModel.isSelected(value);
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Registers a callback to be invoked when the listbox's value changes from user input.
|
|
453
|
-
* @param fn The callback to register
|
|
454
|
-
* @docs-private
|
|
455
|
-
*/
|
|
456
|
-
registerOnChange(fn) {
|
|
457
|
-
this._onChange = fn;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Registers a callback to be invoked when the listbox is blurred by the user.
|
|
461
|
-
* @param fn The callback to register
|
|
462
|
-
* @docs-private
|
|
463
|
-
*/
|
|
464
|
-
registerOnTouched(fn) {
|
|
465
|
-
this._onTouched = fn;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Sets the listbox's value.
|
|
469
|
-
* @param value The new value of the listbox
|
|
470
|
-
* @docs-private
|
|
471
|
-
*/
|
|
472
|
-
writeValue(value) {
|
|
473
|
-
this._setSelection(value);
|
|
474
|
-
this._verifyOptionValues();
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Sets the disabled state of the listbox.
|
|
478
|
-
* @param isDisabled The new disabled state
|
|
479
|
-
* @docs-private
|
|
480
|
-
*/
|
|
481
|
-
setDisabledState(isDisabled) {
|
|
482
|
-
this.disabled = isDisabled;
|
|
483
|
-
this.changeDetectorRef.markForCheck();
|
|
484
|
-
}
|
|
485
|
-
/** Focus the listbox's host element. */
|
|
486
|
-
focus() {
|
|
487
|
-
this.element.focus();
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Triggers the given option in response to user interaction.
|
|
491
|
-
* - In single selection mode: selects the option and deselects any other selected option.
|
|
492
|
-
* - In multi selection mode: toggles the selected state of the option.
|
|
493
|
-
* @param option The option to trigger
|
|
494
|
-
*/
|
|
495
|
-
triggerOption(option) {
|
|
496
|
-
if (option && !option.disabled) {
|
|
497
|
-
this._lastTriggered = option;
|
|
498
|
-
const changed = this.multiple
|
|
499
|
-
? this.selectionModel.toggle(option.value)
|
|
500
|
-
: this.selectionModel.select(option.value);
|
|
501
|
-
if (changed) {
|
|
502
|
-
this._onChange(this.value);
|
|
503
|
-
this.valueChange.next({
|
|
504
|
-
value: this.value,
|
|
505
|
-
listbox: this,
|
|
506
|
-
option: option,
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Trigger the given range of options in response to user interaction.
|
|
513
|
-
* Should only be called in multi-selection mode.
|
|
514
|
-
* @param trigger The option that was triggered
|
|
515
|
-
* @param from The start index of the options to toggle
|
|
516
|
-
* @param to The end index of the options to toggle
|
|
517
|
-
* @param on Whether to toggle the option range on
|
|
518
|
-
*/
|
|
519
|
-
triggerRange(trigger, from, to, on) {
|
|
520
|
-
if (this.disabled || (trigger && trigger.disabled)) {
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
this._lastTriggered = trigger;
|
|
524
|
-
const isEqual = this.compareWith ?? Object.is;
|
|
525
|
-
const updateValues = [...this.options]
|
|
526
|
-
.slice(Math.max(0, Math.min(from, to)), Math.min(this.options.length, Math.max(from, to) + 1))
|
|
527
|
-
.filter(option => !option.disabled)
|
|
528
|
-
.map(option => option.value);
|
|
529
|
-
const selected = [...this.value];
|
|
530
|
-
for (const updateValue of updateValues) {
|
|
531
|
-
const selectedIndex = selected.findIndex(selectedValue => isEqual(selectedValue, updateValue));
|
|
532
|
-
if (on && selectedIndex === -1) {
|
|
533
|
-
selected.push(updateValue);
|
|
534
|
-
}
|
|
535
|
-
else if (!on && selectedIndex !== -1) {
|
|
536
|
-
selected.splice(selectedIndex, 1);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
let changed = this.selectionModel.setSelection(...selected);
|
|
540
|
-
if (changed) {
|
|
541
|
-
this._onChange(this.value);
|
|
542
|
-
this.valueChange.next({
|
|
543
|
-
value: this.value,
|
|
544
|
-
listbox: this,
|
|
545
|
-
option: trigger,
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Sets the given option as active.
|
|
551
|
-
* @param option The option to make active
|
|
552
|
-
*/
|
|
553
|
-
_setActiveOption(option) {
|
|
554
|
-
this.listKeyManager.setActiveItem(option);
|
|
555
|
-
}
|
|
556
|
-
/** Called when the listbox receives focus. */
|
|
557
|
-
_handleFocus() {
|
|
558
|
-
if (!this.useActiveDescendant) {
|
|
559
|
-
if (this.selectionModel.selected.length > 0) {
|
|
560
|
-
this._setNextFocusToSelectedOption();
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
this.listKeyManager.setNextItemActive();
|
|
564
|
-
}
|
|
565
|
-
this._focusActiveOption();
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
/** Called when the user presses keydown on the listbox. */
|
|
569
|
-
_handleKeydown(event) {
|
|
570
|
-
if (this.disabled) {
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
const { keyCode } = event;
|
|
574
|
-
const previousActiveIndex = this.listKeyManager.activeItemIndex;
|
|
575
|
-
const ctrlKeys = ['ctrlKey', 'metaKey'];
|
|
576
|
-
if (this.multiple && keyCode === A && hasModifierKey(event, ...ctrlKeys)) {
|
|
577
|
-
// Toggle all options off if they're all selected, otherwise toggle them all on.
|
|
578
|
-
this.triggerRange(null, 0, this.options.length - 1, this.options.length !== this.value.length);
|
|
579
|
-
event.preventDefault();
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
if (this.multiple &&
|
|
583
|
-
(keyCode === SPACE || keyCode === ENTER) &&
|
|
584
|
-
hasModifierKey(event, 'shiftKey')) {
|
|
585
|
-
if (this.listKeyManager.activeItem && this.listKeyManager.activeItemIndex != null) {
|
|
586
|
-
this.triggerRange(this.listKeyManager.activeItem, this._getLastTriggeredIndex() ?? this.listKeyManager.activeItemIndex, this.listKeyManager.activeItemIndex, !this.listKeyManager.activeItem.isSelected());
|
|
587
|
-
}
|
|
588
|
-
event.preventDefault();
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
if (this.multiple &&
|
|
592
|
-
keyCode === HOME &&
|
|
593
|
-
hasModifierKey(event, ...ctrlKeys) &&
|
|
594
|
-
hasModifierKey(event, 'shiftKey')) {
|
|
595
|
-
const trigger = this.listKeyManager.activeItem;
|
|
596
|
-
if (trigger) {
|
|
597
|
-
const from = this.listKeyManager.activeItemIndex;
|
|
598
|
-
this.listKeyManager.setFirstItemActive();
|
|
599
|
-
this.triggerRange(trigger, from, this.listKeyManager.activeItemIndex, !trigger.isSelected());
|
|
600
|
-
}
|
|
601
|
-
event.preventDefault();
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
if (this.multiple &&
|
|
605
|
-
keyCode === END &&
|
|
606
|
-
hasModifierKey(event, ...ctrlKeys) &&
|
|
607
|
-
hasModifierKey(event, 'shiftKey')) {
|
|
608
|
-
const trigger = this.listKeyManager.activeItem;
|
|
609
|
-
if (trigger) {
|
|
610
|
-
const from = this.listKeyManager.activeItemIndex;
|
|
611
|
-
this.listKeyManager.setLastItemActive();
|
|
612
|
-
this.triggerRange(trigger, from, this.listKeyManager.activeItemIndex, !trigger.isSelected());
|
|
613
|
-
}
|
|
614
|
-
event.preventDefault();
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
if (keyCode === SPACE || keyCode === ENTER) {
|
|
618
|
-
this.triggerOption(this.listKeyManager.activeItem);
|
|
619
|
-
event.preventDefault();
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
const isNavKey = keyCode === UP_ARROW ||
|
|
623
|
-
keyCode === DOWN_ARROW ||
|
|
624
|
-
keyCode === LEFT_ARROW ||
|
|
625
|
-
keyCode === RIGHT_ARROW ||
|
|
626
|
-
keyCode === HOME ||
|
|
627
|
-
keyCode === END;
|
|
628
|
-
this.listKeyManager.onKeydown(event);
|
|
629
|
-
// Will select an option if shift was pressed while navigating to the option
|
|
630
|
-
if (isNavKey && event.shiftKey && previousActiveIndex !== this.listKeyManager.activeItemIndex) {
|
|
631
|
-
this.triggerOption(this.listKeyManager.activeItem);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
/** Called when a focus moves into the listbox. */
|
|
635
|
-
_handleFocusIn() {
|
|
636
|
-
// Note that we use a `focusin` handler for this instead of the existing `focus` handler,
|
|
637
|
-
// because focus won't land on the listbox if `useActiveDescendant` is enabled.
|
|
638
|
-
this._hasFocus = true;
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* Called when the focus leaves an element in the listbox.
|
|
642
|
-
* @param event The focusout event
|
|
643
|
-
*/
|
|
644
|
-
_handleFocusOut(event) {
|
|
645
|
-
// Some browsers (e.g. Chrome and Firefox) trigger the focusout event when the user returns back to the document.
|
|
646
|
-
// To prevent losing the active option in this case, we store it in `_previousActiveOption` and restore it on the window `blur` event
|
|
647
|
-
// This ensures that the `activeItem` matches the actual focused element when the user returns to the document.
|
|
648
|
-
this._previousActiveOption = this.listKeyManager.activeItem;
|
|
649
|
-
const otherElement = event.relatedTarget;
|
|
650
|
-
if (this.element !== otherElement && !this.element.contains(otherElement)) {
|
|
651
|
-
this._onTouched();
|
|
652
|
-
this._hasFocus = false;
|
|
653
|
-
this._setNextFocusToSelectedOption();
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
/** Get the id of the active option if active descendant is being used. */
|
|
657
|
-
_getAriaActiveDescendant() {
|
|
658
|
-
return this.useActiveDescendant ? this.listKeyManager?.activeItem?.id : null;
|
|
659
|
-
}
|
|
660
|
-
/** Get the tabindex for the listbox. */
|
|
661
|
-
_getTabIndex() {
|
|
662
|
-
if (this.disabled) {
|
|
663
|
-
return -1;
|
|
664
|
-
}
|
|
665
|
-
return this.useActiveDescendant || !this.listKeyManager.activeItem ? this.enabledTabIndex : -1;
|
|
666
|
-
}
|
|
667
|
-
/** Initialize the key manager. */
|
|
668
|
-
_initKeyManager() {
|
|
669
|
-
this.listKeyManager = new ActiveDescendantKeyManager(this.options)
|
|
670
|
-
.withWrap(!this._navigationWrapDisabled)
|
|
671
|
-
.withTypeAhead()
|
|
672
|
-
.withHomeAndEnd()
|
|
673
|
-
.withAllowedModifierKeys(['shiftKey'])
|
|
674
|
-
.skipPredicate(this._navigateDisabledOptions ? this._skipNonePredicate : this._skipDisabledPredicate);
|
|
675
|
-
if (this.orientation === 'vertical') {
|
|
676
|
-
this.listKeyManager.withVerticalOrientation();
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
this.listKeyManager.withHorizontalOrientation(this._dir?.value || 'ltr');
|
|
680
|
-
}
|
|
681
|
-
if (this.selectionModel.selected.length) {
|
|
682
|
-
Promise.resolve().then(() => this._setNextFocusToSelectedOption());
|
|
683
|
-
}
|
|
684
|
-
this.listKeyManager.change.subscribe(() => this._focusActiveOption());
|
|
685
|
-
this.options.changes.pipe(takeUntil(this.destroyed)).subscribe(() => {
|
|
686
|
-
const activeOption = this.listKeyManager.activeItem;
|
|
687
|
-
// If the active option was deleted, we need to reset
|
|
688
|
-
// the key manager so it can allow focus back in.
|
|
689
|
-
if (activeOption && !this.options.find(option => option === activeOption)) {
|
|
690
|
-
this.listKeyManager.setActiveItem(-1);
|
|
691
|
-
this.changeDetectorRef.markForCheck();
|
|
692
|
-
}
|
|
208
|
+
_cleanupWindowBlur;
|
|
209
|
+
get id() {
|
|
210
|
+
return this._id || this._generatedId;
|
|
211
|
+
}
|
|
212
|
+
set id(value) {
|
|
213
|
+
this._id = value;
|
|
214
|
+
}
|
|
215
|
+
_id;
|
|
216
|
+
_generatedId = inject(_IdGenerator).getId('cdk-listbox-');
|
|
217
|
+
get enabledTabIndex() {
|
|
218
|
+
return this._enabledTabIndex() === undefined ? 0 : this._enabledTabIndex();
|
|
219
|
+
}
|
|
220
|
+
set enabledTabIndex(value) {
|
|
221
|
+
this._enabledTabIndex.set(value);
|
|
222
|
+
}
|
|
223
|
+
_enabledTabIndex = signal(undefined, ...(ngDevMode ? [{
|
|
224
|
+
debugName: "_enabledTabIndex"
|
|
225
|
+
}] : []));
|
|
226
|
+
get value() {
|
|
227
|
+
return this._invalid ? [] : this.selectionModel.selected;
|
|
228
|
+
}
|
|
229
|
+
set value(value) {
|
|
230
|
+
this._setSelection(value);
|
|
231
|
+
}
|
|
232
|
+
get multiple() {
|
|
233
|
+
return this.selectionModel.multiple;
|
|
234
|
+
}
|
|
235
|
+
set multiple(value) {
|
|
236
|
+
this.selectionModel.multiple = value;
|
|
237
|
+
if (this.options) {
|
|
238
|
+
this._updateInternalValue();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
get disabled() {
|
|
242
|
+
return this._disabled();
|
|
243
|
+
}
|
|
244
|
+
set disabled(value) {
|
|
245
|
+
this._disabled.set(value);
|
|
246
|
+
}
|
|
247
|
+
_disabled = signal(false, ...(ngDevMode ? [{
|
|
248
|
+
debugName: "_disabled"
|
|
249
|
+
}] : []));
|
|
250
|
+
get useActiveDescendant() {
|
|
251
|
+
return this._useActiveDescendant();
|
|
252
|
+
}
|
|
253
|
+
set useActiveDescendant(value) {
|
|
254
|
+
this._useActiveDescendant.set(value);
|
|
255
|
+
}
|
|
256
|
+
_useActiveDescendant = signal(false, ...(ngDevMode ? [{
|
|
257
|
+
debugName: "_useActiveDescendant"
|
|
258
|
+
}] : []));
|
|
259
|
+
get orientation() {
|
|
260
|
+
return this._orientation;
|
|
261
|
+
}
|
|
262
|
+
set orientation(value) {
|
|
263
|
+
this._orientation = value === 'horizontal' ? 'horizontal' : 'vertical';
|
|
264
|
+
if (value === 'horizontal') {
|
|
265
|
+
this.listKeyManager?.withHorizontalOrientation(this._dir?.value || 'ltr');
|
|
266
|
+
} else {
|
|
267
|
+
this.listKeyManager?.withVerticalOrientation();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
_orientation = 'vertical';
|
|
271
|
+
get compareWith() {
|
|
272
|
+
return this.selectionModel.compareWith;
|
|
273
|
+
}
|
|
274
|
+
set compareWith(fn) {
|
|
275
|
+
this.selectionModel.compareWith = fn;
|
|
276
|
+
}
|
|
277
|
+
get navigationWrapDisabled() {
|
|
278
|
+
return this._navigationWrapDisabled;
|
|
279
|
+
}
|
|
280
|
+
set navigationWrapDisabled(wrap) {
|
|
281
|
+
this._navigationWrapDisabled = wrap;
|
|
282
|
+
this.listKeyManager?.withWrap(!this._navigationWrapDisabled);
|
|
283
|
+
}
|
|
284
|
+
_navigationWrapDisabled = false;
|
|
285
|
+
get navigateDisabledOptions() {
|
|
286
|
+
return this._navigateDisabledOptions;
|
|
287
|
+
}
|
|
288
|
+
set navigateDisabledOptions(skip) {
|
|
289
|
+
this._navigateDisabledOptions = skip;
|
|
290
|
+
this.listKeyManager?.skipPredicate(this._navigateDisabledOptions ? this._skipNonePredicate : this._skipDisabledPredicate);
|
|
291
|
+
}
|
|
292
|
+
_navigateDisabledOptions = false;
|
|
293
|
+
valueChange = new Subject();
|
|
294
|
+
options;
|
|
295
|
+
selectionModel = new ListboxSelectionModel();
|
|
296
|
+
listKeyManager;
|
|
297
|
+
destroyed = new Subject();
|
|
298
|
+
element = inject(ElementRef).nativeElement;
|
|
299
|
+
ngZone = inject(NgZone);
|
|
300
|
+
changeDetectorRef = inject(ChangeDetectorRef);
|
|
301
|
+
_invalid = false;
|
|
302
|
+
_lastTriggered = null;
|
|
303
|
+
_onTouched = () => {};
|
|
304
|
+
_onChange = () => {};
|
|
305
|
+
_optionClicked = defer(() => this.options.changes.pipe(startWith(this.options), switchMap(options => merge(...options.map(option => option._clicked.pipe(map(event => ({
|
|
306
|
+
option,
|
|
307
|
+
event
|
|
308
|
+
}))))))));
|
|
309
|
+
_dir = inject(Directionality, {
|
|
310
|
+
optional: true
|
|
311
|
+
});
|
|
312
|
+
_isBrowser = inject(Platform).isBrowser;
|
|
313
|
+
_skipDisabledPredicate = option => option.disabled;
|
|
314
|
+
_skipNonePredicate = () => false;
|
|
315
|
+
_hasFocus = false;
|
|
316
|
+
_previousActiveOption = null;
|
|
317
|
+
constructor() {
|
|
318
|
+
if (this._isBrowser) {
|
|
319
|
+
const renderer = inject(Renderer2);
|
|
320
|
+
this._cleanupWindowBlur = this.ngZone.runOutsideAngular(() => {
|
|
321
|
+
return renderer.listen('window', 'blur', () => {
|
|
322
|
+
if (this.element.contains(document.activeElement) && this._previousActiveOption) {
|
|
323
|
+
this._setActiveOption(this._previousActiveOption);
|
|
324
|
+
this._previousActiveOption = null;
|
|
325
|
+
}
|
|
693
326
|
});
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
ngAfterContentInit() {
|
|
331
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
332
|
+
this._verifyNoOptionValueCollisions();
|
|
333
|
+
this._verifyOptionValues();
|
|
334
|
+
}
|
|
335
|
+
this._initKeyManager();
|
|
336
|
+
merge(this.selectionModel.changed, this.options.changes).pipe(startWith(null), takeUntil(this.destroyed)).subscribe(() => this._updateInternalValue());
|
|
337
|
+
this._optionClicked.pipe(filter(({
|
|
338
|
+
option
|
|
339
|
+
}) => !option.disabled), takeUntil(this.destroyed)).subscribe(({
|
|
340
|
+
option,
|
|
341
|
+
event
|
|
342
|
+
}) => this._handleOptionClicked(option, event));
|
|
343
|
+
}
|
|
344
|
+
ngOnDestroy() {
|
|
345
|
+
this._cleanupWindowBlur?.();
|
|
346
|
+
this.listKeyManager?.destroy();
|
|
347
|
+
this.destroyed.next();
|
|
348
|
+
this.destroyed.complete();
|
|
349
|
+
}
|
|
350
|
+
toggle(option) {
|
|
351
|
+
this.toggleValue(option.value);
|
|
352
|
+
}
|
|
353
|
+
toggleValue(value) {
|
|
354
|
+
if (this._invalid) {
|
|
355
|
+
this.selectionModel.clear(false);
|
|
356
|
+
}
|
|
357
|
+
this.selectionModel.toggle(value);
|
|
358
|
+
}
|
|
359
|
+
select(option) {
|
|
360
|
+
this.selectValue(option.value);
|
|
361
|
+
}
|
|
362
|
+
selectValue(value) {
|
|
363
|
+
if (this._invalid) {
|
|
364
|
+
this.selectionModel.clear(false);
|
|
365
|
+
}
|
|
366
|
+
this.selectionModel.select(value);
|
|
367
|
+
}
|
|
368
|
+
deselect(option) {
|
|
369
|
+
this.deselectValue(option.value);
|
|
370
|
+
}
|
|
371
|
+
deselectValue(value) {
|
|
372
|
+
if (this._invalid) {
|
|
373
|
+
this.selectionModel.clear(false);
|
|
374
|
+
}
|
|
375
|
+
this.selectionModel.deselect(value);
|
|
376
|
+
}
|
|
377
|
+
setAllSelected(isSelected) {
|
|
378
|
+
if (!isSelected) {
|
|
379
|
+
this.selectionModel.clear();
|
|
380
|
+
} else {
|
|
381
|
+
if (this._invalid) {
|
|
382
|
+
this.selectionModel.clear(false);
|
|
383
|
+
}
|
|
384
|
+
this.selectionModel.select(...this.options.map(option => option.value));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
isSelected(option) {
|
|
388
|
+
return this.isValueSelected(option.value);
|
|
389
|
+
}
|
|
390
|
+
isActive(option) {
|
|
391
|
+
return !!(this.listKeyManager?.activeItem === option);
|
|
392
|
+
}
|
|
393
|
+
isValueSelected(value) {
|
|
394
|
+
if (this._invalid) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
return this.selectionModel.isSelected(value);
|
|
398
|
+
}
|
|
399
|
+
registerOnChange(fn) {
|
|
400
|
+
this._onChange = fn;
|
|
401
|
+
}
|
|
402
|
+
registerOnTouched(fn) {
|
|
403
|
+
this._onTouched = fn;
|
|
404
|
+
}
|
|
405
|
+
writeValue(value) {
|
|
406
|
+
this._setSelection(value);
|
|
407
|
+
this._verifyOptionValues();
|
|
408
|
+
}
|
|
409
|
+
setDisabledState(isDisabled) {
|
|
410
|
+
this.disabled = isDisabled;
|
|
411
|
+
this.changeDetectorRef.markForCheck();
|
|
412
|
+
}
|
|
413
|
+
focus() {
|
|
414
|
+
this.element.focus();
|
|
415
|
+
}
|
|
416
|
+
triggerOption(option) {
|
|
417
|
+
if (option && !option.disabled) {
|
|
418
|
+
this._lastTriggered = option;
|
|
419
|
+
const changed = this.multiple ? this.selectionModel.toggle(option.value) : this.selectionModel.select(option.value);
|
|
420
|
+
if (changed) {
|
|
421
|
+
this._onChange(this.value);
|
|
422
|
+
this.valueChange.next({
|
|
423
|
+
value: this.value,
|
|
424
|
+
listbox: this,
|
|
425
|
+
option: option
|
|
730
426
|
});
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
triggerRange(trigger, from, to, on) {
|
|
431
|
+
if (this.disabled || trigger && trigger.disabled) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
this._lastTriggered = trigger;
|
|
435
|
+
const isEqual = this.compareWith ?? Object.is;
|
|
436
|
+
const updateValues = [...this.options].slice(Math.max(0, Math.min(from, to)), Math.min(this.options.length, Math.max(from, to) + 1)).filter(option => !option.disabled).map(option => option.value);
|
|
437
|
+
const selected = [...this.value];
|
|
438
|
+
for (const updateValue of updateValues) {
|
|
439
|
+
const selectedIndex = selected.findIndex(selectedValue => isEqual(selectedValue, updateValue));
|
|
440
|
+
if (on && selectedIndex === -1) {
|
|
441
|
+
selected.push(updateValue);
|
|
442
|
+
} else if (!on && selectedIndex !== -1) {
|
|
443
|
+
selected.splice(selectedIndex, 1);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
let changed = this.selectionModel.setSelection(...selected);
|
|
447
|
+
if (changed) {
|
|
448
|
+
this._onChange(this.value);
|
|
449
|
+
this.valueChange.next({
|
|
450
|
+
value: this.value,
|
|
451
|
+
listbox: this,
|
|
452
|
+
option: trigger
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
_setActiveOption(option) {
|
|
457
|
+
this.listKeyManager.setActiveItem(option);
|
|
458
|
+
}
|
|
459
|
+
_handleFocus() {
|
|
460
|
+
if (!this.useActiveDescendant) {
|
|
461
|
+
if (this.selectionModel.selected.length > 0) {
|
|
462
|
+
this._setNextFocusToSelectedOption();
|
|
463
|
+
} else {
|
|
464
|
+
this.listKeyManager.setNextItemActive();
|
|
465
|
+
}
|
|
466
|
+
this._focusActiveOption();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
_handleKeydown(event) {
|
|
470
|
+
if (this.disabled) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const {
|
|
474
|
+
keyCode
|
|
475
|
+
} = event;
|
|
476
|
+
const previousActiveIndex = this.listKeyManager.activeItemIndex;
|
|
477
|
+
const ctrlKeys = ['ctrlKey', 'metaKey'];
|
|
478
|
+
if (this.multiple && keyCode === A && hasModifierKey(event, ...ctrlKeys)) {
|
|
479
|
+
this.triggerRange(null, 0, this.options.length - 1, this.options.length !== this.value.length);
|
|
480
|
+
event.preventDefault();
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if (this.multiple && (keyCode === SPACE || keyCode === ENTER) && hasModifierKey(event, 'shiftKey')) {
|
|
484
|
+
if (this.listKeyManager.activeItem && this.listKeyManager.activeItemIndex != null) {
|
|
485
|
+
this.triggerRange(this.listKeyManager.activeItem, this._getLastTriggeredIndex() ?? this.listKeyManager.activeItemIndex, this.listKeyManager.activeItemIndex, !this.listKeyManager.activeItem.isSelected());
|
|
486
|
+
}
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (this.multiple && keyCode === HOME && hasModifierKey(event, ...ctrlKeys) && hasModifierKey(event, 'shiftKey')) {
|
|
491
|
+
const trigger = this.listKeyManager.activeItem;
|
|
492
|
+
if (trigger) {
|
|
493
|
+
const from = this.listKeyManager.activeItemIndex;
|
|
494
|
+
this.listKeyManager.setFirstItemActive();
|
|
495
|
+
this.triggerRange(trigger, from, this.listKeyManager.activeItemIndex, !trigger.isSelected());
|
|
496
|
+
}
|
|
497
|
+
event.preventDefault();
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (this.multiple && keyCode === END && hasModifierKey(event, ...ctrlKeys) && hasModifierKey(event, 'shiftKey')) {
|
|
501
|
+
const trigger = this.listKeyManager.activeItem;
|
|
502
|
+
if (trigger) {
|
|
503
|
+
const from = this.listKeyManager.activeItemIndex;
|
|
504
|
+
this.listKeyManager.setLastItemActive();
|
|
505
|
+
this.triggerRange(trigger, from, this.listKeyManager.activeItemIndex, !trigger.isSelected());
|
|
506
|
+
}
|
|
507
|
+
event.preventDefault();
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (keyCode === SPACE || keyCode === ENTER) {
|
|
511
|
+
this.triggerOption(this.listKeyManager.activeItem);
|
|
512
|
+
event.preventDefault();
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const isNavKey = keyCode === UP_ARROW || keyCode === DOWN_ARROW || keyCode === LEFT_ARROW || keyCode === RIGHT_ARROW || keyCode === HOME || keyCode === END;
|
|
516
|
+
this.listKeyManager.onKeydown(event);
|
|
517
|
+
if (isNavKey && event.shiftKey && previousActiveIndex !== this.listKeyManager.activeItemIndex) {
|
|
518
|
+
this.triggerOption(this.listKeyManager.activeItem);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
_handleFocusIn() {
|
|
522
|
+
this._hasFocus = true;
|
|
523
|
+
}
|
|
524
|
+
_handleFocusOut(event) {
|
|
525
|
+
this._previousActiveOption = this.listKeyManager.activeItem;
|
|
526
|
+
const otherElement = event.relatedTarget;
|
|
527
|
+
if (this.element !== otherElement && !this.element.contains(otherElement)) {
|
|
528
|
+
this._onTouched();
|
|
529
|
+
this._hasFocus = false;
|
|
530
|
+
this._setNextFocusToSelectedOption();
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
_getAriaActiveDescendant() {
|
|
534
|
+
return this.useActiveDescendant ? this.listKeyManager?.activeItem?.id : null;
|
|
535
|
+
}
|
|
536
|
+
_getTabIndex() {
|
|
537
|
+
if (this.disabled) {
|
|
538
|
+
return -1;
|
|
539
|
+
}
|
|
540
|
+
return this.useActiveDescendant || !this.listKeyManager.activeItem ? this.enabledTabIndex : -1;
|
|
541
|
+
}
|
|
542
|
+
_initKeyManager() {
|
|
543
|
+
this.listKeyManager = new ActiveDescendantKeyManager(this.options).withWrap(!this._navigationWrapDisabled).withTypeAhead().withHomeAndEnd().withAllowedModifierKeys(['shiftKey']).skipPredicate(this._navigateDisabledOptions ? this._skipNonePredicate : this._skipDisabledPredicate);
|
|
544
|
+
if (this.orientation === 'vertical') {
|
|
545
|
+
this.listKeyManager.withVerticalOrientation();
|
|
546
|
+
} else {
|
|
547
|
+
this.listKeyManager.withHorizontalOrientation(this._dir?.value || 'ltr');
|
|
548
|
+
}
|
|
549
|
+
if (this.selectionModel.selected.length) {
|
|
550
|
+
Promise.resolve().then(() => this._setNextFocusToSelectedOption());
|
|
551
|
+
}
|
|
552
|
+
this.listKeyManager.change.subscribe(() => this._focusActiveOption());
|
|
553
|
+
this.options.changes.pipe(takeUntil(this.destroyed)).subscribe(() => {
|
|
554
|
+
const activeOption = this.listKeyManager.activeItem;
|
|
555
|
+
if (activeOption && !this.options.find(option => option === activeOption)) {
|
|
556
|
+
this.listKeyManager.setActiveItem(-1);
|
|
734
557
|
this.changeDetectorRef.markForCheck();
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
_focusActiveOption() {
|
|
562
|
+
if (!this.useActiveDescendant) {
|
|
563
|
+
this.listKeyManager.activeItem?.focus();
|
|
564
|
+
}
|
|
565
|
+
this.changeDetectorRef.markForCheck();
|
|
566
|
+
}
|
|
567
|
+
_setSelection(value) {
|
|
568
|
+
if (this._invalid) {
|
|
569
|
+
this.selectionModel.clear(false);
|
|
570
|
+
}
|
|
571
|
+
this.selectionModel.setSelection(...this._coerceValue(value));
|
|
572
|
+
if (!this._hasFocus) {
|
|
573
|
+
this._setNextFocusToSelectedOption();
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
_setNextFocusToSelectedOption() {
|
|
577
|
+
const selected = this.options?.find(option => option.isSelected());
|
|
578
|
+
if (selected) {
|
|
579
|
+
this.listKeyManager.updateActiveItem(selected);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
_updateInternalValue() {
|
|
583
|
+
const indexCache = new Map();
|
|
584
|
+
this.selectionModel.sort((a, b) => {
|
|
585
|
+
const aIndex = this._getIndexForValue(indexCache, a);
|
|
586
|
+
const bIndex = this._getIndexForValue(indexCache, b);
|
|
587
|
+
return aIndex - bIndex;
|
|
588
|
+
});
|
|
589
|
+
const selected = this.selectionModel.selected;
|
|
590
|
+
this._invalid = !this.multiple && selected.length > 1 || !!this._getInvalidOptionValues(selected).length;
|
|
591
|
+
this.changeDetectorRef.markForCheck();
|
|
592
|
+
}
|
|
593
|
+
_getIndexForValue(cache, value) {
|
|
594
|
+
const isEqual = this.compareWith || Object.is;
|
|
595
|
+
if (!cache.has(value)) {
|
|
596
|
+
let index = -1;
|
|
597
|
+
for (let i = 0; i < this.options.length; i++) {
|
|
598
|
+
if (isEqual(value, this.options.get(i).value)) {
|
|
599
|
+
index = i;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
cache.set(value, index);
|
|
604
|
+
}
|
|
605
|
+
return cache.get(value);
|
|
606
|
+
}
|
|
607
|
+
_handleOptionClicked(option, event) {
|
|
608
|
+
event.preventDefault();
|
|
609
|
+
this.listKeyManager.setActiveItem(option);
|
|
610
|
+
if (event.shiftKey && this.multiple) {
|
|
611
|
+
this.triggerRange(option, this._getLastTriggeredIndex() ?? this.listKeyManager.activeItemIndex, this.listKeyManager.activeItemIndex, !option.isSelected());
|
|
612
|
+
} else {
|
|
613
|
+
this.triggerOption(option);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
_verifyNoOptionValueCollisions() {
|
|
617
|
+
this.options.changes.pipe(startWith(this.options), takeUntil(this.destroyed)).subscribe(() => {
|
|
618
|
+
const isEqual = this.compareWith ?? Object.is;
|
|
619
|
+
for (let i = 0; i < this.options.length; i++) {
|
|
620
|
+
const option = this.options.get(i);
|
|
621
|
+
let duplicate = null;
|
|
622
|
+
for (let j = i + 1; j < this.options.length; j++) {
|
|
623
|
+
const other = this.options.get(j);
|
|
624
|
+
if (isEqual(option.value, other.value)) {
|
|
625
|
+
duplicate = other;
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (duplicate) {
|
|
630
|
+
if (this.compareWith) {
|
|
631
|
+
console.warn(`Found multiple CdkOption representing the same value under the given compareWith function`, {
|
|
632
|
+
option1: option.element,
|
|
633
|
+
option2: duplicate.element,
|
|
634
|
+
compareWith: this.compareWith
|
|
635
|
+
});
|
|
636
|
+
} else {
|
|
637
|
+
console.warn(`Found multiple CdkOption with the same value`, {
|
|
638
|
+
option1: option.element,
|
|
639
|
+
option2: duplicate.element
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
_verifyOptionValues() {
|
|
648
|
+
if (this.options && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
649
|
+
const selected = this.selectionModel.selected;
|
|
650
|
+
const invalidValues = this._getInvalidOptionValues(selected);
|
|
651
|
+
if (!this.multiple && selected.length > 1) {
|
|
652
|
+
throw Error('Listbox cannot have more than one selected value in multi-selection mode.');
|
|
653
|
+
}
|
|
654
|
+
if (invalidValues.length) {
|
|
655
|
+
throw Error('Listbox has selected values that do not match any of its options.');
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
_coerceValue(value) {
|
|
660
|
+
return value == null ? [] : coerceArray(value);
|
|
661
|
+
}
|
|
662
|
+
_getInvalidOptionValues(values) {
|
|
663
|
+
const isEqual = this.compareWith || Object.is;
|
|
664
|
+
const validValues = (this.options || []).map(option => option.value);
|
|
665
|
+
return values.filter(value => !validValues.some(validValue => isEqual(value, validValue)));
|
|
666
|
+
}
|
|
667
|
+
_getLastTriggeredIndex() {
|
|
668
|
+
const index = this.options.toArray().indexOf(this._lastTriggered);
|
|
669
|
+
return index === -1 ? null : index;
|
|
670
|
+
}
|
|
671
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
672
|
+
minVersion: "12.0.0",
|
|
673
|
+
version: "20.2.0-next.2",
|
|
674
|
+
ngImport: i0,
|
|
675
|
+
type: CdkListbox,
|
|
676
|
+
deps: [],
|
|
677
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
678
|
+
});
|
|
679
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
680
|
+
minVersion: "16.1.0",
|
|
681
|
+
version: "20.2.0-next.2",
|
|
682
|
+
type: CdkListbox,
|
|
683
|
+
isStandalone: true,
|
|
684
|
+
selector: "[cdkListbox]",
|
|
685
|
+
inputs: {
|
|
686
|
+
id: "id",
|
|
687
|
+
enabledTabIndex: ["tabindex", "enabledTabIndex"],
|
|
688
|
+
value: ["cdkListboxValue", "value"],
|
|
689
|
+
multiple: ["cdkListboxMultiple", "multiple", booleanAttribute],
|
|
690
|
+
disabled: ["cdkListboxDisabled", "disabled", booleanAttribute],
|
|
691
|
+
useActiveDescendant: ["cdkListboxUseActiveDescendant", "useActiveDescendant", booleanAttribute],
|
|
692
|
+
orientation: ["cdkListboxOrientation", "orientation"],
|
|
693
|
+
compareWith: ["cdkListboxCompareWith", "compareWith"],
|
|
694
|
+
navigationWrapDisabled: ["cdkListboxNavigationWrapDisabled", "navigationWrapDisabled", booleanAttribute],
|
|
695
|
+
navigateDisabledOptions: ["cdkListboxNavigatesDisabledOptions", "navigateDisabledOptions", booleanAttribute]
|
|
696
|
+
},
|
|
697
|
+
outputs: {
|
|
698
|
+
valueChange: "cdkListboxValueChange"
|
|
699
|
+
},
|
|
700
|
+
host: {
|
|
701
|
+
attributes: {
|
|
702
|
+
"role": "listbox"
|
|
703
|
+
},
|
|
704
|
+
listeners: {
|
|
705
|
+
"focus": "_handleFocus()",
|
|
706
|
+
"keydown": "_handleKeydown($event)",
|
|
707
|
+
"focusout": "_handleFocusOut($event)",
|
|
708
|
+
"focusin": "_handleFocusIn()"
|
|
709
|
+
},
|
|
710
|
+
properties: {
|
|
711
|
+
"id": "id",
|
|
712
|
+
"attr.tabindex": "_getTabIndex()",
|
|
713
|
+
"attr.aria-disabled": "disabled",
|
|
714
|
+
"attr.aria-multiselectable": "multiple",
|
|
715
|
+
"attr.aria-activedescendant": "_getAriaActiveDescendant()",
|
|
716
|
+
"attr.aria-orientation": "orientation"
|
|
717
|
+
},
|
|
718
|
+
classAttribute: "cdk-listbox"
|
|
719
|
+
},
|
|
720
|
+
providers: [{
|
|
721
|
+
provide: NG_VALUE_ACCESSOR,
|
|
722
|
+
useExisting: forwardRef(() => CdkListbox),
|
|
723
|
+
multi: true
|
|
724
|
+
}],
|
|
725
|
+
queries: [{
|
|
726
|
+
propertyName: "options",
|
|
727
|
+
predicate: CdkOption,
|
|
728
|
+
descendants: true
|
|
729
|
+
}],
|
|
730
|
+
exportAs: ["cdkListbox"],
|
|
731
|
+
ngImport: i0
|
|
732
|
+
});
|
|
848
733
|
}
|
|
849
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
734
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
735
|
+
minVersion: "12.0.0",
|
|
736
|
+
version: "20.2.0-next.2",
|
|
737
|
+
ngImport: i0,
|
|
738
|
+
type: CdkListbox,
|
|
739
|
+
decorators: [{
|
|
740
|
+
type: Directive,
|
|
741
|
+
args: [{
|
|
742
|
+
selector: '[cdkListbox]',
|
|
743
|
+
exportAs: 'cdkListbox',
|
|
744
|
+
host: {
|
|
745
|
+
'role': 'listbox',
|
|
746
|
+
'class': 'cdk-listbox',
|
|
747
|
+
'[id]': 'id',
|
|
748
|
+
'[attr.tabindex]': '_getTabIndex()',
|
|
749
|
+
'[attr.aria-disabled]': 'disabled',
|
|
750
|
+
'[attr.aria-multiselectable]': 'multiple',
|
|
751
|
+
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()',
|
|
752
|
+
'[attr.aria-orientation]': 'orientation',
|
|
753
|
+
'(focus)': '_handleFocus()',
|
|
754
|
+
'(keydown)': '_handleKeydown($event)',
|
|
755
|
+
'(focusout)': '_handleFocusOut($event)',
|
|
756
|
+
'(focusin)': '_handleFocusIn()'
|
|
757
|
+
},
|
|
758
|
+
providers: [{
|
|
759
|
+
provide: NG_VALUE_ACCESSOR,
|
|
760
|
+
useExisting: forwardRef(() => CdkListbox),
|
|
761
|
+
multi: true
|
|
762
|
+
}]
|
|
763
|
+
}]
|
|
764
|
+
}],
|
|
765
|
+
ctorParameters: () => [],
|
|
766
|
+
propDecorators: {
|
|
767
|
+
id: [{
|
|
768
|
+
type: Input
|
|
769
|
+
}],
|
|
770
|
+
enabledTabIndex: [{
|
|
771
|
+
type: Input,
|
|
772
|
+
args: ['tabindex']
|
|
773
|
+
}],
|
|
774
|
+
value: [{
|
|
775
|
+
type: Input,
|
|
776
|
+
args: ['cdkListboxValue']
|
|
777
|
+
}],
|
|
778
|
+
multiple: [{
|
|
779
|
+
type: Input,
|
|
780
|
+
args: [{
|
|
781
|
+
alias: 'cdkListboxMultiple',
|
|
782
|
+
transform: booleanAttribute
|
|
783
|
+
}]
|
|
784
|
+
}],
|
|
785
|
+
disabled: [{
|
|
786
|
+
type: Input,
|
|
787
|
+
args: [{
|
|
788
|
+
alias: 'cdkListboxDisabled',
|
|
789
|
+
transform: booleanAttribute
|
|
790
|
+
}]
|
|
791
|
+
}],
|
|
792
|
+
useActiveDescendant: [{
|
|
793
|
+
type: Input,
|
|
794
|
+
args: [{
|
|
795
|
+
alias: 'cdkListboxUseActiveDescendant',
|
|
796
|
+
transform: booleanAttribute
|
|
797
|
+
}]
|
|
798
|
+
}],
|
|
799
|
+
orientation: [{
|
|
800
|
+
type: Input,
|
|
801
|
+
args: ['cdkListboxOrientation']
|
|
802
|
+
}],
|
|
803
|
+
compareWith: [{
|
|
804
|
+
type: Input,
|
|
805
|
+
args: ['cdkListboxCompareWith']
|
|
806
|
+
}],
|
|
807
|
+
navigationWrapDisabled: [{
|
|
808
|
+
type: Input,
|
|
809
|
+
args: [{
|
|
810
|
+
alias: 'cdkListboxNavigationWrapDisabled',
|
|
811
|
+
transform: booleanAttribute
|
|
812
|
+
}]
|
|
813
|
+
}],
|
|
814
|
+
navigateDisabledOptions: [{
|
|
815
|
+
type: Input,
|
|
816
|
+
args: [{
|
|
817
|
+
alias: 'cdkListboxNavigatesDisabledOptions',
|
|
818
|
+
transform: booleanAttribute
|
|
819
|
+
}]
|
|
820
|
+
}],
|
|
821
|
+
valueChange: [{
|
|
822
|
+
type: Output,
|
|
823
|
+
args: ['cdkListboxValueChange']
|
|
824
|
+
}],
|
|
825
|
+
options: [{
|
|
826
|
+
type: ContentChildren,
|
|
827
|
+
args: [CdkOption, {
|
|
828
|
+
descendants: true
|
|
829
|
+
}]
|
|
830
|
+
}]
|
|
831
|
+
}
|
|
832
|
+
});
|
|
912
833
|
|
|
913
834
|
const EXPORTED_DECLARATIONS = [CdkListbox, CdkOption];
|
|
914
835
|
class CdkListboxModule {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
836
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
837
|
+
minVersion: "12.0.0",
|
|
838
|
+
version: "20.2.0-next.2",
|
|
839
|
+
ngImport: i0,
|
|
840
|
+
type: CdkListboxModule,
|
|
841
|
+
deps: [],
|
|
842
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
843
|
+
});
|
|
844
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({
|
|
845
|
+
minVersion: "14.0.0",
|
|
846
|
+
version: "20.2.0-next.2",
|
|
847
|
+
ngImport: i0,
|
|
848
|
+
type: CdkListboxModule,
|
|
849
|
+
imports: [CdkListbox, CdkOption],
|
|
850
|
+
exports: [CdkListbox, CdkOption]
|
|
851
|
+
});
|
|
852
|
+
static ɵinj = i0.ɵɵngDeclareInjector({
|
|
853
|
+
minVersion: "12.0.0",
|
|
854
|
+
version: "20.2.0-next.2",
|
|
855
|
+
ngImport: i0,
|
|
856
|
+
type: CdkListboxModule
|
|
857
|
+
});
|
|
918
858
|
}
|
|
919
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
859
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
860
|
+
minVersion: "12.0.0",
|
|
861
|
+
version: "20.2.0-next.2",
|
|
862
|
+
ngImport: i0,
|
|
863
|
+
type: CdkListboxModule,
|
|
864
|
+
decorators: [{
|
|
865
|
+
type: NgModule,
|
|
866
|
+
args: [{
|
|
867
|
+
imports: [...EXPORTED_DECLARATIONS],
|
|
868
|
+
exports: [...EXPORTED_DECLARATIONS]
|
|
869
|
+
}]
|
|
870
|
+
}]
|
|
871
|
+
});
|
|
926
872
|
|
|
927
873
|
export { CdkListbox, CdkListboxModule, CdkOption };
|
|
928
874
|
//# sourceMappingURL=listbox.mjs.map
|