@angular/cdk-experimental 14.0.3 → 14.1.0-next.2

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.
@@ -1,114 +1,244 @@
1
+ import { AbstractControl } from '@angular/forms';
1
2
  import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
2
3
  import { AfterContentInit } from '@angular/core';
4
+ import { BehaviorSubject } from 'rxjs';
3
5
  import { BooleanInput } from '@angular/cdk/coercion';
4
- import { CdkCombobox } from '@angular/cdk-experimental/combobox';
6
+ import { ChangeDetectorRef } from '@angular/core';
5
7
  import { ControlValueAccessor } from '@angular/forms';
6
- import { Directionality } from '@angular/cdk/bidi';
7
- import { ElementRef } from '@angular/core';
8
- import { EventEmitter } from '@angular/core';
9
8
  import { Highlightable } from '@angular/cdk/a11y';
10
9
  import * as i0 from '@angular/core';
11
- import { InjectionToken } from '@angular/core';
12
10
  import { ListKeyManagerOption } from '@angular/cdk/a11y';
13
- import { Observable } from 'rxjs';
14
11
  import { OnDestroy } from '@angular/core';
15
- import { OnInit } from '@angular/core';
16
12
  import { QueryList } from '@angular/core';
17
13
  import { SelectionModel } from '@angular/cdk/collections';
18
- import { Type } from '@angular/core';
14
+ import { Subject } from 'rxjs';
15
+ import { ValidationErrors } from '@angular/forms';
16
+ import { Validator } from '@angular/forms';
19
17
 
