UNPKG

@angular/material

Version:
1,319 lines (1,309 loc) 78.2 kB
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/cdk/a11y'), require('@angular/cdk/bidi'), require('@angular/cdk/coercion'), require('@angular/cdk/collections'), require('@angular/cdk/keycodes'), require('@angular/cdk/overlay'), require('rxjs/operators/filter'), require('rxjs/operators/take'), require('rxjs/operators/map'), require('rxjs/operators/switchMap'), require('rxjs/operators/startWith'), require('rxjs/operators/takeUntil'), require('@angular/forms'), require('@angular/material/core'), require('@angular/material/form-field'), require('rxjs/Observable'), require('rxjs/observable/merge'), require('rxjs/Subject'), require('rxjs/observable/defer'), require('@angular/animations')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common', '@angular/cdk/a11y', '@angular/cdk/bidi', '@angular/cdk/coercion', '@angular/cdk/collections', '@angular/cdk/keycodes', '@angular/cdk/overlay', 'rxjs/operators/filter', 'rxjs/operators/take', 'rxjs/operators/map', 'rxjs/operators/switchMap', 'rxjs/operators/startWith', 'rxjs/operators/takeUntil', '@angular/forms', '@angular/material/core', '@angular/material/form-field', 'rxjs/Observable', 'rxjs/observable/merge', 'rxjs/Subject', 'rxjs/observable/defer', '@angular/animations'], factory) : (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.select = global.ng.material.select || {}),global.ng.core,global.ng.common,global.ng.cdk.a11y,global.ng.cdk.bidi,global.ng.cdk.coercion,global.ng.cdk.collections,global.ng.cdk.keycodes,global.ng.cdk.overlay,global.Rx.operators,global.Rx.operators,global.Rx.operators,global.Rx.operators,global.Rx.operators,global.Rx.operators,global.ng.forms,global.ng.material.core,global.ng.material.formField,global.Rx,global.Rx.Observable,global.Rx,global.Rx.Observable,global.ng.animations)); }(this, (function (exports,_angular_core,_angular_common,_angular_cdk_a11y,_angular_cdk_bidi,_angular_cdk_coercion,_angular_cdk_collections,_angular_cdk_keycodes,_angular_cdk_overlay,rxjs_operators_filter,rxjs_operators_take,rxjs_operators_map,rxjs_operators_switchMap,rxjs_operators_startWith,rxjs_operators_takeUntil,_angular_forms,_angular_material_core,_angular_material_formField,rxjs_Observable,rxjs_observable_merge,rxjs_Subject,rxjs_observable_defer,_angular_animations) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * The following are all the animations for the mat-select component, with each * const containing the metadata for one animation. * * The values below match the implementation of the AngularJS Material mat-select animation. */ var matSelectAnimations = { /** * This animation transforms the select's overlay panel on and off the page. * * When the panel is attached to the DOM, it expands its width by the amount of padding, scales it * up to 100% on the Y axis, fades in its border, and translates slightly up and to the * side to ensure the option text correctly overlaps the trigger text. * * When the panel is removed from the DOM, it simply fades out linearly. */ transformPanel: _angular_animations.trigger('transformPanel', [ _angular_animations.state('showing', _angular_animations.style({ opacity: 1, minWidth: 'calc(100% + 32px)', // 32px = 2 * 16px padding transform: 'scaleY(1)' })), _angular_animations.state('showing-multiple', _angular_animations.style({ opacity: 1, minWidth: 'calc(100% + 64px)', // 64px = 48px padding on the left + 16px padding on the right transform: 'scaleY(1)' })), _angular_animations.transition('void => *', [ _angular_animations.style({ opacity: 0, minWidth: '100%', transform: 'scaleY(0)' }), _angular_animations.animate('150ms cubic-bezier(0.25, 0.8, 0.25, 1)') ]), _angular_animations.transition('* => void', [ _angular_animations.animate('250ms 100ms linear', _angular_animations.style({ opacity: 0 })) ]) ]), /** * This animation fades in the background color and text content of the * select's options. It is time delayed to occur 100ms after the overlay * panel has transformed in. */ fadeInContent: _angular_animations.trigger('fadeInContent', [ _angular_animations.state('showing', _angular_animations.style({ opacity: 1 })), _angular_animations.transition('void => showing', [ _angular_animations.style({ opacity: 0 }), _angular_animations.animate('150ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)') ]) ]) }; /** * @deprecated * \@deletion-target 7.0.0 */ var transformPanel = matSelectAnimations.transformPanel; /** * @deprecated * \@deletion-target 7.0.0 */ var fadeInContent = matSelectAnimations.fadeInContent; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Returns an exception to be thrown when attempting to change a select's `multiple` option * after initialization. * \@docs-private * @return {?} */ function getMatSelectDynamicMultipleError() { return Error('Cannot change `multiple` mode of select after initialization.'); } /** * Returns an exception to be thrown when attempting to assign a non-array value to a select * in `multiple` mode. Note that `undefined` and `null` are still valid values to allow for * resetting the value. * \@docs-private * @return {?} */ function getMatSelectNonArrayValueError() { return Error('Value must be an array in multiple-selection mode.'); } /** * Returns an exception to be thrown when assigning a non-function value to the comparator * used to determine if a value corresponds to an option. Note that whether the function * actually takes two values and returns a boolean is not checked. * @return {?} */ function getMatSelectNonFunctionValueError() { return Error('`compareWith` must be a function.'); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var nextUniqueId = 0; /** * The max height of the select's overlay panel */ var SELECT_PANEL_MAX_HEIGHT = 256; /** * The panel's padding on the x-axis */ var SELECT_PANEL_PADDING_X = 16; /** * The panel's x axis padding if it is indented (e.g. there is an option group). */ var SELECT_PANEL_INDENT_PADDING_X = SELECT_PANEL_PADDING_X * 2; /** * The height of the select items in `em` units. */ var SELECT_ITEM_HEIGHT_EM = 3; /** * Distance between the panel edge and the option text in * multi-selection mode. * * (SELECT_PANEL_PADDING_X * 1.5) + 20 = 44 * The padding is multiplied by 1.5 because the checkbox's margin is half the padding. * The checkbox width is 20px. */ var SELECT_MULTIPLE_PANEL_PADDING_X = SELECT_PANEL_PADDING_X * 1.5 + 20; /** * The select panel will only "fit" inside the viewport if it is positioned at * this value or more away from the viewport boundary. */ var SELECT_PANEL_VIEWPORT_PADDING = 8; /** * Injection token that determines the scroll handling while a select is open. */ var MAT_SELECT_SCROLL_STRATEGY = new _angular_core.InjectionToken('mat-select-scroll-strategy'); /** * \@docs-private * @param {?} overlay * @return {?} */ function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay) { return function () { return overlay.scrollStrategies.reposition(); }; } /** * \@docs-private */ var MAT_SELECT_SCROLL_STRATEGY_PROVIDER = { provide: MAT_SELECT_SCROLL_STRATEGY, deps: [_angular_cdk_overlay.Overlay], useFactory: MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY, }; /** * Change event object that is emitted when the select value has changed. */ var MatSelectChange = /** @class */ (function () { function MatSelectChange(source, value) { this.source = source; this.value = value; } return MatSelectChange; }()); /** * \@docs-private */ var MatSelectBase = /** @class */ (function () { function MatSelectBase(_elementRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl) { this._elementRef = _elementRef; this._defaultErrorStateMatcher = _defaultErrorStateMatcher; this._parentForm = _parentForm; this._parentFormGroup = _parentFormGroup; this.ngControl = ngControl; } return MatSelectBase; }()); var _MatSelectMixinBase = _angular_material_core.mixinDisableRipple(_angular_material_core.mixinTabIndex(_angular_material_core.mixinDisabled(_angular_material_core.mixinErrorState(MatSelectBase)))); /** * Allows the user to customize the trigger that is displayed when the select has a value. */ var MatSelectTrigger = /** @class */ (function () { function MatSelectTrigger() { } MatSelectTrigger.decorators = [ { type: _angular_core.Directive, args: [{ selector: 'mat-select-trigger' },] }, ]; /** @nocollapse */ MatSelectTrigger.ctorParameters = function () { return []; }; return MatSelectTrigger; }()); var MatSelect = /** @class */ (function (_super) { __extends(MatSelect, _super); function MatSelect(_viewportRuler, _changeDetectorRef, _ngZone, _defaultErrorStateMatcher, elementRef, _dir, _parentForm, _parentFormGroup, _parentFormField, ngControl, tabIndex, _scrollStrategyFactory) { var _this = _super.call(this, elementRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl) || this; _this._viewportRuler = _viewportRuler; _this._changeDetectorRef = _changeDetectorRef; _this._ngZone = _ngZone; _this._dir = _dir; _this._parentFormField = _parentFormField; _this.ngControl = ngControl; _this._scrollStrategyFactory = _scrollStrategyFactory; /** * Whether or not the overlay panel is open. */ _this._panelOpen = false; /** * Whether filling out the select is required in the form. */ _this._required = false; /** * The scroll position of the overlay panel, calculated to center the selected option. */ _this._scrollTop = 0; /** * Whether the component is in multiple selection mode. */ _this._multiple = false; /** * Comparison function to specify which option is displayed. Defaults to object equality. */ _this._compareWith = function (o1, o2) { return o1 === o2; }; /** * Unique id for this input. */ _this._uid = "mat-select-" + nextUniqueId++; /** * Emits whenever the component is destroyed. */ _this._destroy = new rxjs_Subject.Subject(); /** * The cached font-size of the trigger element. */ _this._triggerFontSize = 0; /** * `View -> model callback called when value changes` */ _this._onChange = function () { }; /** * `View -> model callback called when select has been touched` */ _this._onTouched = function () { }; /** * The IDs of child options to be passed to the aria-owns attribute. */ _this._optionIds = ''; /** * The value of the select panel's transform-origin property. */ _this._transformOrigin = 'top'; /** * Whether the panel's animation is done. */ _this._panelDoneAnimating = false; /** * Strategy that will be used to handle scrolling while the select panel is open. */ _this._scrollStrategy = _this._scrollStrategyFactory(); /** * The y-offset of the overlay panel in relation to the trigger's top start corner. * This must be adjusted to align the selected option text over the trigger text. * when the panel opens. Will change based on the y-position of the selected option. */ _this._offsetY = 0; /** * This position config ensures that the top "start" corner of the overlay * is aligned with with the top "start" of the origin by default (overlapping * the trigger completely). If the panel cannot fit below the trigger, it * will fall back to a position above the trigger. */ _this._positions = [ { originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'top', }, { originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'bottom', }, ]; /** * Whether the select is focused. */ _this.focused = false; /** * A name for this control that can be used by `mat-form-field`. */ _this.controlType = 'mat-select'; /** * Aria label of the select. If not specified, the placeholder will be used as label. */ _this.ariaLabel = ''; /** * Combined stream of all of the child options' change events. */ _this.optionSelectionChanges = rxjs_observable_defer.defer(function () { if (_this.options) { return rxjs_observable_merge.merge.apply(void 0, _this.options.map(function (option) { return option.onSelectionChange; })); } return _this._ngZone.onStable .asObservable() .pipe(rxjs_operators_take.take(1), rxjs_operators_switchMap.switchMap(function () { return _this.optionSelectionChanges; })); }); /** * Event emitted when the select panel has been toggled. */ _this.openedChange = new _angular_core.EventEmitter(); /** * Event emitted when the select has been opened. * @deprecated Use `openedChange` instead. * \@deletion-target 6.0.0 */ _this.onOpen = _this._openedStream; /** * Event emitted when the select has been closed. * @deprecated Use `openedChange` instead. * \@deletion-target 6.0.0 */ _this.onClose = _this._closedStream; /** * Event emitted when the selected value has been changed by the user. */ _this.selectionChange = new _angular_core.EventEmitter(); /** * Event emitted when the selected value has been changed by the user. * @deprecated Use `selectionChange` instead. * \@deletion-target 6.0.0 */ _this.change = _this.selectionChange; /** * 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. * \@docs-private */ _this.valueChange = new _angular_core.EventEmitter(); if (_this.ngControl) { // Note: we provide the value accessor through here, instead of // the `providers` to avoid running into a circular import. // Note: we provide the value accessor through here, instead of // the `providers` to avoid running into a circular import. _this.ngControl.valueAccessor = _this; } _this.tabIndex = parseInt(tabIndex) || 0; // Force setter to be called in case id was not specified. // Force setter to be called in case id was not specified. _this.id = _this.id; return _this; } Object.defineProperty(MatSelect.prototype, "placeholder", { get: /** * Placeholder to be shown if no value has been selected. * @return {?} */ function () { return this._placeholder; }, set: /** * @param {?} value * @return {?} */ function (value) { this._placeholder = value; this.stateChanges.next(); }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "required", { get: /** * Whether the component is required. * @return {?} */ function () { return this._required; }, set: /** * @param {?} value * @return {?} */ function (value) { this._required = _angular_cdk_coercion.coerceBooleanProperty(value); this.stateChanges.next(); }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "multiple", { get: /** * Whether the user should be allowed to select multiple options. * @return {?} */ function () { return this._multiple; }, set: /** * @param {?} value * @return {?} */ function (value) { if (this._selectionModel) { throw getMatSelectDynamicMultipleError(); } this._multiple = _angular_cdk_coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "compareWith", { get: /** * 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. * @return {?} */ function () { return this._compareWith; }, set: /** * @param {?} fn * @return {?} */ function (fn) { if (typeof fn !== 'function') { throw getMatSelectNonFunctionValueError(); } this._compareWith = fn; if (this._selectionModel) { // A different comparator means the selection could change. this._initializeSelection(); } }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "value", { get: /** * Value of the select control. * @return {?} */ function () { return this._value; }, set: /** * @param {?} newValue * @return {?} */ function (newValue) { if (newValue !== this._value) { this.writeValue(newValue); this._value = newValue; } }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "id", { get: /** * Unique id of the element. * @return {?} */ function () { return this._id; }, set: /** * @param {?} value * @return {?} */ function (value) { this._id = value || this._uid; this.stateChanges.next(); }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "_openedStream", { get: /** * Event emitted when the select has been opened. * @return {?} */ function () { return this.openedChange.pipe(rxjs_operators_filter.filter(function (o) { return o; }), rxjs_operators_map.map(function () { })); }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "_closedStream", { get: /** * Event emitted when the select has been closed. * @return {?} */ function () { return this.openedChange.pipe(rxjs_operators_filter.filter(function (o) { return !o; }), rxjs_operators_map.map(function () { })); }, enumerable: true, configurable: true }); /** * @return {?} */ MatSelect.prototype.ngOnInit = /** * @return {?} */ function () { this._selectionModel = new _angular_cdk_collections.SelectionModel(this.multiple, undefined, false); this.stateChanges.next(); }; /** * @return {?} */ MatSelect.prototype.ngAfterContentInit = /** * @return {?} */ function () { var _this = this; this._initKeyManager(); this.options.changes.pipe(rxjs_operators_startWith.startWith(null), rxjs_operators_takeUntil.takeUntil(this._destroy)).subscribe(function () { _this._resetOptions(); _this._initializeSelection(); }); }; /** * @return {?} */ MatSelect.prototype.ngDoCheck = /** * @return {?} */ function () { if (this.ngControl) { this.updateErrorState(); } }; /** * @param {?} changes * @return {?} */ MatSelect.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { // Updating the disabled state is handled by `mixinDisabled`, but we need to additionally let // the parent form field know to run change detection when the disabled state changes. if (changes["disabled"]) { this.stateChanges.next(); } }; /** * @return {?} */ MatSelect.prototype.ngOnDestroy = /** * @return {?} */ function () { this._destroy.next(); this._destroy.complete(); this.stateChanges.complete(); }; /** Toggles the overlay panel open or closed. */ /** * Toggles the overlay panel open or closed. * @return {?} */ MatSelect.prototype.toggle = /** * Toggles the overlay panel open or closed. * @return {?} */ function () { this.panelOpen ? this.close() : this.open(); }; /** Opens the overlay panel. */ /** * Opens the overlay panel. * @return {?} */ MatSelect.prototype.open = /** * Opens the overlay panel. * @return {?} */ function () { var _this = this; if (this.disabled || !this.options || !this.options.length) { return; } this._triggerRect = this.trigger.nativeElement.getBoundingClientRect(); // Note: The computed font-size will be a string pixel value (e.g. "16px"). // `parseInt` ignores the trailing 'px' and converts this to a number. this._triggerFontSize = parseInt(getComputedStyle(this.trigger.nativeElement)['font-size']); this._panelOpen = true; this._keyManager.withHorizontalOrientation(null); this._calculateOverlayPosition(); this._highlightCorrectOption(); this._changeDetectorRef.markForCheck(); // Set the font size on the panel element once it exists. this._ngZone.onStable.asObservable().pipe(rxjs_operators_take.take(1)).subscribe(function () { if (_this._triggerFontSize && _this.overlayDir.overlayRef && _this.overlayDir.overlayRef.overlayElement) { _this.overlayDir.overlayRef.overlayElement.style.fontSize = _this._triggerFontSize + "px"; } }); }; /** Closes the overlay panel and focuses the host element. */ /** * Closes the overlay panel and focuses the host element. * @return {?} */ MatSelect.prototype.close = /** * Closes the overlay panel and focuses the host element. * @return {?} */ function () { if (this._panelOpen) { this._panelOpen = false; this._keyManager.withHorizontalOrientation(this._isRtl() ? 'rtl' : 'ltr'); this._changeDetectorRef.markForCheck(); this._onTouched(); } }; /** * Sets the select's value. Part of the ControlValueAccessor interface * required to integrate with Angular's core forms API. * * @param value New value to be written to the model. */ /** * Sets the select's value. Part of the ControlValueAccessor interface * required to integrate with Angular's core forms API. * * @param {?} value New value to be written to the model. * @return {?} */ MatSelect.prototype.writeValue = /** * Sets the select's value. Part of the ControlValueAccessor interface * required to integrate with Angular's core forms API. * * @param {?} value New value to be written to the model. * @return {?} */ function (value) { if (this.options) { this._setSelectionByValue(value); } }; /** * 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. */ /** * 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. * @return {?} */ MatSelect.prototype.registerOnChange = /** * 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. * @return {?} */ function (fn) { this._onChange = fn; }; /** * 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. */ /** * 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. * @return {?} */ MatSelect.prototype.registerOnTouched = /** * 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. * @return {?} */ function (fn) { this._onTouched = fn; }; /** * 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. */ /** * 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. * @return {?} */ MatSelect.prototype.setDisabledState = /** * 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. * @return {?} */ function (isDisabled) { this.disabled = isDisabled; this._changeDetectorRef.markForCheck(); this.stateChanges.next(); }; Object.defineProperty(MatSelect.prototype, "panelOpen", { /** Whether or not the overlay panel is open. */ get: /** * Whether or not the overlay panel is open. * @return {?} */ function () { return this._panelOpen; }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "selected", { /** The currently selected option. */ get: /** * The currently selected option. * @return {?} */ function () { return this.multiple ? this._selectionModel.selected : this._selectionModel.selected[0]; }, enumerable: true, configurable: true }); Object.defineProperty(MatSelect.prototype, "triggerValue", { /** The value displayed in the trigger. */ get: /** * The value displayed in the trigger. * @return {?} */ function () { if (this.empty) { return ''; } if (this._multiple) { var /** @type {?} */ selectedOptions = this._selectionModel.selected.map(function (option) { return option.viewValue; }); if (this._isRtl()) { selectedOptions.reverse(); } // TODO(crisbeto): delimiter should be configurable for proper localization. return selectedOptions.join(', '); } return this._selectionModel.selected[0].viewValue; }, enumerable: true, configurable: true }); /** Whether the element is in RTL mode. */ /** * Whether the element is in RTL mode. * @return {?} */ MatSelect.prototype._isRtl = /** * Whether the element is in RTL mode. * @return {?} */ function () { return this._dir ? this._dir.value === 'rtl' : false; }; /** Handles all keydown events on the select. */ /** * Handles all keydown events on the select. * @param {?} event * @return {?} */ MatSelect.prototype._handleKeydown = /** * Handles all keydown events on the select. * @param {?} event * @return {?} */ function (event) { if (!this.disabled) { this.panelOpen ? this._handleOpenKeydown(event) : this._handleClosedKeydown(event); } }; /** * Handles keyboard events while the select is closed. * @param {?} event * @return {?} */ MatSelect.prototype._handleClosedKeydown = /** * Handles keyboard events while the select is closed. * @param {?} event * @return {?} */ function (event) { var /** @type {?} */ keyCode = event.keyCode; var /** @type {?} */ isArrowKey = keyCode === _angular_cdk_keycodes.DOWN_ARROW || keyCode === _angular_cdk_keycodes.UP_ARROW || keyCode === _angular_cdk_keycodes.LEFT_ARROW || keyCode === _angular_cdk_keycodes.RIGHT_ARROW; var /** @type {?} */ isOpenKey = keyCode === _angular_cdk_keycodes.ENTER || keyCode === _angular_cdk_keycodes.SPACE; // Open the select on ALT + arrow key to match the native <select> if (isOpenKey || ((this.multiple || event.altKey) && isArrowKey)) { event.preventDefault(); // prevents the page from scrolling down when pressing space this.open(); } else if (!this.multiple) { this._keyManager.onKeydown(event); } }; /** * Handles keyboard events when the selected is open. * @param {?} event * @return {?} */ MatSelect.prototype._handleOpenKeydown = /** * Handles keyboard events when the selected is open. * @param {?} event * @return {?} */ function (event) { var /** @type {?} */ keyCode = event.keyCode; var /** @type {?} */ isArrowKey = keyCode === _angular_cdk_keycodes.DOWN_ARROW || keyCode === _angular_cdk_keycodes.UP_ARROW; var /** @type {?} */ manager = this._keyManager; if (keyCode === _angular_cdk_keycodes.HOME || keyCode === _angular_cdk_keycodes.END) { event.preventDefault(); keyCode === _angular_cdk_keycodes.HOME ? manager.setFirstItemActive() : manager.setLastItemActive(); } else if (isArrowKey && event.altKey) { // Close the select on ALT + arrow key to match the native <select> event.preventDefault(); this.close(); } else if ((keyCode === _angular_cdk_keycodes.ENTER || keyCode === _angular_cdk_keycodes.SPACE) && manager.activeItem) { event.preventDefault(); manager.activeItem._selectViaInteraction(); } else { var /** @type {?} */ previouslyFocusedIndex = manager.activeItemIndex; manager.onKeydown(event); if (this._multiple && isArrowKey && event.shiftKey && manager.activeItem && manager.activeItemIndex !== previouslyFocusedIndex) { manager.activeItem._selectViaInteraction(); } } }; /** * 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. */ /** * 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. * @return {?} */ MatSelect.prototype._onPanelDone = /** * 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. * @return {?} */ function () { if (this.panelOpen) { this._scrollTop = 0; this.openedChange.emit(true); } else { this.openedChange.emit(false); this._panelDoneAnimating = false; this.overlayDir.offsetX = 0; this._changeDetectorRef.markForCheck(); } }; /** * When the panel content is done fading in, the _panelDoneAnimating property is * set so the proper class can be added to the panel. */ /** * When the panel content is done fading in, the _panelDoneAnimating property is * set so the proper class can be added to the panel. * @return {?} */ MatSelect.prototype._onFadeInDone = /** * When the panel content is done fading in, the _panelDoneAnimating property is * set so the proper class can be added to the panel. * @return {?} */ function () { this._panelDoneAnimating = this.panelOpen; this._changeDetectorRef.markForCheck(); }; /** * @return {?} */ MatSelect.prototype._onFocus = /** * @return {?} */ function () { if (!this.disabled) { this.focused = true; this.stateChanges.next(); } }; /** * Calls the touched callback only if the panel is closed. Otherwise, the trigger will * "blur" to the panel when it opens, causing a false positive. */ /** * Calls the touched callback only if the panel is closed. Otherwise, the trigger will * "blur" to the panel when it opens, causing a false positive. * @return {?} */ MatSelect.prototype._onBlur = /** * Calls the touched callback only if the panel is closed. Otherwise, the trigger will * "blur" to the panel when it opens, causing a false positive. * @return {?} */ function () { this.focused = false; if (!this.disabled && !this.panelOpen) { this._onTouched(); this._changeDetectorRef.markForCheck(); this.stateChanges.next(); } }; /** * Callback that is invoked when the overlay panel has been attached. */ /** * Callback that is invoked when the overlay panel has been attached. * @return {?} */ MatSelect.prototype._onAttached = /** * Callback that is invoked when the overlay panel has been attached. * @return {?} */ function () { var _this = this; this.overlayDir.positionChange.pipe(rxjs_operators_take.take(1)).subscribe(function () { _this._changeDetectorRef.detectChanges(); _this._calculateOverlayOffsetX(); _this.panel.nativeElement.scrollTop = _this._scrollTop; }); }; /** Returns the theme to be used on the panel. */ /** * Returns the theme to be used on the panel. * @return {?} */ MatSelect.prototype._getPanelTheme = /** * Returns the theme to be used on the panel. * @return {?} */ function () { return this._parentFormField ? "mat-" + this._parentFormField.color : ''; }; Object.defineProperty(MatSelect.prototype, "empty", { /** Whether the select has a value. */ get: /** * Whether the select has a value. * @return {?} */ function () { return !this._selectionModel || this._selectionModel.isEmpty(); }, enumerable: true, configurable: true }); /** * @return {?} */ MatSelect.prototype._initializeSelection = /** * @return {?} */ function () { var _this = this; // Defer setting the value in order to avoid the "Expression // has changed after it was checked" errors from Angular. Promise.resolve().then(function () { _this._setSelectionByValue(_this.ngControl ? _this.ngControl.value : _this._value); }); }; /** * Sets the selected option based on a value. If no option can be * found with the designated value, the select trigger is cleared. * @param {?} value * @param {?=} isUserInput * @return {?} */ MatSelect.prototype._setSelectionByValue = /** * Sets the selected option based on a value. If no option can be * found with the designated value, the select trigger is cleared. * @param {?} value * @param {?=} isUserInput * @return {?} */ function (value, isUserInput) { var _this = this; if (isUserInput === void 0) { isUserInput = false; } if (this.multiple && value) { if (!Array.isArray(value)) { throw getMatSelectNonArrayValueError(); } this._clearSelection(); value.forEach(function (currentValue) { return _this._selectValue(currentValue, isUserInput); }); this._sortValues(); } else { this._clearSelection(); var /** @type {?} */ correspondingOption = this._selectValue(value, isUserInput); // Shift focus to the active item. Note that we shouldn't do this in multiple // mode, because we don't know what option the user interacted with last. if (correspondingOption) { this._keyManager.setActiveItem(this.options.toArray().indexOf(correspondingOption)); } } this._changeDetectorRef.markForCheck(); }; /** * Finds and selects and option based on its value. * @param {?} value * @param {?=} isUserInput * @return {?} Option that has the corresponding value. */ MatSelect.prototype._selectValue = /** * Finds and selects and option based on its value. * @param {?} value * @param {?=} isUserInput * @return {?} Option that has the corresponding value. */ function (value, isUserInput) { var _this = this; if (isUserInput === void 0) { isUserInput = false; } var /** @type {?} */ correspondingOption = this.options.find(function (option) { try { // Treat null as a special reset value. return option.value != null && _this._compareWith(option.value, value); } catch (/** @type {?} */ error) { if (_angular_core.isDevMode()) { // Notify developers of errors in their comparator. console.warn(error); } return false; } }); if (correspondingOption) { isUserInput ? correspondingOption._selectViaInteraction() : correspondingOption.select(); this._selectionModel.select(correspondingOption); this.stateChanges.next(); } return correspondingOption; }; /** * Clears the select trigger and deselects every option in the list. * @param {?=} skip Option that should not be deselected. * @return {?} */ MatSelect.prototype._clearSelection = /** * Clears the select trigger and deselects every option in the list. * @param {?=} skip Option that should not be deselected. * @return {?} */ function (skip) { this._selectionModel.clear(); this.options.forEach(function (option) { if (option !== skip) { option.deselect(); } }); this.stateChanges.next(); }; /** * Sets up a key manager to listen to keyboard events on the overlay panel. * @return {?} */ MatSelect.prototype._initKeyManager = /** * Sets up a key manager to listen to keyboard events on the overlay panel. * @return {?} */ function () { var _this = this; this._keyManager = new _angular_cdk_a11y.ActiveDescendantKeyManager(this.options) .withTypeAhead() .withVerticalOrientation() .withHorizontalOrientation(this._isRtl() ? 'rtl' : 'ltr'); this._keyManager.tabOut.pipe(rxjs_operators_takeUntil.takeUntil(this._destroy)).subscribe(function () { return _this.close(); }); this._keyManager.change.pipe(rxjs_operators_takeUntil.takeUntil(this._destroy)).subscribe(function () { if (_this._panelOpen && _this.panel) { _this._scrollActiveOptionIntoView(); } else if (!_this._panelOpen && !_this.multiple && _this._keyManager.activeItem) { _this._keyManager.activeItem._selectViaInteraction(); } }); }; /** * Drops current option subscriptions and IDs and resets from scratch. * @return {?} */ MatSelect.prototype._resetOptions = /** * Drops current option subscriptions and IDs and resets from scratch. * @return {?} */ function () { var _this = this; var /** @type {?} */ changedOrDestroyed = rxjs_observable_merge.merge(this.options.changes, this._destroy); this.optionSelectionChanges .pipe(rxjs_operators_takeUntil.takeUntil(changedOrDestroyed), rxjs_operators_filter.filter(function (event) { return event.isUserInput; })) .subscribe(function (event) { _this._onSelect(event.source); if (!_this.multiple && _this._panelOpen) { _this.close(); _this.focus(); } }); // Listen to changes in the internal state of the options and react accordingly. // Handles cases like the labels of the selected options changing. rxjs_observable_merge.merge.apply(void 0, this.options.map(function (option) { return option._stateChanges; })).pipe(rxjs_operators_takeUntil.takeUntil(changedOrDestroyed)) .subscribe(function () { _this._changeDetectorRef.markForCheck(); _this.stateChanges.next(); }); this._setOptionIds(); }; /** * Invoked when an option is clicked. * @param {?} option * @return {?} */ MatSelect.prototype._onSelect = /** * Invoked when an option is clicked. * @param {?} option * @return {?} */ function (option) { var /** @type {?} */ wasSelected = this._selectionModel.isSelected(option); // TODO(crisbeto): handle blank/null options inside multi-select. if (this.multiple) { this._selectionModel.toggle(option); this.stateChanges.next(); wasSelected ? option.deselect() : option.select(); this._keyManager.setActiveItem(/** @type {?} */ ((this._getOptionIndex(option)))); this._sortValues(); } else { this._clearSelection(option.value == null ? undefined : option); if (option.value == null) { this._propagateChanges(option.value); } else { this._selectionModel.select(option); this.stateChanges.next(); } } if (wasSelected !== this._selectionModel.isSelected(option)) { this._propagateChanges(); } }; /** * Sorts the model values, ensuring that they keep the same * order that they have in the panel. * @return {?} */ MatSelect.prototype._sortValues = /** * Sorts the model values, ensuring that they keep the same * order that they have in the panel. * @return {?} */ function () { var _this = this; if (this._multiple) { this._selectionModel.clear(); this.options.forEach(function (option) { if (option.selected) { _this._selectionModel.select(option); } }); this.stateChanges.next(); } }; /** * Emits change event to set the model value. * @param {?=} fallbackValue * @return {?} */ MatSelect.prototype._propagateChanges = /** * Emits change event to set the model value. * @param {?=} fallbackValue * @return {?} */ function (fallbackValue) { var /** @type {?} */ valueToEmit = null; if (this.multiple) { valueToEmit = (/** @type {?} */ (this.selected)).map(function (option) { return option.value; }); } else { valueToEmit = this.selected ? (/** @type {?} */ (this.selected)).value : fallbackValue; } this._value = valueToEmit; this.valueChange.emit(valueToEmit); this._onChange(valueToEmit); this.selectionChange.emit(new MatSelectChange(this, valueToEmit)); this._changeDetectorRef.markForCheck(); }; /** * Records option IDs to pass to the aria-owns property. * @return {?} */ MatSelect.prototype._setOptionIds = /** * Records option IDs to pass to the aria-owns property. * @return {?} */ function () { this._optionIds = this.options.map(function (option) { return option.id; }).join(' '); }; /** * Highlights the selected item. If no option is selected, it will highlight * the first item instead. * @return {?} */ MatSelect.prototype._highlightCorrectOption = /** * Highlights the selected item. If no option is selected, it will highlight * the first item instead. * @return {?} */ function () { if (this._keyManager) { if (this.empty) { this._keyManager.setFirstItemActive(); } else { this._keyManager.setActiveItem(/** @type {?} */ ((this._getOptionIndex(this._selectionModel.selected[0])))); } } }; /** * Scrolls the active option into view. * @return {?} */ MatSelect.prototype._scrollActiveOptionIntoView = /** * Scrolls the active option into view. * @return {?} */ function () { var /** @type {?} */ activeOptionIndex = this._keyManager.activeItemIndex || 0; var /** @type {?} */ labelCount = _angular_material_core._countGroupLabelsBeforeOption(activeOptionIndex, this.options, this.optionGroups); this.panel.nativeElement.scrollTop = _angular_material_core._getOptionScrollPosition(activeOptionIndex + labelCount, this._getItemHeight(), this.panel.nativeElement.scrollTop, SELECT_PANEL_MAX_HEIGHT); }; /** Focuses the select element. */ /** * Focuses the select element. * @return {?} */ MatSelect.prototype.focus = /** * Focuses the select element. * @return {?} */ function () { this._elementRef.nativeElement.focus(); }; /** * Gets the index of the provided option in the option list. * @param {?} option * @return {?} */ MatSelect.prototype._getOptionIndex = /** * Gets the index of the provided option in the option list. * @param {?} option * @return {?} */ function (option) { return this.options.reduce(function (result, current, index) { return result === undef