UNPKG

20.7 kBTypeScriptView Raw
1import { _AbstractConstructor } from '@angular/material/core';
2import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
3import { AfterContentInit } from '@angular/core';
4import { AfterViewInit } from '@angular/core';
5import { BooleanInput } from '@angular/cdk/coercion';
6import { CanDisableRipple } from '@angular/material/core';
7import { ChangeDetectorRef } from '@angular/core';
8import { _Constructor } from '@angular/material/core';
9import { ControlValueAccessor } from '@angular/forms';
10import { Directionality } from '@angular/cdk/bidi';
11import { ElementRef } from '@angular/core';
12import { EventEmitter } from '@angular/core';
13import * as i0 from '@angular/core';
14import * as i4 from '@angular/cdk/overlay';
15import * as i5 from '@angular/material/core';
16import * as i6 from '@angular/common';
17import * as i7 from '@angular/cdk/scrolling';
18import { InjectionToken } from '@angular/core';
19import { MatFormField } from '@angular/material/form-field';
20import { MatOptgroup } from '@angular/material/core';
21import { _MatOptgroupBase } from '@angular/material/core';
22import { MatOption } from '@angular/material/core';
23import { _MatOptionBase } from '@angular/material/core';
24import { MatOptionSelectionChange } from '@angular/material/core';
25import { NgZone } from '@angular/core';
26import { Observable } from 'rxjs';
27import { OnChanges } from '@angular/core';
28import { OnDestroy } from '@angular/core';
29import { Overlay } from '@angular/cdk/overlay';
30import { Platform } from '@angular/cdk/platform';
31import { QueryList } from '@angular/core';
32import { ScrollStrategy } from '@angular/cdk/overlay';
33import { SimpleChanges } from '@angular/core';
34import { TemplateRef } from '@angular/core';
35import { ViewContainerRef } from '@angular/core';
36import { ViewportRuler } from '@angular/cdk/scrolling';
37
38/**
39 * Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
40 * @docs-private
41 */
42export declare function getMatAutocompleteMissingPanelError(): Error;
43
44declare namespace i1 {
45 export {
46 MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY,
47 MatAutocompleteSelectedEvent,
48 MatAutocompleteActivatedEvent,
49 MatAutocompleteDefaultOptions,
50 MAT_AUTOCOMPLETE_DEFAULT_OPTIONS,
51 _MatAutocompleteBase,
52 MatAutocomplete
53 }
54}
55
56declare namespace i2 {
57 export {
58 MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY,
59 getMatAutocompleteMissingPanelError,
60 MAT_AUTOCOMPLETE_SCROLL_STRATEGY,
61 MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER,
62 MAT_AUTOCOMPLETE_VALUE_ACCESSOR,
63 _MatAutocompleteTriggerBase,
64 MatAutocompleteTrigger
65 }
66}
67
68declare namespace i3 {
69 export {
70 _MatAutocompleteOriginBase,
71 MatAutocompleteOrigin
72 }
73}
74
75/** Injection token to be used to override the default options for `mat-autocomplete`. */
76export declare const MAT_AUTOCOMPLETE_DEFAULT_OPTIONS: InjectionToken<MatAutocompleteDefaultOptions>;
77
78/** @docs-private */
79export declare function MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY(): MatAutocompleteDefaultOptions;
80
81/** Injection token that determines the scroll handling while the autocomplete panel is open. */
82export declare const MAT_AUTOCOMPLETE_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
83
84/** @docs-private */
85export declare function MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
86
87/** @docs-private */
88export declare const MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER: {
89 provide: InjectionToken<() => ScrollStrategy>;
90 deps: (typeof Overlay)[];
91 useFactory: typeof MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY;
92};
93
94/**
95 * Provider that allows the autocomplete to register as a ControlValueAccessor.
96 * @docs-private
97 */
98export declare const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any;
99
100export declare class MatAutocomplete extends _MatAutocompleteBase {
101 /** Reference to all option groups within the autocomplete. */
102 optionGroups: QueryList<MatOptgroup>;
103 /** Reference to all options within the autocomplete. */
104 options: QueryList<MatOption>;
105 protected _visibleClass: string;
106 protected _hiddenClass: string;
107 static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocomplete, never>;
108 static ɵcmp: i0.ɵɵComponentDeclaration<MatAutocomplete, "mat-autocomplete", ["matAutocomplete"], { "disableRipple": "disableRipple"; }, {}, ["optionGroups", "options"], ["*"], false>;
109}
110
111/** Event object that is emitted when an autocomplete option is activated. */
112export declare interface MatAutocompleteActivatedEvent {
113 /** Reference to the autocomplete panel that emitted the event. */
114 source: _MatAutocompleteBase;
115 /** Option that was selected. */
116 option: _MatOptionBase | null;
117}
118
119/** Base class with all of the `MatAutocomplete` functionality. */
120export declare abstract class _MatAutocompleteBase extends _MatAutocompleteMixinBase implements AfterContentInit, CanDisableRipple, OnDestroy {
121 private _changeDetectorRef;
122 private _elementRef;
123 private _activeOptionChanges;
124 /** Class to apply to the panel when it's visible. */
125 protected abstract _visibleClass: string;
126 /** Class to apply to the panel when it's hidden. */
127 protected abstract _hiddenClass: string;
128 /** Manages active item in option list based on key events. */
129 _keyManager: ActiveDescendantKeyManager<_MatOptionBase>;
130 /** Whether the autocomplete panel should be visible, depending on option length. */
131 showPanel: boolean;
132 /** Whether the autocomplete panel is open. */
133 get isOpen(): boolean;
134 _isOpen: boolean;
135 /** @docs-private */
136 template: TemplateRef<any>;
137 /** Element for the panel containing the autocomplete options. */
138 panel: ElementRef;
139 /** Reference to all options within the autocomplete. */
140 abstract options: QueryList<_MatOptionBase>;
141 /** Reference to all option groups within the autocomplete. */
142 abstract optionGroups: QueryList<_MatOptgroupBase>;
143 /** Aria label of the autocomplete. */
144 ariaLabel: string;
145 /** Input that can be used to specify the `aria-labelledby` attribute. */
146 ariaLabelledby: string;
147 /** Function that maps an option's control value to its display value in the trigger. */
148 displayWith: ((value: any) => string) | null;
149 /**
150 * Whether the first option should be highlighted when the autocomplete panel is opened.
151 * Can be configured globally through the `MAT_AUTOCOMPLETE_DEFAULT_OPTIONS` token.
152 */
153 get autoActiveFirstOption(): boolean;
154 set autoActiveFirstOption(value: BooleanInput);
155 private _autoActiveFirstOption;
156 /** Whether the active option should be selected as the user is navigating. */
157 get autoSelectActiveOption(): boolean;
158 set autoSelectActiveOption(value: BooleanInput);
159 private _autoSelectActiveOption;
160 /**
161 * Specify the width of the autocomplete panel. Can be any CSS sizing value, otherwise it will
162 * match the width of its host.
163 */
164 panelWidth: string | number;
165 /** Event that is emitted whenever an option from the list is selected. */
166 readonly optionSelected: EventEmitter<MatAutocompleteSelectedEvent>;
167 /** Event that is emitted when the autocomplete panel is opened. */
168 readonly opened: EventEmitter<void>;
169 /** Event that is emitted when the autocomplete panel is closed. */
170 readonly closed: EventEmitter<void>;
171 /** Emits whenever an option is activated. */
172 readonly optionActivated: EventEmitter<MatAutocompleteActivatedEvent>;
173 /**
174 * Takes classes set on the host mat-autocomplete element and applies them to the panel
175 * inside the overlay container to allow for easy styling.
176 */
177 set classList(value: string | string[]);
178 _classList: {
179 [key: string]: boolean;
180 };
181 /** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
182 id: string;
183 /**
184 * Tells any descendant `mat-optgroup` to use the inert a11y pattern.
185 * @docs-private
186 */
187 readonly inertGroups: boolean;
188 constructor(_changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef<HTMLElement>, defaults: MatAutocompleteDefaultOptions, platform?: Platform);
189 ngAfterContentInit(): void;
190 ngOnDestroy(): void;
191 /**
192 * Sets the panel scrollTop. This allows us to manually scroll to display options
193 * above or below the fold, as they are not actually being focused when active.
194 */
195 _setScrollTop(scrollTop: number): void;
196 /** Returns the panel's scrollTop. */
197 _getScrollTop(): number;
198 /** Panel should hide itself when the option list is empty. */
199 _setVisibility(): void;
200 /** Emits the `select` event. */
201 _emitSelectEvent(option: _MatOptionBase): void;
202 /** Gets the aria-labelledby for the autocomplete panel. */
203 _getPanelAriaLabelledby(labelId: string | null): string | null;
204 /** Sets the autocomplete visibility classes on a classlist based on the panel is visible. */
205 private _setVisibilityClasses;
206 static ɵfac: i0.ɵɵFactoryDeclaration<_MatAutocompleteBase, never>;
207 static ɵdir: i0.ɵɵDirectiveDeclaration<_MatAutocompleteBase, never, never, { "ariaLabel": "aria-label"; "ariaLabelledby": "aria-labelledby"; "displayWith": "displayWith"; "autoActiveFirstOption": "autoActiveFirstOption"; "autoSelectActiveOption": "autoSelectActiveOption"; "panelWidth": "panelWidth"; "classList": "class"; }, { "optionSelected": "optionSelected"; "opened": "opened"; "closed": "closed"; "optionActivated": "optionActivated"; }, never, never, false>;
208}
209
210/** Default `mat-autocomplete` options that can be overridden. */
211export declare interface MatAutocompleteDefaultOptions {
212 /** Whether the first option should be highlighted when an autocomplete panel is opened. */
213 autoActiveFirstOption?: boolean;
214 /** Whether the active option should be selected as the user is navigating. */
215 autoSelectActiveOption?: boolean;
216 /** Class or list of classes to be applied to the autocomplete's overlay panel. */
217 overlayPanelClass?: string | string[];
218}
219
220/** @docs-private */
221declare const _MatAutocompleteMixinBase: _Constructor<CanDisableRipple> & _AbstractConstructor<CanDisableRipple> & {
222 new (): {};
223};
224
225export declare class MatAutocompleteModule {
226 static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteModule, never>;
227 static ɵmod: i0.ɵɵNgModuleDeclaration<MatAutocompleteModule, [typeof i1.MatAutocomplete, typeof i2.MatAutocompleteTrigger, typeof i3.MatAutocompleteOrigin], [typeof i4.OverlayModule, typeof i5.MatOptionModule, typeof i5.MatCommonModule, typeof i6.CommonModule], [typeof i1.MatAutocomplete, typeof i2.MatAutocompleteTrigger, typeof i3.MatAutocompleteOrigin, typeof i7.CdkScrollableModule, typeof i5.MatOptionModule, typeof i5.MatCommonModule]>;
228 static ɵinj: i0.ɵɵInjectorDeclaration<MatAutocompleteModule>;
229}
230
231/**
232 * Directive applied to an element to make it usable
233 * as a connection point for an autocomplete panel.
234 */
235export declare class MatAutocompleteOrigin extends _MatAutocompleteOriginBase {
236 static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteOrigin, never>;
237 static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteOrigin, "[matAutocompleteOrigin]", ["matAutocompleteOrigin"], {}, {}, never, never, false>;
238}
239
240/** Base class containing all of the functionality for `MatAutocompleteOrigin`. */
241export declare abstract class _MatAutocompleteOriginBase {
242 /** Reference to the element on which the directive is applied. */
243 elementRef: ElementRef<HTMLElement>;
244 constructor(
245 /** Reference to the element on which the directive is applied. */
246 elementRef: ElementRef<HTMLElement>);
247 static ɵfac: i0.ɵɵFactoryDeclaration<_MatAutocompleteOriginBase, never>;
248 static ɵdir: i0.ɵɵDirectiveDeclaration<_MatAutocompleteOriginBase, never, never, {}, {}, never, never, false>;
249}
250
251/** Event object that is emitted when an autocomplete option is selected. */
252export declare class MatAutocompleteSelectedEvent {
253 /** Reference to the autocomplete panel that emitted the event. */
254 source: _MatAutocompleteBase;
255 /** Option that was selected. */
256 option: _MatOptionBase;
257 constructor(
258 /** Reference to the autocomplete panel that emitted the event. */
259 source: _MatAutocompleteBase,
260 /** Option that was selected. */
261 option: _MatOptionBase);
262}
263
264export declare class MatAutocompleteTrigger extends _MatAutocompleteTriggerBase {
265 protected _aboveClass: string;
266 static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteTrigger, never>;
267 static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteTrigger, "input[matAutocomplete], textarea[matAutocomplete]", ["matAutocompleteTrigger"], {}, {}, never, never, false>;
268}
269
270/** Base class with all of the `MatAutocompleteTrigger` functionality. */
271export declare abstract class _MatAutocompleteTriggerBase implements ControlValueAccessor, AfterViewInit, OnChanges, OnDestroy {
272 private _element;
273 private _overlay;
274 private _viewContainerRef;
275 private _zone;
276 private _changeDetectorRef;
277 private _dir;
278 private _formField;
279 private _document;
280 private _viewportRuler;
281 private _defaults?;
282 private _overlayRef;
283 private _portal;
284 private _componentDestroyed;
285 private _autocompleteDisabled;
286 private _scrollStrategy;
287 /** Old value of the native input. Used to work around issues with the `input` event on IE. */
288 private _previousValue;
289 /** Strategy that is used to position the panel. */
290 private _positionStrategy;
291 /** Whether or not the label state is being overridden. */
292 private _manuallyFloatingLabel;
293 /** The subscription for closing actions (some are bound to document). */
294 private _closingActionsSubscription;
295 /** Subscription to viewport size changes. */
296 private _viewportSubscription;
297 /**
298 * Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
299 * closed autocomplete from being reopened if the user switches to another browser tab and then
300 * comes back.
301 */
302 private _canOpenOnNextFocus;
303 /** Value inside the input before we auto-selected an option. */
304 private _valueBeforeAutoSelection;
305 /**
306 * Current option that we have auto-selected as the user is navigating,
307 * but which hasn't been propagated to the model value yet.
308 */
309 private _pendingAutoselectedOption;
310 /** Stream of keyboard events that can close the panel. */
311 private readonly _closeKeyEventStream;
312 /**
313 * Event handler for when the window is blurred. Needs to be an
314 * arrow function in order to preserve the context.
315 */
316 private _windowBlurHandler;
317 /** `View -> model callback called when value changes` */
318 _onChange: (value: any) => void;
319 /** `View -> model callback called when autocomplete has been touched` */
320 _onTouched: () => void;
321 /** The autocomplete panel to be attached to this trigger. */
322 autocomplete: _MatAutocompleteBase;
323 /**
324 * Position of the autocomplete panel relative to the trigger element. A position of `auto`
325 * will render the panel underneath the trigger if there is enough space for it to fit in
326 * the viewport, otherwise the panel will be shown above it. If the position is set to
327 * `above` or `below`, the panel will always be shown above or below the trigger. no matter
328 * whether it fits completely in the viewport.
329 */
330 position: 'auto' | 'above' | 'below';
331 /**
332 * Reference relative to which to position the autocomplete panel.
333 * Defaults to the autocomplete trigger element.
334 */
335 connectedTo: _MatAutocompleteOriginBase;
336 /**
337 * `autocomplete` attribute to be set on the input element.
338 * @docs-private
339 */
340 autocompleteAttribute: string;
341 /**
342 * Whether the autocomplete is disabled. When disabled, the element will
343 * act as a regular input and the user won't be able to open the panel.
344 */
345 get autocompleteDisabled(): boolean;
346 set autocompleteDisabled(value: BooleanInput);
347 constructor(_element: ElementRef<HTMLInputElement>, _overlay: Overlay, _viewContainerRef: ViewContainerRef, _zone: NgZone, _changeDetectorRef: ChangeDetectorRef, scrollStrategy: any, _dir: Directionality, _formField: MatFormField, _document: any, _viewportRuler: ViewportRuler, _defaults?: MatAutocompleteDefaultOptions | undefined);
348 /** Class to apply to the panel when it's above the input. */
349 protected abstract _aboveClass: string;
350 ngAfterViewInit(): void;
351 ngOnChanges(changes: SimpleChanges): void;
352 ngOnDestroy(): void;
353 /** Whether or not the autocomplete panel is open. */
354 get panelOpen(): boolean;
355 private _overlayAttached;
356 /** Opens the autocomplete suggestion panel. */
357 openPanel(): void;
358 /** Closes the autocomplete suggestion panel. */
359 closePanel(): void;
360 /**
361 * Updates the position of the autocomplete suggestion panel to ensure that it fits all options
362 * within the viewport.
363 */
364 updatePosition(): void;
365 /**
366 * A stream of actions that should close the autocomplete panel, including
367 * when an option is selected, on blur, and when TAB is pressed.
368 */
369 get panelClosingActions(): Observable<MatOptionSelectionChange | null>;
370 /** Stream of changes to the selection state of the autocomplete options. */
371 readonly optionSelections: Observable<MatOptionSelectionChange>;
372 /** The currently active option, coerced to MatOption type. */
373 get activeOption(): _MatOptionBase | null;
374 /** Stream of clicks outside of the autocomplete panel. */
375 private _getOutsideClickStream;
376 writeValue(value: any): void;
377 registerOnChange(fn: (value: any) => {}): void;
378 registerOnTouched(fn: () => {}): void;
379 setDisabledState(isDisabled: boolean): void;
380 _handleKeydown(event: KeyboardEvent): void;
381 _handleInput(event: KeyboardEvent): void;
382 _handleFocus(): void;
383 _handleClick(): void;
384 /**
385 * In "auto" mode, the label will animate down as soon as focus is lost.
386 * This causes the value to jump when selecting an option with the mouse.
387 * This method manually floats the label until the panel can be closed.
388 * @param shouldAnimate Whether the label should be animated when it is floated.
389 */
390 private _floatLabel;
391 /** If the label has been manually elevated, return it to its normal state. */
392 private _resetLabel;
393 /**
394 * This method listens to a stream of panel closing actions and resets the
395 * stream every time the option list changes.
396 */
397 private _subscribeToClosingActions;
398 /** Destroys the autocomplete suggestion panel. */
399 private _destroyPanel;
400 private _assignOptionValue;
401 private _updateNativeInputValue;
402 /**
403 * This method closes the panel, and if a value is specified, also sets the associated
404 * control to that value. It will also mark the control as dirty if this interaction
405 * stemmed from the user.
406 */
407 private _setValueAndClose;
408 /**
409 * Clear any previous selected option and emit a selection change event for this option
410 */
411 private _clearPreviousSelectedOption;
412 private _attachOverlay;
413 private _getOverlayConfig;
414 private _getOverlayPosition;
415 /** Sets the positions on a position strategy based on the directive's input state. */
416 private _setStrategyPositions;
417 private _getConnectedElement;
418 private _getPanelWidth;
419 /** Returns the width of the input element, so the panel width can match it. */
420 private _getHostWidth;
421 /**
422 * Resets the active item to -1 so arrow events will activate the
423 * correct options, or to 0 if the consumer opted into it.
424 */
425 private _resetActiveItem;
426 /** Determines whether the panel can be opened. */
427 private _canOpen;
428 /** Use defaultView of injected document if available or fallback to global window reference */
429 private _getWindow;
430 /** Scrolls to a particular option in the list. */
431 private _scrollToOption;
432 /** Handles keyboard events coming from the overlay panel. */
433 private _handleOverlayEvents;
434 static ɵfac: i0.ɵɵFactoryDeclaration<_MatAutocompleteTriggerBase, [null, null, null, null, null, null, { optional: true; }, { optional: true; host: true; }, { optional: true; }, null, { optional: true; }]>;
435 static ɵdir: i0.ɵɵDirectiveDeclaration<_MatAutocompleteTriggerBase, never, never, { "autocomplete": "matAutocomplete"; "position": "matAutocompletePosition"; "connectedTo": "matAutocompleteConnectedTo"; "autocompleteAttribute": "autocomplete"; "autocompleteDisabled": "matAutocompleteDisabled"; }, {}, never, never, false>;
436}
437
438export { }