UNPKG

15.3 kBTypeScriptView Raw
1import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
2import { AfterContentInit } from '@angular/core';
3import { BooleanInput } from '@angular/cdk/coercion';
4import { ChangeDetectorRef } from '@angular/core';
5import { ControlValueAccessor } from '@angular/forms';
6import { Highlightable } from '@angular/cdk/a11y';
7import * as i0 from '@angular/core';
8import { ListKeyManagerOption } from '@angular/cdk/a11y';
9import { OnDestroy } from '@angular/core';
10import { QueryList } from '@angular/core';
11import { SelectionModel } from '@angular/cdk/collections';
12import { Subject } from 'rxjs';
13
14export declare class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, ControlValueAccessor {
15 /** The id of the option's host element. */
16 get id(): string;
17 set id(value: string);
18 private _id;
19 private _generatedId;
20 /** The tabindex to use when the listbox is enabled. */
21 get enabledTabIndex(): number | null;
22 set enabledTabIndex(value: number | null);
23 private _enabledTabIndex?;
24 /** The value selected in the listbox, represented as an array of option values. */
25 get value(): readonly T[];
26 set value(value: readonly T[]);
27 /**
28 * Whether the listbox allows multiple options to be selected. If the value switches from `true`
29 * to `false`, and more than one option is selected, all options are deselected.
30 */
31 get multiple(): boolean;
32 set multiple(value: BooleanInput);
33 /** Whether the listbox is disabled. */
34 get disabled(): boolean;
35 set disabled(value: BooleanInput);
36 private _disabled;
37 /** Whether the listbox will use active descendant or will move focus onto the options. */
38 get useActiveDescendant(): boolean;
39 set useActiveDescendant(shouldUseActiveDescendant: BooleanInput);
40 private _useActiveDescendant;
41 /** The orientation of the listbox. Only affects keyboard interaction, not visual layout. */
42 get orientation(): 'horizontal' | 'vertical';
43 set orientation(value: 'horizontal' | 'vertical');
44 private _orientation;
45 /** The function used to compare option values. */
46 get compareWith(): undefined | ((o1: T, o2: T) => boolean);
47 set compareWith(fn: undefined | ((o1: T, o2: T) => boolean));
48 /**
49 * Whether the keyboard navigation should wrap when the user presses arrow down on the last item
50 * or arrow up on the first item.
51 */
52 get navigationWrapDisabled(): BooleanInput;
53 set navigationWrapDisabled(wrap: BooleanInput);
54 private _navigationWrapDisabled;
55 /** Whether keyboard navigation should skip over disabled items. */
56 get navigateDisabledOptions(): BooleanInput;
57 set navigateDisabledOptions(skip: BooleanInput);
58 private _navigateDisabledOptions;
59 /** Emits when the selected value(s) in the listbox change. */
60 readonly valueChange: Subject<ListboxValueChangeEvent<T>>;
61 /** The child options in this listbox. */
62 protected options: QueryList<CdkOption<T>>;
63 /** The selection model used by the listbox. */
64 protected selectionModel: ListboxSelectionModel<T>;
65 /** The key manager that manages keyboard navigation for this listbox. */
66 protected listKeyManager: ActiveDescendantKeyManager<CdkOption<T>>;
67 /** Emits when the listbox is destroyed. */
68 protected readonly destroyed: Subject<void>;
69 /** The host element of the listbox. */
70 protected readonly element: HTMLElement;
71 /** The change detector for this listbox. */
72 protected readonly changeDetectorRef: ChangeDetectorRef;
73 /** Whether the currently selected value in the selection model is invalid. */
74 private _invalid;
75 /** The last user-triggered option. */
76 private _lastTriggered;
77 /** Callback called when the listbox has been touched */
78 private _onTouched;
79 /** Callback called when the listbox value changes */
80 private _onChange;
81 /** Emits when an option has been clicked. */
82 private _optionClicked;
83 /** The directionality of the page. */
84 private readonly _dir;
85 /** A predicate that skips disabled options. */
86 private readonly _skipDisabledPredicate;
87 /** A predicate that does not skip any options. */
88 private readonly _skipNonePredicate;
89 /** Whether the listbox currently has focus. */
90 private _hasFocus;
91 ngAfterContentInit(): void;
92 ngOnDestroy(): void;
93 /**
94 * Toggle the selected state of the given option.
95 * @param option The option to toggle
96 */
97 toggle(option: CdkOption<T>): void;
98 /**
99 * Toggle the selected state of the given value.
100 * @param value The value to toggle
101 */
102 toggleValue(value: T): void;
103 /**
104 * Select the given option.
105 * @param option The option to select
106 */
107 select(option: CdkOption<T>): void;
108 /**
109 * Select the given value.
110 * @param value The value to select
111 */
112 selectValue(value: T): void;
113 /**
114 * Deselect the given option.
115 * @param option The option to deselect
116 */
117 deselect(option: CdkOption<T>): void;
118 /**
119 * Deselect the given value.
120 * @param value The value to deselect
121 */
122 deselectValue(value: T): void;
123 /**
124 * Set the selected state of all options.
125 * @param isSelected The new selected state to set
126 */
127 setAllSelected(isSelected: boolean): void;
128 /**
129 * Get whether the given option is selected.
130 * @param option The option to get the selected state of
131 */
132 isSelected(option: CdkOption<T>): boolean;
133 /**
134 * Get whether the given option is active.
135 * @param option The option to get the active state of
136 */
137 isActive(option: CdkOption<T>): boolean;
138 /**
139 * Get whether the given value is selected.
140 * @param value The value to get the selected state of
141 */
142 isValueSelected(value: T): boolean;
143 /**
144 * Registers a callback to be invoked when the listbox's value changes from user input.
145 * @param fn The callback to register
146 * @docs-private
147 */
148 registerOnChange(fn: (value: readonly T[]) => void): void;
149 /**
150 * Registers a callback to be invoked when the listbox is blurred by the user.
151 * @param fn The callback to register
152 * @docs-private
153 */
154 registerOnTouched(fn: () => {}): void;
155 /**
156 * Sets the listbox's value.
157 * @param value The new value of the listbox
158 * @docs-private
159 */
160 writeValue(value: readonly T[]): void;
161 /**
162 * Sets the disabled state of the listbox.
163 * @param isDisabled The new disabled state
164 * @docs-private
165 */
166 setDisabledState(isDisabled: boolean): void;
167 /** Focus the listbox's host element. */
168 focus(): void;
169 /**
170 * Triggers the given option in response to user interaction.
171 * - In single selection mode: selects the option and deselects any other selected option.
172 * - In multi selection mode: toggles the selected state of the option.
173 * @param option The option to trigger
174 */
175 protected triggerOption(option: CdkOption<T> | null): void;
176 /**
177 * Trigger the given range of options in response to user interaction.
178 * Should only be called in multi-selection mode.
179 * @param trigger The option that was triggered
180 * @param from The start index of the options to toggle
181 * @param to The end index of the options to toggle
182 * @param on Whether to toggle the option range on
183 */
184 protected triggerRange(trigger: CdkOption<T> | null, from: number, to: number, on: boolean): void;
185 /**
186 * Sets the given option as active.
187 * @param option The option to make active
188 */
189 _setActiveOption(option: CdkOption<T>): void;
190 /** Called when the listbox receives focus. */
191 protected _handleFocus(): void;
192 /** Called when the user presses keydown on the listbox. */
193 protected _handleKeydown(event: KeyboardEvent): void;
194 /** Called when a focus moves into the listbox. */
195 protected _handleFocusIn(): void;
196 /**
197 * Called when the focus leaves an element in the listbox.
198 * @param event The focusout event
199 */
200 protected _handleFocusOut(event: FocusEvent): void;
201 /** Get the id of the active option if active descendant is being used. */
202 protected _getAriaActiveDescendant(): string | null | undefined;
203 /** Get the tabindex for the listbox. */
204 protected _getTabIndex(): number | null;
205 /** Initialize the key manager. */
206 private _initKeyManager;
207 /** Focus the active option. */
208 private _focusActiveOption;
209 /**
210 * Set the selected values.
211 * @param value The list of new selected values.
212 */
213 private _setSelection;
214 /** Sets the first selected option as first in the keyboard focus order. */
215 private _setNextFocusToSelectedOption;
216 /** Update the internal value of the listbox based on the selection model. */
217 private _updateInternalValue;
218 /**
219 * Gets the index of the given value in the given list of options.
220 * @param cache The cache of indices found so far
221 * @param value The value to find
222 * @return The index of the value in the options list
223 */
224 private _getIndexForValue;
225 /**
226 * Handle the user clicking an option.
227 * @param option The option that was clicked.
228 */
229 private _handleOptionClicked;
230 /** Verifies that no two options represent the same value under the compareWith function. */
231 private _verifyNoOptionValueCollisions;
232 /** Verifies that the option values are valid. */
233 private _verifyOptionValues;
234 /**
235 * Coerces a value into an array representing a listbox selection.
236 * @param value The value to coerce
237 * @return An array
238 */
239 private _coerceValue;
240 /**
241 * Get the sublist of values that do not represent valid option values in this listbox.
242 * @param values The list of values
243 * @return The sublist of values that are not valid option values
244 */
245 private _getInvalidOptionValues;
246 /** Get the index of the last triggered option. */
247 private _getLastTriggeredIndex;
248 static ɵfac: i0.ɵɵFactoryDeclaration<CdkListbox<any>, never>;
249 static ɵdir: i0.ɵɵDirectiveDeclaration<CdkListbox<any>, "[cdkListbox]", ["cdkListbox"], { "id": { "alias": "id"; "required": false; }; "enabledTabIndex": { "alias": "tabindex"; "required": false; }; "value": { "alias": "cdkListboxValue"; "required": false; }; "multiple": { "alias": "cdkListboxMultiple"; "required": false; }; "disabled": { "alias": "cdkListboxDisabled"; "required": false; }; "useActiveDescendant": { "alias": "cdkListboxUseActiveDescendant"; "required": false; }; "orientation": { "alias": "cdkListboxOrientation"; "required": false; }; "compareWith": { "alias": "cdkListboxCompareWith"; "required": false; }; "navigationWrapDisabled": { "alias": "cdkListboxNavigationWrapDisabled"; "required": false; }; "navigateDisabledOptions": { "alias": "cdkListboxNavigatesDisabledOptions"; "required": false; }; }, { "valueChange": "cdkListboxValueChange"; }, ["options"], never, true, never>;
250}
251
252export declare class CdkListboxModule {
253 static ɵfac: i0.ɵɵFactoryDeclaration<CdkListboxModule, never>;
254 static ɵmod: i0.ɵɵNgModuleDeclaration<CdkListboxModule, never, [typeof i1.CdkListbox, typeof i1.CdkOption], [typeof i1.CdkListbox, typeof i1.CdkOption]>;
255 static ɵinj: i0.ɵɵInjectorDeclaration<CdkListboxModule>;
256}
257
258/** A selectable option in a listbox. */
259export declare class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightable, OnDestroy {
260 /** The id of the option's host element. */
261 get id(): string;
262 set id(value: string);
263 private _id;
264 private _generatedId;
265 /** The value of this option. */
266 value: T;
267 /**
268 * The text used to locate this item during listbox typeahead. If not specified,
269 * the `textContent` of the item will be used.
270 */
271 typeaheadLabel: string;
272 /** Whether this option is disabled. */
273 get disabled(): boolean;
274 set disabled(value: BooleanInput);
275 private _disabled;
276 /** The tabindex of the option when it is enabled. */
277 get enabledTabIndex(): number | null;
278 set enabledTabIndex(value: number | null);
279 private _enabledTabIndex?;
280 /** The option's host element */
281 readonly element: HTMLElement;
282 /** The parent listbox this option belongs to. */
283 protected readonly listbox: CdkListbox<T>;
284 /** Emits when the option is destroyed. */
285 protected destroyed: Subject<void>;
286 /** Emits when the option is clicked. */
287 readonly _clicked: Subject<MouseEvent>;
288 ngOnDestroy(): void;
289 /** Whether this option is selected. */
290 isSelected(): boolean;
291 /** Whether this option is active. */
292 isActive(): boolean;
293 /** Toggle the selected state of this option. */
294 toggle(): void;
295 /** Select this option if it is not selected. */
296 select(): void;
297 /** Deselect this option if it is selected. */
298 deselect(): void;
299 /** Focus this option. */
300 focus(): void;
301 /** Get the label for this element which is required by the FocusableOption interface. */
302 getLabel(): string;
303 /**
304 * No-op implemented as a part of `Highlightable`.
305 * @docs-private
306 */
307 setActiveStyles(): void;
308 /**
309 * No-op implemented as a part of `Highlightable`.
310 * @docs-private
311 */
312 setInactiveStyles(): void;
313 /** Handle focus events on the option. */
314 protected _handleFocus(): void;
315 /** Get the tabindex for this option. */
316 protected _getTabIndex(): number | null;
317 static ɵfac: i0.ɵɵFactoryDeclaration<CdkOption<any>, never>;
318 static ɵdir: i0.ɵɵDirectiveDeclaration<CdkOption<any>, "[cdkOption]", ["cdkOption"], { "id": { "alias": "id"; "required": false; }; "value": { "alias": "cdkOption"; "required": false; }; "typeaheadLabel": { "alias": "cdkOptionTypeaheadLabel"; "required": false; }; "disabled": { "alias": "cdkOptionDisabled"; "required": false; }; "enabledTabIndex": { "alias": "tabindex"; "required": false; }; }, {}, never, never, true, never>;
319}
320
321declare namespace i1 {
322 export {
323 CdkOption,
324 CdkListbox,
325 ListboxValueChangeEvent
326 }
327}
328
329/**
330 * An implementation of SelectionModel that internally always represents the selection as a
331 * multi-selection. This is necessary so that we can recover the full selection if the user
332 * switches the listbox from single-selection to multi-selection after initialization.
333 *
334 * This selection model may report multiple selected values, even if it is in single-selection
335 * mode. It is up to the user (CdkListbox) to check for invalid selections.
336 */
337declare class ListboxSelectionModel<T> extends SelectionModel<T> {
338 multiple: boolean;
339 constructor(multiple?: boolean, initiallySelectedValues?: T[], emitChanges?: boolean, compareWith?: (o1: T, o2: T) => boolean);
340 isMultipleSelection(): boolean;
341 select(...values: T[]): boolean | void;
342}
343
344/** Change event that is fired whenever the value of the listbox changes. */
345export declare interface ListboxValueChangeEvent<T> {
346 /** The new value of the listbox. */
347 readonly value: readonly T[];
348 /** Reference to the listbox that emitted the event. */
349 readonly listbox: CdkListbox<T>;
350 /** Reference to the option that was triggered. */
351 readonly option: CdkOption<T> | null;
352}
353
354export { }
355
\No newline at end of file