[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC All Rights Reserved.
|
---|
| 4 | *
|
---|
| 5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 6 | * found in the LICENSE file at https://angular.io/license
|
---|
| 7 | */
|
---|
| 8 | import { Directionality } from '@angular/cdk/bidi';
|
---|
| 9 | import { BooleanInput } from '@angular/cdk/coercion';
|
---|
| 10 | import { Overlay, ScrollStrategy } from '@angular/cdk/overlay';
|
---|
| 11 | import { ViewportRuler } from '@angular/cdk/scrolling';
|
---|
| 12 | import { AfterViewInit, ChangeDetectorRef, ElementRef, InjectionToken, NgZone, OnDestroy, ViewContainerRef, OnChanges, SimpleChanges } from '@angular/core';
|
---|
| 13 | import { ControlValueAccessor } from '@angular/forms';
|
---|
| 14 | import { MatOption, MatOptionSelectionChange } from '@angular/material/core';
|
---|
| 15 | import { MatFormField } from '@angular/material/form-field';
|
---|
| 16 | import { Observable } from 'rxjs';
|
---|
| 17 | import { _MatAutocompleteBase, MatAutocompleteDefaultOptions } from './autocomplete';
|
---|
| 18 | import { _MatAutocompleteOriginBase } from './autocomplete-origin';
|
---|
| 19 | /** Injection token that determines the scroll handling while the autocomplete panel is open. */
|
---|
| 20 | export declare const MAT_AUTOCOMPLETE_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
|
---|
| 21 | /** @docs-private */
|
---|
| 22 | export declare function MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
|
---|
| 23 | /** @docs-private */
|
---|
| 24 | export declare const MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER: {
|
---|
| 25 | provide: InjectionToken<() => ScrollStrategy>;
|
---|
| 26 | deps: (typeof Overlay)[];
|
---|
| 27 | useFactory: typeof MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY;
|
---|
| 28 | };
|
---|
| 29 | /**
|
---|
| 30 | * Provider that allows the autocomplete to register as a ControlValueAccessor.
|
---|
| 31 | * @docs-private
|
---|
| 32 | */
|
---|
| 33 | export declare const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any;
|
---|
| 34 | /**
|
---|
| 35 | * Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
|
---|
| 36 | * @docs-private
|
---|
| 37 | */
|
---|
| 38 | export declare function getMatAutocompleteMissingPanelError(): Error;
|
---|
| 39 | /** Base class with all of the `MatAutocompleteTrigger` functionality. */
|
---|
| 40 | export declare abstract class _MatAutocompleteTriggerBase implements ControlValueAccessor, AfterViewInit, OnChanges, OnDestroy {
|
---|
| 41 | private _element;
|
---|
| 42 | private _overlay;
|
---|
| 43 | private _viewContainerRef;
|
---|
| 44 | private _zone;
|
---|
| 45 | private _changeDetectorRef;
|
---|
| 46 | private _dir;
|
---|
| 47 | private _formField;
|
---|
| 48 | private _document;
|
---|
| 49 | private _viewportRuler;
|
---|
| 50 | private _defaults?;
|
---|
| 51 | private _overlayRef;
|
---|
| 52 | private _portal;
|
---|
| 53 | private _componentDestroyed;
|
---|
| 54 | private _autocompleteDisabled;
|
---|
| 55 | private _scrollStrategy;
|
---|
| 56 | /** Old value of the native input. Used to work around issues with the `input` event on IE. */
|
---|
| 57 | private _previousValue;
|
---|
| 58 | /** Strategy that is used to position the panel. */
|
---|
| 59 | private _positionStrategy;
|
---|
| 60 | /** Whether or not the label state is being overridden. */
|
---|
| 61 | private _manuallyFloatingLabel;
|
---|
| 62 | /** The subscription for closing actions (some are bound to document). */
|
---|
| 63 | private _closingActionsSubscription;
|
---|
| 64 | /** Subscription to viewport size changes. */
|
---|
| 65 | private _viewportSubscription;
|
---|
| 66 | /**
|
---|
| 67 | * Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
|
---|
| 68 | * closed autocomplete from being reopened if the user switches to another browser tab and then
|
---|
| 69 | * comes back.
|
---|
| 70 | */
|
---|
| 71 | private _canOpenOnNextFocus;
|
---|
| 72 | /** Stream of keyboard events that can close the panel. */
|
---|
| 73 | private readonly _closeKeyEventStream;
|
---|
| 74 | /**
|
---|
| 75 | * Event handler for when the window is blurred. Needs to be an
|
---|
| 76 | * arrow function in order to preserve the context.
|
---|
| 77 | */
|
---|
| 78 | private _windowBlurHandler;
|
---|
| 79 | /** `View -> model callback called when value changes` */
|
---|
| 80 | _onChange: (value: any) => void;
|
---|
| 81 | /** `View -> model callback called when autocomplete has been touched` */
|
---|
| 82 | _onTouched: () => void;
|
---|
| 83 | /** The autocomplete panel to be attached to this trigger. */
|
---|
| 84 | autocomplete: _MatAutocompleteBase;
|
---|
| 85 | /**
|
---|
| 86 | * Position of the autocomplete panel relative to the trigger element. A position of `auto`
|
---|
| 87 | * will render the panel underneath the trigger if there is enough space for it to fit in
|
---|
| 88 | * the viewport, otherwise the panel will be shown above it. If the position is set to
|
---|
| 89 | * `above` or `below`, the panel will always be shown above or below the trigger. no matter
|
---|
| 90 | * whether it fits completely in the viewport.
|
---|
| 91 | */
|
---|
| 92 | position: 'auto' | 'above' | 'below';
|
---|
| 93 | /**
|
---|
| 94 | * Reference relative to which to position the autocomplete panel.
|
---|
| 95 | * Defaults to the autocomplete trigger element.
|
---|
| 96 | */
|
---|
| 97 | connectedTo: _MatAutocompleteOriginBase;
|
---|
| 98 | /**
|
---|
| 99 | * `autocomplete` attribute to be set on the input element.
|
---|
| 100 | * @docs-private
|
---|
| 101 | */
|
---|
| 102 | autocompleteAttribute: string;
|
---|
| 103 | /**
|
---|
| 104 | * Whether the autocomplete is disabled. When disabled, the element will
|
---|
| 105 | * act as a regular input and the user won't be able to open the panel.
|
---|
| 106 | */
|
---|
| 107 | get autocompleteDisabled(): boolean;
|
---|
| 108 | set autocompleteDisabled(value: boolean);
|
---|
| 109 | 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);
|
---|
| 110 | /** Class to apply to the panel when it's above the input. */
|
---|
| 111 | protected abstract _aboveClass: string;
|
---|
| 112 | ngAfterViewInit(): void;
|
---|
| 113 | ngOnChanges(changes: SimpleChanges): void;
|
---|
| 114 | ngOnDestroy(): void;
|
---|
| 115 | /** Whether or not the autocomplete panel is open. */
|
---|
| 116 | get panelOpen(): boolean;
|
---|
| 117 | private _overlayAttached;
|
---|
| 118 | /** Opens the autocomplete suggestion panel. */
|
---|
| 119 | openPanel(): void;
|
---|
| 120 | /** Closes the autocomplete suggestion panel. */
|
---|
| 121 | closePanel(): void;
|
---|
| 122 | /**
|
---|
| 123 | * Updates the position of the autocomplete suggestion panel to ensure that it fits all options
|
---|
| 124 | * within the viewport.
|
---|
| 125 | */
|
---|
| 126 | updatePosition(): void;
|
---|
| 127 | /**
|
---|
| 128 | * A stream of actions that should close the autocomplete panel, including
|
---|
| 129 | * when an option is selected, on blur, and when TAB is pressed.
|
---|
| 130 | */
|
---|
| 131 | get panelClosingActions(): Observable<MatOptionSelectionChange | null>;
|
---|
| 132 | /** Stream of autocomplete option selections. */
|
---|
| 133 | readonly optionSelections: Observable<MatOptionSelectionChange>;
|
---|
| 134 | /** The currently active option, coerced to MatOption type. */
|
---|
| 135 | get activeOption(): MatOption | null;
|
---|
| 136 | /** Stream of clicks outside of the autocomplete panel. */
|
---|
| 137 | private _getOutsideClickStream;
|
---|
| 138 | writeValue(value: any): void;
|
---|
| 139 | registerOnChange(fn: (value: any) => {}): void;
|
---|
| 140 | registerOnTouched(fn: () => {}): void;
|
---|
| 141 | setDisabledState(isDisabled: boolean): void;
|
---|
| 142 | _handleKeydown(event: KeyboardEvent): void;
|
---|
| 143 | _handleInput(event: KeyboardEvent): void;
|
---|
| 144 | _handleFocus(): void;
|
---|
| 145 | /**
|
---|
| 146 | * In "auto" mode, the label will animate down as soon as focus is lost.
|
---|
| 147 | * This causes the value to jump when selecting an option with the mouse.
|
---|
| 148 | * This method manually floats the label until the panel can be closed.
|
---|
| 149 | * @param shouldAnimate Whether the label should be animated when it is floated.
|
---|
| 150 | */
|
---|
| 151 | private _floatLabel;
|
---|
| 152 | /** If the label has been manually elevated, return it to its normal state. */
|
---|
| 153 | private _resetLabel;
|
---|
| 154 | /**
|
---|
| 155 | * This method listens to a stream of panel closing actions and resets the
|
---|
| 156 | * stream every time the option list changes.
|
---|
| 157 | */
|
---|
| 158 | private _subscribeToClosingActions;
|
---|
| 159 | /** Destroys the autocomplete suggestion panel. */
|
---|
| 160 | private _destroyPanel;
|
---|
| 161 | private _setTriggerValue;
|
---|
| 162 | /**
|
---|
| 163 | * This method closes the panel, and if a value is specified, also sets the associated
|
---|
| 164 | * control to that value. It will also mark the control as dirty if this interaction
|
---|
| 165 | * stemmed from the user.
|
---|
| 166 | */
|
---|
| 167 | private _setValueAndClose;
|
---|
| 168 | /**
|
---|
| 169 | * Clear any previous selected option and emit a selection change event for this option
|
---|
| 170 | */
|
---|
| 171 | private _clearPreviousSelectedOption;
|
---|
| 172 | private _attachOverlay;
|
---|
| 173 | private _getOverlayConfig;
|
---|
| 174 | private _getOverlayPosition;
|
---|
| 175 | /** Sets the positions on a position strategy based on the directive's input state. */
|
---|
| 176 | private _setStrategyPositions;
|
---|
| 177 | private _getConnectedElement;
|
---|
| 178 | private _getPanelWidth;
|
---|
| 179 | /** Returns the width of the input element, so the panel width can match it. */
|
---|
| 180 | private _getHostWidth;
|
---|
| 181 | /**
|
---|
| 182 | * Resets the active item to -1 so arrow events will activate the
|
---|
| 183 | * correct options, or to 0 if the consumer opted into it.
|
---|
| 184 | */
|
---|
| 185 | private _resetActiveItem;
|
---|
| 186 | /** Determines whether the panel can be opened. */
|
---|
| 187 | private _canOpen;
|
---|
| 188 | /** Use defaultView of injected document if available or fallback to global window reference */
|
---|
| 189 | private _getWindow;
|
---|
| 190 | /** Scrolls to a particular option in the list. */
|
---|
| 191 | private _scrollToOption;
|
---|
| 192 | static ngAcceptInputType_autocompleteDisabled: BooleanInput;
|
---|
| 193 | }
|
---|
| 194 | export declare class MatAutocompleteTrigger extends _MatAutocompleteTriggerBase {
|
---|
| 195 | protected _aboveClass: string;
|
---|
| 196 | }
|
---|