import { ElementRef, ChangeDetectorRef, QueryList, OnInit, OnChanges, DoCheck, OnDestroy, AfterContentInit, NgZone, EventEmitter, SimpleChanges } from '@angular/core'; import { SelectionModel } from '@angular/cdk/collections'; import { ActiveDescendantKeyManager } from '@angular/cdk/a11y'; import { Overlay, RepositionScrollStrategy, CdkConnectedOverlay } from '@angular/cdk/overlay'; import { ControlValueAccessor, FormGroupDirective, NgControl, NgForm } from '@angular/forms'; import { Observable } from 'rxjs/Observable'; import { CanDisable, HasTabIndex, ErrorStateMatcher, CanUpdateErrorState } from '@dynatrace/ngx-groundhog/core'; import { GhFormFieldControl } from '@dynatrace/ngx-groundhog/form-field'; import { GhOption, GhOptionSelectionChange } from './option'; /** The height of the select items. */ export declare const SELECT_ITEM_HEIGHT = 32; /** * The maximum count of items that should be visible in the panel at once. * To indicate that the panel can be scrolled, show half of the next item */ export declare const SELECT_MAX_ITEMS_VISIBLE = 7.5; /** Change event object that is emitted when the select value has changed. */ export interface GhSelectChange { /** Reference to the select that emitted the change event. */ source: GhSelect; /** Current value of the select that emitted the event. */ value: any; } export declare class GhSelectBase { _elementRef: ElementRef; _defaultErrorStateMatcher: ErrorStateMatcher; _parentForm: NgForm; _parentFormGroup: FormGroupDirective; ngControl: NgControl; constructor(_elementRef: ElementRef, _defaultErrorStateMatcher: ErrorStateMatcher, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, ngControl: NgControl); } export declare const _GhSelectMixinBase: (new (...args: any[]) => HasTabIndex) & (new (...args: any[]) => CanDisable) & (new (...args: any[]) => CanUpdateErrorState) & typeof GhSelectBase; export declare class GhSelect extends _GhSelectMixinBase implements OnInit, OnChanges, OnDestroy, DoCheck, AfterContentInit, CanDisable, HasTabIndex, ControlValueAccessor, CanUpdateErrorState, GhFormFieldControl { private _changeDetectorRef; private _ngZone; ngControl: NgControl; private _overlay; /** The placeholder displayed in the trigger of the select. */ private _placeholder; /** Whether or not the overlay panel is open. */ private _panelOpen; /** Whether filling out the select is required in the form. */ private _required; /** Unique id for this input. */ private _uid; /** _uid or provided id via input */ private _id; /** Current value of the select */ private _value; /** Emits whenever the component is destroyed. */ private _destroy; /** Comparison function to specify which option is displayed. Defaults to object equality. */ private _compareWith; /** The scroll position of the overlay panel, calculated to center the selected option. */ private _scrollTop; /** Last emitted position of the overlay */ private _connectionPair; /** Deals with the selection logic. */ _selectionModel: SelectionModel; /** The IDs of child options to be passed to the aria-owns attribute. */ _optionIds: string; /** The aria-describedby attribute on the select for improved a11y. */ _ariaDescribedby: string; /** Whether the select is focused. */ focused: boolean; /** Manages keyboard events for options in the panel. */ _keyManager: ActiveDescendantKeyManager; /** `View -> model callback called when value changes` */ _onChange: (value: any) => void; /** `View -> model callback called when select has been touched` */ _onTouched: () => void; /** The last measured value for the trigger's client bounding rect. */ _triggerRect: ClientRect; /** Whether the panel's animation is done. */ _panelDoneAnimating: boolean; /** The max height of the select's overlay panel */ _maxPanelHeight: number; /** Strategy that will be used to handle scrolling while the select panel is open. */ _scrollStrategy: RepositionScrollStrategy; _positions: { originX: string; originY: string; overlayX: string; overlayY: string; }[]; /** Classes to be passed to the select panel. Supports the same syntax as `ngClass`. */ panelClass: string | Set | string[] | { [key: string]: any; }; /** Placeholder to be shown if no value has been selected. */ placeholder: string; /** Value of the select. */ value: any; /** Unique id of the element. */ id: string; /** Whether the component is required. */ required: boolean; /** * A function to compare the option values with the selected values. The first argument * is a value from an option. The second is a value from the selection. A boolean * should be returned. */ compareWith: (o1: any, o2: any) => boolean; /** Aria label of the select. If not specified, the placeholder will be used as label. */ ariaLabel: string; /** Input that can be used to specify the `aria-labelledby` attribute. */ ariaLabelledby: string; /** An object used to control when error messages are shown. */ errorStateMatcher: ErrorStateMatcher; /** Event emitted when the select has been opened. */ readonly openedChange: EventEmitter; /** Event emitted when the selected value has been changed by the user. */ readonly selectionChange: EventEmitter; /** * Event that emits whenever the raw value of the select changes. This is here primarily * to facilitate the two-way binding for the `value` input. */ readonly valueChange: EventEmitter; /** The currently selected option. */ readonly selected: GhOption; /** Whether the select has a value. */ readonly empty: boolean; /** The value displayed in the trigger. */ readonly triggerValue: string; /** Whether or not the overlay panel is open. */ readonly panelOpen: boolean; /** Returns the aria-label of the select component. */ readonly _ariaLabel: string | null; /** Determines the `aria-activedescendant` to be set on the host. */ _getAriaActiveDescendant(): string | null; /** Panel containing the select options. */ panel: ElementRef; /** Overlay pane containing the options. */ overlayDir: CdkConnectedOverlay; /** Trigger that opens the select. */ trigger: ElementRef; /** All of the defined select options. */ options: QueryList; /** Combined stream of all of the child options' change events. */ optionSelectionChanges: Observable; constructor(_changeDetectorRef: ChangeDetectorRef, _ngZone: NgZone, _elementRef: ElementRef, _defaultErrorStateMatcher: ErrorStateMatcher, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, ngControl: NgControl, tabIndex: string, _overlay: Overlay); /** * Hook that triggers after the component has been initialized * and the first change detection has run. */ ngOnInit(): void; /** Hook that triggers when ng-content and all sub components (the options) are initialized. */ ngAfterContentInit(): void; ngDoCheck(): void; ngOnChanges(changes: SimpleChanges): void; /** Hook that trigger right before the component will be destroyed. */ ngOnDestroy(): void; /** Opens the panel */ open(): void; /** Closes the panel */ close(): void; /** Toggles the panel */ toggle(): void; /** Focuses the select element. */ focus(): void; /** * Sets the select's value. Part of the ControlValueAccessor interface * required to integrate with Angular's core forms API. */ writeValue(value: any): void; /** * Saves a callback function to be invoked when the select's value * changes from user input. Part of the ControlValueAccessor interface * required to integrate with Angular's core forms API. * @param fn Callback to be triggered when the value changes. */ registerOnChange(fn: (value: any) => void): void; /** * Saves a callback function to be invoked when the select is blurred * by the user. Part of the ControlValueAccessor interface required * to integrate with Angular's core forms API. * @param fn Callback to be triggered when the component has been touched. */ registerOnTouched(fn: () => {}): void; /** * Disables the select. Part of the ControlValueAccessor interface required * to integrate with Angular's core forms API. * @param isDisabled Sets whether the component is disabled. */ setDisabledState(isDisabled: boolean): void; /** Implemented as part of GhFormFieldControl. */ setDescribedByIds(ids: string[]): void; /** Implemented as part of GhFormFieldControl. */ onContainerClick(): void; /** Drops current option subscriptions and resets from scratch. */ _resetOptions(): void; /** Handles all keydown events on the select. */ _handleKeydown(event: KeyboardEvent): void; /** Handles keyboard events while the select is closed. */ private _handleClosedKeydown(event); /** Handles keyboard events when the selected is open. */ private _handleOpenKeydown(event); /** Invoked when the control gains focus. */ _onFocus(): void; /** Invoked when the control looses focus. */ _onBlur(): void; /** Callback that is invoked when the overlay panel has been attached. */ _onAttached(): void; /** * When the panel element is finished transforming in (though not fading in), it * emits an event and focuses an option if the panel is open. */ _onPanelDone(): void; /** * When the panel content is done fading in, the _panelDoneAnimating property is * set so the proper class can be added to the panel. */ _onFadeInDone(): void; private _initializeSelection(); /** * Highlights the selected item. If no option is selected, it will highlight * the first item instead. */ private _highlightCorrectOption(); /** Gets the index of the provided option in the option list. */ private _getOptionIndex(option); /** * Calculates the scroll position of the select's overlay panel. * Attempts to center the selected option in the panel. If the option is * too high or too low in the panel to be scrolled to the center, it clamps the * scroll position to the min or max scroll positions respectively. */ private _calculateOverlayScroll(); /** Scrolls the active option into view. */ private _scrollActiveOptionIntoView(); /** Invoked when an option is clicked. */ private _onSelect(option); /** Clears the select trigger and deselects every option in the list. */ private _clearSelection(skip?); /** * Sets the selected option based on a value. If no option can be * found with the designated value, the select trigger is cleared. */ private _setSelectionByValue(value, isUserInput?); /** * Finds and selects and option based on its value. * @returns Option that has the corresponding value. */ private _selectValue(value, isUserInput?); /** Sets up a key manager to listen to keyboard events on the overlay panel. */ private _initKeyManager(); /** Emits change event to set the model value. */ private _propagateChanges(fallbackValue?); /** Records option IDs to pass to the aria-owns property. */ private _setOptionIds(); private _updatePanelMaxHeight(); }