20
- export declare const CDK_LISTBOX_VALUE_ACCESSOR: {
21
- provide: InjectionToken<readonly ControlValueAccessor[]>;
22
- useExisting: Type<any>;
23
- multi: boolean;
24
- };
25
-
26
- export declare class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, ControlValueAccessor {
27
- private readonly _combobox;
28
- private readonly _dir?;
29
- _listKeyManager: ActiveDescendantKeyManager<CdkOption<T>>;
30
- _selectionModel: SelectionModel<CdkOption<T>>;
31
- _tabIndex: number;
32
- /** `View -> model callback called when select has been touched` */
33
- _onTouched: () => void;
34
- /** `View -> model callback called when value changes` */
35
- _onChange: (value: T) => void;
36
- readonly optionSelectionChanges: Observable<OptionSelectionChangeEvent<T>>;
37
- private _disabled;
38
- private _multiple;
39
- private _useActiveDescendant;
40
- private _autoFocus;
41
- private _activeOption;
42
- private readonly _destroyed;
43
- _options: QueryList<CdkOption<T>>;
44
- readonly selectionChange: EventEmitter<ListboxSelectionChangeEvent<T>>;
45
- id: string;
18
+ export declare class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, ControlValueAccessor, Validator {
19
+ /** The id of the option's host element. */
20
+ get id(): string;
21
+ set id(value: string);
22
+ private _id;
23
+ private _generatedId;
24
+ /** The tabindex to use when the listbox is enabled. */
25
+ get enabledTabIndex(): number | null;
26
+ set enabledTabIndex(value: number | null);
27
+ private _enabledTabIndex?;
28
+ /** The value selected in the listbox, represented as an array of option values. */
29
+ get value(): readonly T[];
30
+ set value(value: readonly T[]);
46
31
  /**
47
- * Whether the listbox allows multiple options to be selected.
48
- * If `multiple` switches from `true` to `false`, all options are deselected.
32
+ * Whether the listbox allows multiple options to be selected. If the value switches from `true`
33
+ * to `false`, and more than one option is selected, all options are deselected.
49
34
  */
50
35
  get multiple(): boolean;
51
36
  set multiple(value: BooleanInput);
37
+ private _multiple;
38
+ /** Whether the listbox is disabled. */
52
39
  get disabled(): boolean;
53
40
  set disabled(value: BooleanInput);
41
+ private _disabled;
54
42
  /** Whether the listbox will use active descendant or will move focus onto the options. */
55
43
  get useActiveDescendant(): boolean;
56
44
  set useActiveDescendant(shouldUseActiveDescendant: BooleanInput);
57
- /** Whether on focus the listbox will focus its active option, default to true. */
58
- get autoFocus(): boolean;
59
- set autoFocus(shouldAutoFocus: BooleanInput);
60
- /** Determines the orientation for the list key manager. Affects keyboard interaction. */
45
+ private _useActiveDescendant;
46
+ /** The orientation of the listbox. Only affects keyboard interaction, not visual layout. */
61
47
  orientation: 'horizontal' | 'vertical';
62
- compareWith: (o1: T, o2: T) => boolean;
63
- constructor(_combobox: CdkCombobox, _dir?: Directionality | undefined);
64
- ngOnInit(): void;
48
+ /** The function used to compare option values. */
49
+ get compareWith(): undefined | ((o1: T, o2: T) => boolean);
50
+ set compareWith(fn: undefined | ((o1: T, o2: T) => boolean));
51
+ private _compareWith?;
52
+ /** Emits when the selected value(s) in the listbox change. */
53
+ readonly valueChange: Subject<ListboxValueChangeEvent<T>>;
54
+ /** The child options in this listbox. */
55
+ protected options: QueryList<CdkOption<T>>;
56
+ /** The selection model used by the listbox. */
57
+ protected selectionModelSubject: BehaviorSubject<SelectionModel<T>>;
58
+ /** The key manager that manages keyboard navigation for this listbox. */
59
+ protected listKeyManager: ActiveDescendantKeyManager<CdkOption<T>>;
60
+ /** Emits when the listbox is destroyed. */
61
+ protected readonly destroyed: Subject<void>;
62
+ /** The host element of the listbox. */
63
+ protected readonly element: HTMLElement;
64
+ /** The change detector for this listbox. */
65
+ protected readonly changeDetectorRef: ChangeDetectorRef;
66
+ /** Callback called when the listbox has been touched */
67
+ private _onTouched;
68
+ /** Callback called when the listbox value changes */
69
+ private _onChange;
70
+ /** Callback called when the form validator changes. */
71
+ private _onValidatorChange;
72
+ /** Emits when an option has been clicked. */
73
+ private _optionClicked;
74
+ /** The directionality of the page. */
75
+ private readonly _dir;
76
+ private readonly _combobox;
77
+ /**
78
+ * Validator that produces an error if multiple values are selected in a single selection
79
+ * listbox.
80
+ * @param control The control to validate
81
+ * @return A validation error or null
82
+ */
83
+ private _validateMultipleValues;
84
+ /**
85
+ * Validator that produces an error if any selected values are not valid options for this listbox.
86
+ * @param control The control to validate
87
+ * @return A validation error or null
88
+ */
89
+ private _validateInvalidValues;
90
+ /** The combined set of validators for this listbox. */
91
+ private _validators;
92
+ constructor();
65
93
  ngAfterContentInit(): void;
66
94
  ngOnDestroy(): void;
67
- private _initKeyManager;
68
- private _initSelectionModel;
69
- _keydown(event: KeyboardEvent): void;
70
- /** Emits a selection change event, called when an option has its selected state changed. */
71
- _emitChangeEvent(option: CdkOption<T>): void;
72
- /** Updates the selection model after a toggle. */
73
- _updateSelectionModel(option: CdkOption<T>): void;
74
- _updatePanelForSelection(option: CdkOption<T>): void;
75
- /** Toggles the selected state of the active option if not disabled. */
76
- private _toggleActiveOption;
77
- /** Returns the id of the active option if active descendant is being used. */
78
- _getAriaActiveDescendant(): string | null | undefined;
79
- /** Updates the activeOption and the active and focus properties of the option. */
80
- private _updateActiveOption;
81
- /** Updates selection states of options when the 'multiple' property changes. */
82
- private _updateSelectionOnMultiSelectionChange;
83
- _focusActiveOption(): void;
84
- /** Selects the given option if the option and listbox aren't disabled. */
95
+ /**
96
+ * Toggle the selected state of the given option.
97
+ * @param option The option to toggle
98
+ */
99
+ toggle(option: CdkOption<T>): void;
100
+ /**
101
+ * Toggle the selected state of the given value.
102
+ * @param value The value to toggle
103
+ */
104
+ toggleValue(value: T): void;
105
+ /**
106
+ * Select the given option.
107
+ * @param option The option to select
108
+ */
85
109
  select(option: CdkOption<T>): void;
86
- /** Deselects the given option if the option and listbox aren't disabled. */
110
+ /**
111
+ * Select the given value.
112
+ * @param value The value to select
113
+ */
114
+ selectValue(value: T): void;
115
+ /**
116
+ * Deselect the given option.
117
+ * @param option The option to deselect
118
+ */
87
119
  deselect(option: CdkOption<T>): void;
88
- /** Sets the selected state of all options to be the given value. */
120
+ /**
121
+ * Deselect the given value.
122
+ * @param value The value to deselect
123
+ */
124
+ deselectValue(value: T): void;
125
+ /**
126
+ * Set the selected state of all options.
127
+ * @param isSelected The new selected state to set
128
+ */
89
129
  setAllSelected(isSelected: boolean): void;
90
- /** Updates the key manager's active item to the given option. */
91
- setActiveOption(option: CdkOption<T>): void;
92
130
  /**
93
- * Saves a callback function to be invoked when the select's value
94
- * changes from user input. Required to implement ControlValueAccessor.
131
+ * Get whether the given option is selected.
132
+ * @param option The option to get the selected state of
133
+ */
134
+ isSelected(option: CdkOption<T> | T): boolean;
135
+ /**
136
+ * Registers a callback to be invoked when the listbox's value changes from user input.
137
+ * @param fn The callback to register
138
+ * @docs-private
95
139
  */
96
- registerOnChange(fn: (value: T) => void): void;
140
+ registerOnChange(fn: (value: readonly T[]) => void): void;
97
141
  /**
98
- * Saves a callback function to be invoked when the select is blurred
99
- * by the user. Required to implement ControlValueAccessor.
142
+ * Registers a callback to be invoked when the listbox is blurred by the user.
143
+ * @param fn The callback to register
144
+ * @docs-private
100
145
  */
101
146
  registerOnTouched(fn: () => {}): void;
102
- /** Sets the select's value. Required to implement ControlValueAccessor. */
103
- writeValue(values: T | T[]): void;
104
- /** Disables the select. Required to implement ControlValueAccessor. */
147
+ /**
148
+ * Sets the listbox's value.
149
+ * @param value The new value of the listbox
150
+ * @docs-private
151
+ */
152
+ writeValue(value: readonly T[]): void;
153
+ /**
154
+ * Sets the disabled state of the listbox.
155
+ * @param isDisabled The new disabled state
156
+ * @docs-private
157
+ */
105
158
  setDisabledState(isDisabled: boolean): void;
106
- /** Returns the values of the currently selected options. */
107
- getSelectedValues(): T[];
108
- /** Selects an option that has the corresponding given value. */
109
- private _setSelectionByValue;
110
- static ɵfac: i0.ɵɵFactoryDeclaration<CdkListbox<any>, [{ optional: true; }, { optional: true; }]>;
111
- static ɵdir: i0.ɵɵDirectiveDeclaration<CdkListbox<any>, "[cdkListbox]", ["cdkListbox"], { "id": "id"; "multiple": "multiple"; "disabled": "disabled"; "useActiveDescendant": "useActiveDescendant"; "autoFocus": "autoFocus"; "orientation": "listboxOrientation"; "compareWith": "compareWith"; }, { "selectionChange": "selectionChange"; }, ["_options"], never, false>;
159
+ /**
160
+ * Validate the given control
161
+ * @docs-private
162
+ */
163
+ validate(control: AbstractControl<any, any>): ValidationErrors | null;
164
+ /**
165
+ * Registers a callback to be called when the form validator changes.
166
+ * @param fn The callback to call
167
+ * @docs-private
168
+ */
169
+ registerOnValidatorChange(fn: () => void): void;
170
+ /** Focus the listbox's host element. */
171
+ focus(): void;
172
+ /** The selection model used to track the listbox's value. */
173
+ protected selectionModel(): SelectionModel<T>;
174
+ /**
175
+ * Triggers the given option in response to user interaction.
176
+ * - In single selection mode: selects the option and deselects any other selected option.
177
+ * - In multi selection mode: toggles the selected state of the option.
178
+ * @param option The option to trigger
179
+ */
180
+ protected triggerOption(option: CdkOption<T> | null): void;
181
+ /**
182
+ * Sets the given option as active.
183
+ * @param option The option to make active
184
+ */
185
+ _setActiveOption(option: CdkOption<T>): void;
186
+ /** Called when the listbox receives focus. */
187
+ protected _handleFocus(): void;
188
+ /** Called when the user presses keydown on the listbox. */
189
+ protected _handleKeydown(event: KeyboardEvent): void;
190
+ /**
191
+ * Called when the focus leaves an element in the listbox.
192
+ * @param event The focusout event
193
+ */
194
+ protected _handleFocusOut(event: FocusEvent): void;
195
+ /** Get the id of the active option if active descendant is being used. */
196
+ protected _getAriaActiveDescendant(): string | null | undefined;
197
+ /** Get the tabindex for the listbox. */
198
+ protected _getTabIndex(): number | null;
199
+ /** Initialize the key manager. */
200
+ private _initKeyManager;
201
+ private _updatePanelForSelection;
202
+ /** Update the selection mode when the 'multiple' property changes. */
203
+ private _updateSelectionModel;
204
+ /** Focus the active option. */
205
+ private _focusActiveOption;
206
+ /**
207
+ * Set the selected values.
208
+ * @param value The list of new selected values.
209
+ */
210
+ private _setSelection;
211
+ /** Update the internal value of the listbox based on the selection model. */
212
+ private _updateInternalValue;
213
+ /**
214
+ * Gets the index of the given value in the given list of options.
215
+ * @param cache The cache of indices found so far
216
+ * @param value The value to find
217
+ * @return The index of the value in the options list
218
+ */
219
+ private _getIndexForValue;
220
+ /**
221
+ * Handle the user clicking an option.
222
+ * @param option The option that was clicked.
223
+ */
224
+ private _handleOptionClicked;
225
+ /** Verifies that no two options represent the same value under the compareWith function. */
226
+ private _verifyNoOptionValueCollisions;
227
+ /**
228
+ * Coerces a value into an array representing a listbox selection.
229
+ * @param value The value to coerce
230
+ * @return An array
231
+ */
232
+ private _coerceValue;
233
+ /**
234
+ * Get the sublist of values with the given validity.
235
+ * @param values The list of values
236
+ * @param valid Whether to get valid values
237
+ * @return The sublist of values with the requested validity
238
+ */
239
+ private _getValuesWithValidity;
240
+ static ɵfac: i0.ɵɵFactoryDeclaration<CdkListbox<any>, never>;
241
+ static ɵdir: i0.ɵɵDirectiveDeclaration<CdkListbox<any>, "[cdkListbox]", ["cdkListbox"], { "id": "id"; "enabledTabIndex": "tabindex"; "value": "cdkListboxValue"; "multiple": "cdkListboxMultiple"; "disabled": "cdkListboxDisabled"; "useActiveDescendant": "cdkListboxUseActiveDescendant"; "orientation": "cdkListboxOrientation"; "compareWith": "cdkListboxCompareWith"; }, { "valueChange": "cdkListboxValueChange"; }, ["options"], never, false>;
112
242
  }
113
243
 
114
244
  export declare class CdkListboxModule {
@@ -117,81 +247,87 @@ export declare class CdkListboxModule {
117
247
  static ɵinj: i0.ɵɵInjectorDeclaration<CdkListboxModule>;
118
248
  }
119
249
 
120
- export declare class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightable {
121
- private readonly _elementRef;
122
- readonly listbox: CdkListbox<T>;
123
- private _selected;
124
- private _disabled;
125
- private _value;
126
- _active: boolean;
127
- /** The id of the option, set to a uniqueid if the user does not provide one. */
128
- id: string;
129
- get selected(): boolean;
130
- set selected(value: BooleanInput);
131
- get disabled(): boolean;
132
- set disabled(value: BooleanInput);
133
- /** The form value of the option. */
134
- get value(): T;
135
- set value(value: T);
250
+ /** A selectable option in a listbox. */
251
+ export declare class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightable, OnDestroy {
252
+ /** The id of the option's host element. */
253
+ get id(): string;
254
+ set id(value: string);
255
+ private _id;
256
+ private _generatedId;
257
+ /** The value of this option. */
258
+ value: T;
136
259
  /**
137
- * The text used to locate this item during menu typeahead. If not specified,
260
+ * The text used to locate this item during listbox typeahead. If not specified,
138
261
  * the `textContent` of the item will be used.
139
262
  */
140
- typeahead: string;
141
- readonly selectionChange: EventEmitter<OptionSelectionChangeEvent<T>>;
142
- constructor(_elementRef: ElementRef, listbox: CdkListbox<T>);
143
- /** Toggles the selected state, emits a change event through the injected listbox. */
263
+ typeaheadLabel: string;
264
+ /** Whether this option is disabled. */
265
+ get disabled(): boolean;
266
+ set disabled(value: BooleanInput);
267
+ private _disabled;
268
+ /** The tabindex of the option when it is enabled. */
269
+ get enabledTabIndex(): number | null;
270
+ set enabledTabIndex(value: number | null);
271
+ private _enabledTabIndex?;
272
+ /** The option's host element */
273
+ readonly element: HTMLElement;
274
+ /** The parent listbox this option belongs to. */
275
+ protected readonly listbox: CdkListbox<T>;
276
+ /** Emits when the option is destroyed. */
277
+ protected destroyed: Subject<void>;
278
+ /** Emits when the option is clicked. */
279
+ readonly _clicked: Subject<void>;
280
+ /** Whether the option is currently active. */
281
+ private _active;
282
+ ngOnDestroy(): void;
283
+ /** Whether this option is selected. */
284
+ isSelected(): boolean;
285
+ /** Whether this option is active. */
286
+ isActive(): boolean;
287
+ /** Toggle the selected state of this option. */
144
288
  toggle(): void;
145
- /** Sets the active property true if the option and listbox aren't disabled. */
146
- activate(): void;
147
- /** Sets the active property false. */
148
- deactivate(): void;
149
- /** Sets the selected property true if it was false. */
289
+ /** Select this option if it is not selected. */
150
290
  select(): void;
151
- /** Sets the selected property false if it was true. */
291
+ /** Deselect this option if it is selected. */
152
292
  deselect(): void;
153
- /** Applies focus to the option. */
293
+ /** Focus this option. */
154
294
  focus(): void;
155
- /** Returns true if the option or listbox are disabled, and false otherwise. */
156
- _isInteractionDisabled(): boolean;
157
- /** Emits a change event extending the Option Selection Change Event interface. */
158
- private _emitSelectionChange;
159
- /** Returns the tab index which depends on the disabled property. */
160
- _getTabIndex(): string | null;
161
295
  /** Get the label for this element which is required by the FocusableOption interface. */
162
296
  getLabel(): string;
163
- /** Sets the active property to true to enable the active css class. */
297
+ /**
298
+ * Set the option as active.
299
+ * @docs-private
300
+ */
164
301
  setActiveStyles(): void;
165
- /** Sets the active property to false to disable the active css class. */
302
+ /**
303
+ * Set the option as inactive.
304
+ * @docs-private
305
+ */
166
306
  setInactiveStyles(): void;
307
+ /** Handle focus events on the option. */
308
+ protected _handleFocus(): void;
309
+ /** Get the tabindex for this option. */
310
+ protected _getTabIndex(): number | null;
167
311
  static ɵfac: i0.ɵɵFactoryDeclaration<CdkOption<any>, never>;
168
- static ɵdir: i0.ɵɵDirectiveDeclaration<CdkOption<any>, "[cdkOption]", ["cdkOption"], { "id": "id"; "selected": "selected"; "disabled": "disabled"; "value": "value"; "typeahead": "typeahead"; }, { "selectionChange": "selectionChange"; }, never, never, false>;
312
+ static ɵdir: i0.ɵɵDirectiveDeclaration<CdkOption<any>, "[cdkOption]", ["cdkOption"], { "id": "id"; "value": "cdkOption"; "typeaheadLabel": "cdkOptionTypeaheadLabel"; "disabled": "cdkOptionDisabled"; "enabledTabIndex": "tabindex"; }, {}, never, never, false>;
169
313
  }
170
314
 
171
315
  declare namespace i1 {
172
316
  export {
173
- CDK_LISTBOX_VALUE_ACCESSOR,
174
317
  CdkOption,
175
318
  CdkListbox,
176
- ListboxSelectionChangeEvent,
177
- OptionSelectionChangeEvent
319
+ ListboxValueChangeEvent
178
320
  }
179
321
  }
180
322
 
181
- /** Change event that is being fired whenever the selected state of an option changes. */
182
- export declare interface ListboxSelectionChangeEvent<T> {
323
+ /** Change event that is fired whenever the value of the listbox changes. */
324
+ export declare interface ListboxValueChangeEvent<T> {
325
+ /** The new value of the listbox. */
326
+ readonly value: readonly T[];
183
327
  /** Reference to the listbox that emitted the event. */
184
- readonly source: CdkListbox<T>;
185
- /** Reference to the option that has been changed. */
328
+ readonly listbox: CdkListbox<T>;
329
+ /** Reference to the option that was triggered. */
186
330
  readonly option: CdkOption<T>;
187
331
  }
188
332
 
189
- /** Event object emitted by MatOption when selected or deselected. */
190
- export declare interface OptionSelectionChangeEvent<T> {
191
- /** Reference to the option that emitted the event. */
192
- source: CdkOption<T>;
193
- /** Whether the change in the option's value was a result of a user action. */
194
- isUserInput: boolean;
195
- }
196
-
197
333
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/cdk-experimental",
3
- "version": "14.0.3",
3
+ "version": "14.1.0-next.2",
4
4
  "description": "Experimental components for Angular CDK",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "homepage": "https://github.com/angular/components#readme",
14
14
  "peerDependencies": {
15
- "@angular/cdk": "14.0.3",
15
+ "@angular/cdk": "14.1.0-next.2",
16
16
  "@angular/core": "^14.0.0 || ^15.0.0"
17
17
  },
18
18
  "dependencies": {