@angular/material
Version:
Angular Material
439 lines (416 loc) • 20.7 kB
TypeScript
import { _AbstractConstructor } from '@angular/material/core';
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
import { AfterContentInit } from '@angular/core';
import { AfterViewInit } from '@angular/core';
import { BooleanInput } from '@angular/cdk/coercion';
import { CanDisableRipple } from '@angular/material/core';
import { ChangeDetectorRef } from '@angular/core';
import { _Constructor } from '@angular/material/core';
import { ControlValueAccessor } from '@angular/forms';
import { Directionality } from '@angular/cdk/bidi';
import { ElementRef } from '@angular/core';
import { EventEmitter } from '@angular/core';
import * as i0 from '@angular/core';
import * as i4 from '@angular/cdk/overlay';
import * as i5 from '@angular/material/core';
import * as i6 from '@angular/common';
import * as i7 from '@angular/cdk/scrolling';
import { InjectionToken } from '@angular/core';
import { MatFormField } from '@angular/material/form-field';
import { MatOptgroup } from '@angular/material/core';
import { _MatOptgroupBase } from '@angular/material/core';
import { MatOption } from '@angular/material/core';
import { _MatOptionBase } from '@angular/material/core';
import { MatOptionSelectionChange } from '@angular/material/core';
import { NgZone } from '@angular/core';
import { Observable } from 'rxjs';
import { OnChanges } from '@angular/core';
import { OnDestroy } from '@angular/core';
import { Overlay } from '@angular/cdk/overlay';
import { Platform } from '@angular/cdk/platform';
import { QueryList } from '@angular/core';
import { ScrollStrategy } from '@angular/cdk/overlay';
import { SimpleChanges } from '@angular/core';
import { TemplateRef } from '@angular/core';
import { ViewContainerRef } from '@angular/core';
import { ViewportRuler } from '@angular/cdk/scrolling';
/**
* Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
* @docs-private
*/
export declare function getMatAutocompleteMissingPanelError(): Error;
declare namespace i1 {
export {
MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY,
MatAutocompleteSelectedEvent,
MatAutocompleteActivatedEvent,
MatAutocompleteDefaultOptions,
MAT_AUTOCOMPLETE_DEFAULT_OPTIONS,
_MatAutocompleteBase,
MatAutocomplete
}
}
declare namespace i2 {
export {
getMatAutocompleteMissingPanelError,
MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY,
MAT_AUTOCOMPLETE_VALUE_ACCESSOR,
MAT_AUTOCOMPLETE_SCROLL_STRATEGY,
MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER,
_MatAutocompleteTriggerBase,
MatAutocompleteTrigger
}
}
declare namespace i3 {
export {
_MatAutocompleteOriginBase,
MatAutocompleteOrigin
}
}
/** Injection token to be used to override the default options for `mat-autocomplete`. */
export declare const MAT_AUTOCOMPLETE_DEFAULT_OPTIONS: InjectionToken<MatAutocompleteDefaultOptions>;
/** @docs-private */
export declare function MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY(): MatAutocompleteDefaultOptions;
/** Injection token that determines the scroll handling while the autocomplete panel is open. */
export declare const MAT_AUTOCOMPLETE_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
/** @docs-private */
export declare function MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
/** @docs-private */
export declare const MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER: {
provide: InjectionToken<() => ScrollStrategy>;
deps: (typeof Overlay)[];
useFactory: typeof MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY;
};
/**
* Provider that allows the autocomplete to register as a ControlValueAccessor.
* @docs-private
*/
export declare const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any;
export declare class MatAutocomplete extends _MatAutocompleteBase {
/** Reference to all option groups within the autocomplete. */
optionGroups: QueryList<MatOptgroup>;
/** Reference to all options within the autocomplete. */
options: QueryList<MatOption>;
protected _visibleClass: string;
protected _hiddenClass: string;
static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocomplete, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MatAutocomplete, "mat-autocomplete", ["matAutocomplete"], { "disableRipple": "disableRipple"; }, {}, ["optionGroups", "options"], ["*"], false, never>;
}
/** Event object that is emitted when an autocomplete option is activated. */
export declare interface MatAutocompleteActivatedEvent {
/** Reference to the autocomplete panel that emitted the event. */
source: _MatAutocompleteBase;
/** Option that was selected. */
option: _MatOptionBase | null;
}
/** Base class with all of the `MatAutocomplete` functionality. */
export declare abstract class _MatAutocompleteBase extends _MatAutocompleteMixinBase implements AfterContentInit, CanDisableRipple, OnDestroy {
private _changeDetectorRef;
private _elementRef;
private _activeOptionChanges;
/** Class to apply to the panel when it's visible. */
protected abstract _visibleClass: string;
/** Class to apply to the panel when it's hidden. */
protected abstract _hiddenClass: string;
/** Manages active item in option list based on key events. */
_keyManager: ActiveDescendantKeyManager<_MatOptionBase>;
/** Whether the autocomplete panel should be visible, depending on option length. */
showPanel: boolean;
/** Whether the autocomplete panel is open. */
get isOpen(): boolean;
_isOpen: boolean;
/** @docs-private */
template: TemplateRef<any>;
/** Element for the panel containing the autocomplete options. */
panel: ElementRef;
/** Reference to all options within the autocomplete. */
abstract options: QueryList<_MatOptionBase>;
/** Reference to all option groups within the autocomplete. */
abstract optionGroups: QueryList<_MatOptgroupBase>;
/** Aria label of the autocomplete. */
ariaLabel: string;
/** Input that can be used to specify the `aria-labelledby` attribute. */
ariaLabelledby: string;
/** Function that maps an option's control value to its display value in the trigger. */
displayWith: ((value: any) => string) | null;
/**
* Whether the first option should be highlighted when the autocomplete panel is opened.
* Can be configured globally through the `MAT_AUTOCOMPLETE_DEFAULT_OPTIONS` token.
*/
get autoActiveFirstOption(): boolean;
set autoActiveFirstOption(value: BooleanInput);
private _autoActiveFirstOption;
/** Whether the active option should be selected as the user is navigating. */
get autoSelectActiveOption(): boolean;
set autoSelectActiveOption(value: BooleanInput);
private _autoSelectActiveOption;
/**
* Specify the width of the autocomplete panel. Can be any CSS sizing value, otherwise it will
* match the width of its host.
*/
panelWidth: string | number;
/** Event that is emitted whenever an option from the list is selected. */
readonly optionSelected: EventEmitter<MatAutocompleteSelectedEvent>;
/** Event that is emitted when the autocomplete panel is opened. */
readonly opened: EventEmitter<void>;
/** Event that is emitted when the autocomplete panel is closed. */
readonly closed: EventEmitter<void>;
/** Emits whenever an option is activated. */
readonly optionActivated: EventEmitter<MatAutocompleteActivatedEvent>;
/**
* Takes classes set on the host mat-autocomplete element and applies them to the panel
* inside the overlay container to allow for easy styling.
*/
set classList(value: string | string[]);
_classList: {
[key: string]: boolean;
};
/** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
id: string;
/**
* Tells any descendant `mat-optgroup` to use the inert a11y pattern.
* @docs-private
*/
readonly inertGroups: boolean;
constructor(_changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef<HTMLElement>, defaults: MatAutocompleteDefaultOptions, platform?: Platform);
ngAfterContentInit(): void;
ngOnDestroy(): void;
/**
* Sets the panel scrollTop. This allows us to manually scroll to display options
* above or below the fold, as they are not actually being focused when active.
*/
_setScrollTop(scrollTop: number): void;
/** Returns the panel's scrollTop. */
_getScrollTop(): number;
/** Panel should hide itself when the option list is empty. */
_setVisibility(): void;
/** Emits the `select` event. */
_emitSelectEvent(option: _MatOptionBase): void;
/** Gets the aria-labelledby for the autocomplete panel. */
_getPanelAriaLabelledby(labelId: string | null): string | null;
/** Sets the autocomplete visibility classes on a classlist based on the panel is visible. */
private _setVisibilityClasses;
static ɵfac: i0.ɵɵFactoryDeclaration<_MatAutocompleteBase, never>;
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, never>;
}
/** Default `mat-autocomplete` options that can be overridden. */
export declare interface MatAutocompleteDefaultOptions {
/** Whether the first option should be highlighted when an autocomplete panel is opened. */
autoActiveFirstOption?: boolean;
/** Whether the active option should be selected as the user is navigating. */
autoSelectActiveOption?: boolean;
/** Class or list of classes to be applied to the autocomplete's overlay panel. */
overlayPanelClass?: string | string[];
}
/** @docs-private */
declare const _MatAutocompleteMixinBase: _Constructor<CanDisableRipple> & _AbstractConstructor<CanDisableRipple> & {
new (): {};
};
export declare class MatAutocompleteModule {
static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteModule, never>;
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 i7.CdkScrollableModule, typeof i1.MatAutocomplete, typeof i5.MatOptionModule, typeof i5.MatCommonModule, typeof i2.MatAutocompleteTrigger, typeof i3.MatAutocompleteOrigin]>;
static ɵinj: i0.ɵɵInjectorDeclaration<MatAutocompleteModule>;
}
/**
* Directive applied to an element to make it usable
* as a connection point for an autocomplete panel.
*/
export declare class MatAutocompleteOrigin extends _MatAutocompleteOriginBase {
static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteOrigin, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteOrigin, "[matAutocompleteOrigin]", ["matAutocompleteOrigin"], {}, {}, never, never, false, never>;
}
/** Base class containing all of the functionality for `MatAutocompleteOrigin`. */
export declare abstract class _MatAutocompleteOriginBase {
/** Reference to the element on which the directive is applied. */
elementRef: ElementRef<HTMLElement>;
constructor(
/** Reference to the element on which the directive is applied. */
elementRef: ElementRef<HTMLElement>);
static ɵfac: i0.ɵɵFactoryDeclaration<_MatAutocompleteOriginBase, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatAutocompleteOriginBase, never, never, {}, {}, never, never, false, never>;
}
/** Event object that is emitted when an autocomplete option is selected. */
export declare class MatAutocompleteSelectedEvent {
/** Reference to the autocomplete panel that emitted the event. */
source: _MatAutocompleteBase;
/** Option that was selected. */
option: _MatOptionBase;
constructor(
/** Reference to the autocomplete panel that emitted the event. */
source: _MatAutocompleteBase,
/** Option that was selected. */
option: _MatOptionBase);
}
export declare class MatAutocompleteTrigger extends _MatAutocompleteTriggerBase {
protected _aboveClass: string;
static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteTrigger, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteTrigger, "input[matAutocomplete], textarea[matAutocomplete]", ["matAutocompleteTrigger"], {}, {}, never, never, false, never>;
}
/** Base class with all of the `MatAutocompleteTrigger` functionality. */
export declare abstract class _MatAutocompleteTriggerBase implements ControlValueAccessor, AfterViewInit, OnChanges, OnDestroy {
private _element;
private _overlay;
private _viewContainerRef;
private _zone;
private _changeDetectorRef;
private _dir;
private _formField;
private _document;
private _viewportRuler;
private _defaults?;
private _overlayRef;
private _portal;
private _componentDestroyed;
private _autocompleteDisabled;
private _scrollStrategy;
/** Old value of the native input. Used to work around issues with the `input` event on IE. */
private _previousValue;
/** Strategy that is used to position the panel. */
private _positionStrategy;
/** Whether or not the label state is being overridden. */
private _manuallyFloatingLabel;
/** The subscription for closing actions (some are bound to document). */
private _closingActionsSubscription;
/** Subscription to viewport size changes. */
private _viewportSubscription;
/**
* Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
* closed autocomplete from being reopened if the user switches to another browser tab and then
* comes back.
*/
private _canOpenOnNextFocus;
/** Value inside the input before we auto-selected an option. */
private _valueBeforeAutoSelection;
/**
* Current option that we have auto-selected as the user is navigating,
* but which hasn't been propagated to the model value yet.
*/
private _pendingAutoselectedOption;
/** Stream of keyboard events that can close the panel. */
private readonly _closeKeyEventStream;
/**
* Event handler for when the window is blurred. Needs to be an
* arrow function in order to preserve the context.
*/
private _windowBlurHandler;
/** `View -> model callback called when value changes` */
_onChange: (value: any) => void;
/** `View -> model callback called when autocomplete has been touched` */
_onTouched: () => void;
/** The autocomplete panel to be attached to this trigger. */
autocomplete: _MatAutocompleteBase;
/**
* Position of the autocomplete panel relative to the trigger element. A position of `auto`
* will render the panel underneath the trigger if there is enough space for it to fit in
* the viewport, otherwise the panel will be shown above it. If the position is set to
* `above` or `below`, the panel will always be shown above or below the trigger. no matter
* whether it fits completely in the viewport.
*/
position: 'auto' | 'above' | 'below';
/**
* Reference relative to which to position the autocomplete panel.
* Defaults to the autocomplete trigger element.
*/
connectedTo: _MatAutocompleteOriginBase;
/**
* `autocomplete` attribute to be set on the input element.
* @docs-private
*/
autocompleteAttribute: string;
/**
* Whether the autocomplete is disabled. When disabled, the element will
* act as a regular input and the user won't be able to open the panel.
*/
get autocompleteDisabled(): boolean;
set autocompleteDisabled(value: BooleanInput);
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);
/** Class to apply to the panel when it's above the input. */
protected abstract _aboveClass: string;
ngAfterViewInit(): void;
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;
/** Whether or not the autocomplete panel is open. */
get panelOpen(): boolean;
private _overlayAttached;
/** Opens the autocomplete suggestion panel. */
openPanel(): void;
/** Closes the autocomplete suggestion panel. */
closePanel(): void;
/**
* Updates the position of the autocomplete suggestion panel to ensure that it fits all options
* within the viewport.
*/
updatePosition(): void;
/**
* A stream of actions that should close the autocomplete panel, including
* when an option is selected, on blur, and when TAB is pressed.
*/
get panelClosingActions(): Observable<MatOptionSelectionChange | null>;
/** Stream of changes to the selection state of the autocomplete options. */
readonly optionSelections: Observable<MatOptionSelectionChange>;
/** The currently active option, coerced to MatOption type. */
get activeOption(): _MatOptionBase | null;
/** Stream of clicks outside of the autocomplete panel. */
private _getOutsideClickStream;
writeValue(value: any): void;
registerOnChange(fn: (value: any) => {}): void;
registerOnTouched(fn: () => {}): void;
setDisabledState(isDisabled: boolean): void;
_handleKeydown(event: KeyboardEvent): void;
_handleInput(event: KeyboardEvent): void;
_handleFocus(): void;
_handleClick(): void;
/**
* In "auto" mode, the label will animate down as soon as focus is lost.
* This causes the value to jump when selecting an option with the mouse.
* This method manually floats the label until the panel can be closed.
* @param shouldAnimate Whether the label should be animated when it is floated.
*/
private _floatLabel;
/** If the label has been manually elevated, return it to its normal state. */
private _resetLabel;
/**
* This method listens to a stream of panel closing actions and resets the
* stream every time the option list changes.
*/
private _subscribeToClosingActions;
/** Destroys the autocomplete suggestion panel. */
private _destroyPanel;
private _assignOptionValue;
private _updateNativeInputValue;
/**
* This method closes the panel, and if a value is specified, also sets the associated
* control to that value. It will also mark the control as dirty if this interaction
* stemmed from the user.
*/
private _setValueAndClose;
/**
* Clear any previous selected option and emit a selection change event for this option
*/
private _clearPreviousSelectedOption;
private _attachOverlay;
private _getOverlayConfig;
private _getOverlayPosition;
/** Sets the positions on a position strategy based on the directive's input state. */
private _setStrategyPositions;
private _getConnectedElement;
private _getPanelWidth;
/** Returns the width of the input element, so the panel width can match it. */
private _getHostWidth;
/**
* Resets the active item to -1 so arrow events will activate the
* correct options, or to 0 if the consumer opted into it.
*/
private _resetActiveItem;
/** Determines whether the panel can be opened. */
private _canOpen;
/** Use defaultView of injected document if available or fallback to global window reference */
private _getWindow;
/** Scrolls to a particular option in the list. */
private _scrollToOption;
/** Handles keyboard events coming from the overlay panel. */
private _handleOverlayEvents;
static ɵfac: i0.ɵɵFactoryDeclaration<_MatAutocompleteTriggerBase, [null, null, null, null, null, null, { optional: true; }, { optional: true; host: true; }, { optional: true; }, null, { optional: true; }]>;
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatAutocompleteTriggerBase, never, never, { "autocomplete": "matAutocomplete"; "position": "matAutocompletePosition"; "connectedTo": "matAutocompleteConnectedTo"; "autocompleteAttribute": "autocomplete"; "autocompleteDisabled": "matAutocompleteDisabled"; }, {}, never, never, false, never>;
}
export { }