@angular-mdc/web
Version:
1,362 lines (1,356 loc) • 45.5 kB
JavaScript
/**
* @license
* Copyright (c) Dominic Carretto
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE
*/
import { Directive, ElementRef, Input, InjectionToken, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef, Optional, Self, Inject, Output, ViewChild, ContentChild, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MdcFloatingLabel, MdcFloatingLabelModule } from '@angular-mdc/web/floating-label';
import { MdcLineRipple, MdcLineRippleModule } from '@angular-mdc/web/line-ripple';
import { MdcNotchedOutline, MdcNotchedOutlineModule } from '@angular-mdc/web/notched-outline';
import { mixinErrorState, MdcFormFieldControl, ErrorStateMatcher, MdcFormField, MdcFormFieldModule } from '@angular-mdc/web/form-field';
import { MdcMenu, MdcMenuModule } from '@angular-mdc/web/menu';
import { MdcListModule } from '@angular-mdc/web/list';
import { __extends, __assign, __awaiter, __generator } from 'tslib';
import { NgControl, NgForm, FormGroupDirective } from '@angular/forms';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { Platform } from '@angular/cdk/platform';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { MDCComponent } from '@angular-mdc/web/base';
import { MdcRipple } from '@angular-mdc/web/ripple';
import { MDCRippleFoundation } from '@material/ripple';
import { MDCSelectFoundation, strings, MDCSelectHelperTextFoundation } from '@material/select';
/**
* @fileoverview added by tsickle
* Generated from: select/select-directives.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var MdcSelectIcon = /** @class */ (function () {
function MdcSelectIcon() {
}
MdcSelectIcon.decorators = [
{ type: Directive, args: [{
selector: '[mdcSelectIcon]',
exportAs: 'mdcSelectIcon',
host: { 'class': 'mdc-select__icon' }
},] },
];
return MdcSelectIcon;
}());
var MdcSelectAnchor = /** @class */ (function () {
function MdcSelectAnchor(elementRef) {
this.elementRef = elementRef;
}
Object.defineProperty(MdcSelectAnchor.prototype, "root", {
get: /**
* @return {?}
*/
function () {
return this.elementRef.nativeElement;
},
enumerable: true,
configurable: true
});
MdcSelectAnchor.decorators = [
{ type: Directive, args: [{
selector: '[mdcSelectAnchor]',
exportAs: 'mdcSelectAnchor',
host: { 'class': 'mdc-select__anchor' }
},] },
];
/** @nocollapse */
MdcSelectAnchor.ctorParameters = function () { return [
{ type: ElementRef }
]; };
return MdcSelectAnchor;
}());
var MdcSelectedText = /** @class */ (function () {
function MdcSelectedText(elementRef) {
this.elementRef = elementRef;
}
Object.defineProperty(MdcSelectedText.prototype, "root", {
get: /**
* @return {?}
*/
function () {
return this.elementRef.nativeElement;
},
enumerable: true,
configurable: true
});
MdcSelectedText.decorators = [
{ type: Directive, args: [{
selector: '[mdcSelectedText]',
exportAs: 'mdcSelectedText',
host: {
'class': 'mdc-select__selected-text',
'role': 'button',
'aria-haspopup': 'listbox',
'[attr.aria-labelledby]': 'ariaLabelledby',
'[attr.aria-required]': 'ariaRequired'
}
},] },
];
/** @nocollapse */
MdcSelectedText.ctorParameters = function () { return [
{ type: ElementRef }
]; };
MdcSelectedText.propDecorators = {
ariaLabelledby: [{ type: Input }],
ariaRequired: [{ type: Input }]
};
return MdcSelectedText;
}());
/**
* @fileoverview added by tsickle
* Generated from: select/select.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Injection token that can be used to configure the default options for all
* mdc-select usage within an app.
* @type {?}
*/
var MDC_SELECT_DEFAULT_OPTIONS = new InjectionToken('MDC_SELECT_DEFAULT_OPTIONS');
var MdcSelectBase = /** @class */ (function (_super) {
__extends(MdcSelectBase, _super);
function MdcSelectBase(_elementRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl) {
var _this = _super.call(this, _elementRef) || this;
_this._elementRef = _elementRef;
_this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
_this._parentForm = _parentForm;
_this._parentFormGroup = _parentFormGroup;
_this.ngControl = ngControl;
return _this;
}
return MdcSelectBase;
}(MDCComponent));
/** @type {?} */
var _MdcSelectMixinBase = mixinErrorState(MdcSelectBase);
var MdcSelectChange = /** @class */ (function () {
function MdcSelectChange(source, index, value) {
this.source = source;
this.index = index;
this.value = value;
}
return MdcSelectChange;
}());
/** @type {?} */
var nextUniqueId = 0;
var MdcSelect = /** @class */ (function (_super) {
__extends(MdcSelect, _super);
function MdcSelect(_platform, _changeDetectorRef, elementRef, _defaultErrorStateMatcher, _parentFormField, _ripple, ngControl, _parentForm, _parentFormGroup, _defaults) {
var _this = _super.call(this, elementRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl) || this;
_this._platform = _platform;
_this._changeDetectorRef = _changeDetectorRef;
_this.elementRef = elementRef;
_this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
_this._parentFormField = _parentFormField;
_this._ripple = _ripple;
_this.ngControl = ngControl;
_this._defaults = _defaults;
/**
* Emits whenever the component is destroyed.
*/
_this._destroyed = new Subject();
_this._uniqueId = "mdc-select-" + ++nextUniqueId;
_this._initialized = false;
_this.id = _this._uniqueId;
_this._disabled = false;
_this._floatLabel = true;
_this._outlined = false;
_this._required = false;
_this.compareWith = (/**
* @param {?} a1
* @param {?} a2
* @return {?}
*/
function (a1, a2) { return a1 === a2; });
/**
* Event emitted when the selected value has been changed by the user.
*/
_this.selectionChange = new 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.
*/
_this.valueChange = new EventEmitter();
_this.blur = new EventEmitter();
_this._onFocus = new EventEmitter();
/**
* View to model callback called when value changes
*/
_this._onChange = (/**
* @return {?}
*/
function () { });
/**
* View to model callback called when select has been touched
*/
_this._onTouched = (/**
* @return {?}
*/
function () { });
_this._root = _this.elementRef.nativeElement;
if (_this.ngControl) {
// Note: we provide the value accessor through here, instead of
// the `providers` to avoid running into a circular import.
_this.ngControl.valueAccessor = _this;
}
if (_this._parentFormField) {
_parentFormField.elementRef.nativeElement.classList.add('ngx-form-field-select');
}
// Force setter to be called in case id was not specified.
_this.id = _this.id;
_this._setDefaultGlobalOptions();
return _this;
}
Object.defineProperty(MdcSelect.prototype, "disabled", {
get: /**
* @return {?}
*/
function () {
return this._disabled;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this.setDisabledState(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "floatLabel", {
get: /**
* @return {?}
*/
function () {
return this._floatLabel;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var newValue = coerceBooleanProperty(value);
if (newValue !== this._floatLabel) {
this._floatLabel = newValue;
this.layout();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "outlined", {
get: /**
* @return {?}
*/
function () {
return this._outlined;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var newValue = coerceBooleanProperty(value);
this._outlined = newValue;
this.layout();
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "required", {
get: /**
* @return {?}
*/
function () {
return this._required;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var newValue = coerceBooleanProperty(value);
if (newValue !== this._required) {
this._required = newValue;
if (this._initialized && !this._required) {
this.valid = true;
this._changeDetectorRef.markForCheck();
}
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "valid", {
get: /**
* @return {?}
*/
function () {
return this._valid;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
var _a;
/** @type {?} */
var newValue = coerceBooleanProperty(value);
this._valid = newValue;
(_a = this._foundation) === null || _a === void 0 ? void 0 : _a.setValid(this._valid);
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "value", {
/** Value of the select */
get: /**
* Value of the select
* @return {?}
*/
function () {
return this._value;
},
set: /**
* @param {?} newValue
* @return {?}
*/
function (newValue) {
if (newValue !== this._value) {
this.setSelectionByValue(newValue);
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "helperText", {
get: /**
* @return {?}
*/
function () {
return this._helperText;
},
set: /**
* @param {?} helperText
* @return {?}
*/
function (helperText) {
var _a;
this._helperText = helperText;
(_a = this.helperText) === null || _a === void 0 ? void 0 : _a.init();
},
enumerable: true,
configurable: true
});
Object.defineProperty(MdcSelect.prototype, "_hasPlaceholder", {
get: /**
* @return {?}
*/
function () {
return this.placeholder ? this.placeholder.length > 0 : false;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
MdcSelect.prototype.getDefaultFoundation = /**
* @return {?}
*/
function () {
// Do not initialize foundation until ngAfterViewInit runs
if (!this._initialized) {
return undefined;
}
/** @type {?} */
var adapter = __assign(__assign(__assign(__assign({}, this._getSelectAdapterMethods()), this._getCommonAdapterMethods()), this._getOutlineAdapterMethods()), this._getLabelAdapterMethods());
return new MDCSelectFoundation(adapter, this._getFoundationMap());
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._getSelectAdapterMethods = /**
* @private
* @return {?}
*/
function () {
var _this = this;
return {
getSelectedMenuItem: (/**
* @return {?}
*/
function () {
return (/** @type {?} */ (_this._menu)).elementRef.nativeElement.querySelector(strings.SELECTED_ITEM_SELECTOR);
}),
getMenuItemAttr: (/**
* @param {?} menuItem
* @param {?} attr
* @return {?}
*/
function (menuItem, attr) { return menuItem.getAttribute(attr); }),
setSelectedText: (/**
* @param {?} text
* @return {?}
*/
function (text) { return _this._selectedText.root.textContent = text; }),
isSelectedTextFocused: (/**
* @return {?}
*/
function () { return _this._platform.isBrowser ?
document.activeElement === _this._selectedText.root : false; }),
getSelectedTextAttr: (/**
* @param {?} attr
* @return {?}
*/
function (attr) { return _this._selectedText.root.getAttribute(attr); }),
setSelectedTextAttr: (/**
* @param {?} attr
* @param {?} value
* @return {?}
*/
function (attr, value) { return _this._selectedText.root.setAttribute(attr, value); }),
openMenu: (/**
* @return {?}
*/
function () { return _this._menu.open = true; }),
closeMenu: (/**
* @return {?}
*/
function () { return _this._menu.open = false; }),
getAnchorElement: (/**
* @return {?}
*/
function () { return _this._selectAnchor.root; }),
setMenuAnchorElement: (/**
* @param {?} anchorEl
* @return {?}
*/
function (anchorEl) { return _this._menu.anchorElement = anchorEl; }),
setMenuAnchorCorner: (/**
* @param {?} anchorCorner
* @return {?}
*/
function (anchorCorner) { return _this._menu.anchorCorner = anchorCorner; }),
setMenuWrapFocus: (/**
* @param {?} wrapFocus
* @return {?}
*/
function (wrapFocus) { return _this._menu.wrapFocus = wrapFocus; }),
setAttributeAtIndex: (/**
* @param {?} index
* @param {?} attributeName
* @param {?} attributeValue
* @return {?}
*/
function (index, attributeName, attributeValue) {
return (/** @type {?} */ (_this._menu._list)).items.toArray()[index].getListItemElement().setAttribute(attributeName, attributeValue);
}),
removeAttributeAtIndex: (/**
* @param {?} index
* @param {?} attributeName
* @return {?}
*/
function (index, attributeName) {
return (/** @type {?} */ (_this._menu._list)).items.toArray()[index].getListItemElement().removeAttribute(attributeName);
}),
focusMenuItemAtIndex: (/**
* @param {?} index
* @return {?}
*/
function (index) { return (/** @type {?} */ (_this._menu._list)).items.toArray()[index].focus(); }),
getMenuItemCount: (/**
* @return {?}
*/
function () { return (/** @type {?} */ (_this._menu._list)).items.length; }),
getMenuItemValues: (/**
* @return {?}
*/
function () { var _a; return _a = (/** @type {?} */ (_this._menu._list)).items.map((/**
* @param {?} el
* @return {?}
*/
function (el) {
return el.getListItemElement().getAttribute(strings.VALUE_ATTR) || '';
})), (_a !== null && _a !== void 0 ? _a : []); }),
getMenuItemTextAtIndex: (/**
* @param {?} index
* @return {?}
*/
function (index) { var _a; return _a = (/** @type {?} */ (_this._menu._list)).items.toArray()[index].getListItemElement().textContent, (_a !== null && _a !== void 0 ? _a : ''); }),
addClassAtIndex: (/**
* @param {?} index
* @param {?} className
* @return {?}
*/
function (index, className) {
return (/** @type {?} */ (_this._menu._list)).items.toArray()[index].getListItemElement().classList.add(className);
}),
removeClassAtIndex: (/**
* @param {?} index
* @param {?} className
* @return {?}
*/
function (index, className) {
return (/** @type {?} */ (_this._menu._list)).items.toArray()[index].getListItemElement().classList.remove(className);
})
};
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._getCommonAdapterMethods = /**
* @private
* @return {?}
*/
function () {
var _this = this;
return {
addClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this._root.classList.add(className); }),
removeClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this._root.classList.remove(className); }),
hasClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this._root.classList.contains(className); }),
setRippleCenter: (/**
* @param {?} normalizedX
* @return {?}
*/
function (normalizedX) { var _a; return (_a = _this._lineRipple) === null || _a === void 0 ? void 0 : _a.setRippleCenter(normalizedX); }),
activateBottomLine: (/**
* @return {?}
*/
function () { var _a; return (_a = _this._lineRipple) === null || _a === void 0 ? void 0 : _a.activate(); }),
deactivateBottomLine: (/**
* @return {?}
*/
function () { var _a; return (_a = _this._lineRipple) === null || _a === void 0 ? void 0 : _a.deactivate(); }),
notifyChange: (/**
* @return {?}
*/
function () { })
};
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._getOutlineAdapterMethods = /**
* @private
* @return {?}
*/
function () {
var _this = this;
return {
hasOutline: (/**
* @return {?}
*/
function () { return !!_this._notchedOutline; }),
notchOutline: (/**
* @param {?} labelWidth
* @return {?}
*/
function (labelWidth) { var _a; return (_a = _this._notchedOutline) === null || _a === void 0 ? void 0 : _a.notch(labelWidth); }),
closeOutline: (/**
* @return {?}
*/
function () { var _a; return (_a = _this._notchedOutline) === null || _a === void 0 ? void 0 : _a.closeNotch(); })
};
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._getLabelAdapterMethods = /**
* @private
* @return {?}
*/
function () {
var _this = this;
return {
hasLabel: (/**
* @return {?}
*/
function () { return _this._hasPlaceholder; }),
floatLabel: (/**
* @param {?} shouldFloat
* @return {?}
*/
function (shouldFloat) { return _this._getFloatingLabel().float(shouldFloat); }),
getLabelWidth: (/**
* @return {?}
*/
function () { var _a; return (_a = _this._getFloatingLabel()) === null || _a === void 0 ? void 0 : _a.getWidth(); })
};
};
/** Returns a map of all subcomponents to subfoundations.*/
/**
* Returns a map of all subcomponents to subfoundations.
* @private
* @return {?}
*/
MdcSelect.prototype._getFoundationMap = /**
* Returns a map of all subcomponents to subfoundations.
* @private
* @return {?}
*/
function () {
var _a;
return {
helperText: (_a = this._helperText) === null || _a === void 0 ? void 0 : _a.foundation
};
};
/**
* @return {?}
*/
MdcSelect.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
var _this = this;
this._initialized = true;
this._asyncBuildFoundation()
.then((/**
* @return {?}
*/
function () {
_this._selectBuilder();
}));
this._initializeSelection();
this._subscribeToMenuEvents();
};
/**
* @return {?}
*/
MdcSelect.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.destroy();
};
/** Override MdcSelectBase destroy method */
/**
* Override MdcSelectBase destroy method
* @return {?}
*/
MdcSelect.prototype.destroy = /**
* Override MdcSelectBase destroy method
* @return {?}
*/
function () {
var _a;
this._destroyed.next();
this._destroyed.complete();
(_a = this._lineRipple) === null || _a === void 0 ? void 0 : _a.destroy();
this._ripple.destroy();
this._foundation.destroy();
};
/**
* @return {?}
*/
MdcSelect.prototype.ngDoCheck = /**
* @return {?}
*/
function () {
if (this.ngControl) {
// We need to re-evaluate this on every change detection cycle, because there are some
// error triggers that we can't subscribe to (e.g. parent form submissions). This means
// that whatever logic is in here has to be super lean or we risk destroying the performance.
this.updateErrorState();
}
};
/**
* @param {?} value
* @return {?}
*/
MdcSelect.prototype.writeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
if (this._initialized) {
this.setSelectionByValue(value, false);
}
};
/**
* @param {?} fn
* @return {?}
*/
MdcSelect.prototype.registerOnChange = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this._onChange = fn;
};
/**
* @param {?} fn
* @return {?}
*/
MdcSelect.prototype.registerOnTouched = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this._onTouched = fn;
};
/**
* @return {?}
*/
MdcSelect.prototype.onFocus = /**
* @return {?}
*/
function () {
if (!this.disabled) {
this._foundation.handleFocus();
this._onFocus.emit(true);
}
};
/**
* @return {?}
*/
MdcSelect.prototype.onBlur = /**
* @return {?}
*/
function () {
this._foundation.handleBlur();
};
/**
* @param {?} evt
* @return {?}
*/
MdcSelect.prototype.onClick = /**
* @param {?} evt
* @return {?}
*/
function (evt) {
this._foundation.handleClick(this._getNormalizedXCoordinate(evt));
};
/**
* @param {?} evt
* @return {?}
*/
MdcSelect.prototype.onKeydown = /**
* @param {?} evt
* @return {?}
*/
function (evt) {
this._foundation.handleKeydown(evt);
};
/**
* @return {?}
*/
MdcSelect.prototype.getSelectedIndex = /**
* @return {?}
*/
function () {
var _a, _b;
return _b = (_a = this._foundation) === null || _a === void 0 ? void 0 : _a.getSelectedIndex(), (_b !== null && _b !== void 0 ? _b : -1);
};
/**
* @return {?}
*/
MdcSelect.prototype.focus = /**
* @return {?}
*/
function () {
this._selectedText.root.focus();
};
/**
* @param {?} index
* @return {?}
*/
MdcSelect.prototype.setSelectedIndex = /**
* @param {?} index
* @return {?}
*/
function (index) {
var _a, _b;
this.setSelectionByValue((_b = (_a = this._menu._list) === null || _a === void 0 ? void 0 : _a.getListItemByIndex(index)) === null || _b === void 0 ? void 0 : _b.value, true, index);
};
/**
* @param {?} value
* @param {?=} isUserInput
* @param {?=} index
* @return {?}
*/
MdcSelect.prototype.setSelectionByValue = /**
* @param {?} value
* @param {?=} isUserInput
* @param {?=} index
* @return {?}
*/
function (value, isUserInput, index) {
if (isUserInput === void 0) { isUserInput = true; }
var _a;
if (!this._value && !value) {
return;
}
if (!index) {
index = (_a = this._menu._list) === null || _a === void 0 ? void 0 : _a.getListItemIndexByValue(value);
}
this._value = value;
this._foundation.setSelectedIndex((index !== null && index !== void 0 ? index : -1), this._menu.closeSurfaceOnSelection);
if (isUserInput) {
this._onChange(this._value);
this.selectionChange.emit(new MdcSelectChange(this, this.getSelectedIndex(), value));
}
this.valueChange.emit({
index: this.getSelectedIndex(),
value: this._value
});
this._foundation.handleChange();
this._changeDetectorRef.markForCheck();
};
// Implemented as part of ControlValueAccessor.
// Implemented as part of ControlValueAccessor.
/**
* @param {?} disabled
* @return {?}
*/
MdcSelect.prototype.setDisabledState =
// Implemented as part of ControlValueAccessor.
/**
* @param {?} disabled
* @return {?}
*/
function (disabled) {
var _a;
this._disabled = coerceBooleanProperty(disabled);
(_a = this._foundation) === null || _a === void 0 ? void 0 : _a.setDisabled(this._disabled);
this._changeDetectorRef.markForCheck();
};
Object.defineProperty(MdcSelect.prototype, "_hasValue", {
get: /**
* @return {?}
*/
function () {
var _a;
return ((_a = this._value) === null || _a === void 0 ? void 0 : _a.length) > 0;
},
enumerable: true,
configurable: true
});
/** Initialize Select internal state based on the environment state */
/**
* Initialize Select internal state based on the environment state
* @private
* @return {?}
*/
MdcSelect.prototype.layout = /**
* Initialize Select internal state based on the environment state
* @private
* @return {?}
*/
function () {
var _this = this;
if (this._initialized) {
this._asyncBuildFoundation().then((/**
* @return {?}
*/
function () {
_this._selectBuilder();
_this._foundation.layout();
}));
}
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._initializeSelection = /**
* @private
* @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((/**
* @return {?}
*/
function () {
var _a, _b;
/** @type {?} */
var value = (_b = (_a = _this.ngControl) === null || _a === void 0 ? void 0 : _a.value, (_b !== null && _b !== void 0 ? _b : _this._value));
if (value) {
_this.setSelectionByValue(value, false);
}
}));
};
/** Set the default options. */
/**
* Set the default options.
* @private
* @return {?}
*/
MdcSelect.prototype._setDefaultGlobalOptions = /**
* Set the default options.
* @private
* @return {?}
*/
function () {
if (this._defaults) {
if (this._defaults.outlined != null) {
this.outlined = this._defaults.outlined;
}
}
};
/**
* @return {?}
*/
MdcSelect.prototype._asyncBuildFoundation = /**
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this._foundation = this.getDefaultFoundation();
return [2 /*return*/];
});
});
};
/**
* @return {?}
*/
MdcSelect.prototype._asyncInitFoundation = /**
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this._foundation.init();
return [2 /*return*/];
});
});
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._selectBuilder = /**
* @private
* @return {?}
*/
function () {
var _this = this;
this._changeDetectorRef.detectChanges();
// initialize after running a detectChanges()
this._asyncInitFoundation()
.then((/**
* @return {?}
*/
function () {
if (!_this.outlined) {
_this._ripple = _this._createRipple();
_this._ripple.init();
}
_this._menu.wrapFocus = false;
_this._menu.elementRef.nativeElement.setAttribute('role', 'listbox');
_this._menu.elementRef.nativeElement.classList.add('mdc-select__menu');
if (_this._menu._list) {
_this._menu._list.useSelectedClass = true;
_this._menu._list.singleSelection = true;
}
}));
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._subscribeToMenuEvents = /**
* @private
* @return {?}
*/
function () {
var _this = this;
// When the list items change, re-subscribe
(/** @type {?} */ (this._menu._list)).items.changes.pipe(takeUntil(this._destroyed))
.subscribe((/**
* @return {?}
*/
function () { return _this._initializeSelection(); }));
// Subscribe to menu opened event
this._menu.opened.pipe(takeUntil(this._destroyed))
.subscribe((/**
* @return {?}
*/
function () { return _this._foundation.handleMenuOpened(); }));
// Subscribe to menu closed event
this._menu.closed.pipe(takeUntil(this._destroyed))
.subscribe((/**
* @return {?}
*/
function () {
_this._foundation.handleMenuClosed();
_this._blur();
}));
// Subscribe to list-item action event
this._menu.selected.pipe(takeUntil(this._destroyed))
.subscribe((/**
* @param {?} evt
* @return {?}
*/
function (evt) { return _this.setSelectedIndex(evt.index); }));
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._blur = /**
* @private
* @return {?}
*/
function () {
this._onTouched();
this.blur.emit(this.value);
this._onFocus.emit(false);
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._getFloatingLabel = /**
* @private
* @return {?}
*/
function () {
var _a;
return _a = this._floatingLabel, (_a !== null && _a !== void 0 ? _a : (/** @type {?} */ (this._notchedOutline)).floatingLabel);
};
/**
* Calculates where the line ripple should start based on the x coordinate within the component.
*/
/**
* Calculates where the line ripple should start based on the x coordinate within the component.
* @private
* @param {?} evt
* @return {?}
*/
MdcSelect.prototype._getNormalizedXCoordinate = /**
* Calculates where the line ripple should start based on the x coordinate within the component.
* @private
* @param {?} evt
* @return {?}
*/
function (evt) {
/** @type {?} */
var targetClientRect = ((/** @type {?} */ (evt.target))).getBoundingClientRect();
if (evt instanceof MouseEvent) {
return evt.clientX - targetClientRect.left;
}
/** @type {?} */
var clientX = evt.touches[0] && evt.touches[0].clientX;
return clientX - targetClientRect.left;
};
/**
* @private
* @return {?}
*/
MdcSelect.prototype._createRipple = /**
* @private
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var adapter = __assign(__assign({}, MdcRipple.createAdapter({ _root: this._selectAnchor.root })), { registerInteractionHandler: (/**
* @param {?} evtType
* @param {?} handler
* @return {?}
*/
function (evtType, handler) {
return _this._selectedText.root.addEventListener(evtType, handler);
}), deregisterInteractionHandler: (/**
* @param {?} evtType
* @param {?} handler
* @return {?}
*/
function (evtType, handler) {
return _this._selectedText.root.removeEventListener(evtType, handler);
}) });
return new MdcRipple(this._selectAnchor.elementRef, new MDCRippleFoundation(adapter));
};
MdcSelect.decorators = [
{ type: Component, args: [{selector: 'mdc-select',
exportAs: 'mdcSelect',
host: {
'[id]': 'id',
'class': 'mdc-select',
'[class.mdc-select--disabled]': 'disabled',
'[class.mdc-select--outlined]': 'outlined',
'[class.mdc-select--required]': 'required',
'[class.mdc-select--no-label]': '!_hasPlaceholder',
'[class.mdc-select--with-leading-icon]': 'leadingIcon',
'[class.mdc-select--invalid]': 'errorState'
},
template: "\n <div mdcSelectAnchor>\n <ng-content select=\"mdc-icon\"></ng-content>\n <i class=\"mdc-select__dropdown-icon\"></i>\n <div mdcSelectedText\n [tabindex]=\"disabled ? '-1' : '0'\"\n (focus)=\"onFocus()\"\n (blur)=\"onBlur()\"\n (keydown)=\"onKeydown($event)\"\n (click)=\"onClick($event)\"\n [ariaRequired]=\"required\"\n [ariaLabelledby]=\"id\"></div>\n <label mdcFloatingLabel *ngIf=\"!outlined\" [for]=\"id\">{{placeholder}}</label>\n <mdc-line-ripple *ngIf=\"!outlined\"></mdc-line-ripple>\n <mdc-notched-outline *ngIf=\"outlined\" [label]=\"placeholder\" [for]=\"id\"></mdc-notched-outline>\n </div>\n <ng-content select=\"mdc-menu\"></ng-content>\n ",
providers: [
MdcRipple,
{ provide: MdcFormFieldControl, useExisting: MdcSelect }
],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
},] },
];
/** @nocollapse */
MdcSelect.ctorParameters = function () { return [
{ type: Platform },
{ type: ChangeDetectorRef },
{ type: ElementRef },
{ type: ErrorStateMatcher },
{ type: MdcFormField, decorators: [{ type: Optional }] },
{ type: MdcRipple, decorators: [{ type: Optional }] },
{ type: NgControl, decorators: [{ type: Self }, { type: Optional }] },
{ type: NgForm, decorators: [{ type: Optional }] },
{ type: FormGroupDirective, decorators: [{ type: Optional }] },
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MDC_SELECT_DEFAULT_OPTIONS,] }] }
]; };
MdcSelect.propDecorators = {
id: [{ type: Input }],
name: [{ type: Input }],
placeholder: [{ type: Input }],
disabled: [{ type: Input }],
floatLabel: [{ type: Input }],
outlined: [{ type: Input }],
required: [{ type: Input }],
valid: [{ type: Input }],
compareWith: [{ type: Input }],
value: [{ type: Input }],
helperText: [{ type: Input }],
errorStateMatcher: [{ type: Input }],
selectionChange: [{ type: Output }],
valueChange: [{ type: Output }],
blur: [{ type: Output }],
_onFocus: [{ type: Output, args: ['focus',] }],
_floatingLabel: [{ type: ViewChild, args: [MdcFloatingLabel, { static: false },] }],
_lineRipple: [{ type: ViewChild, args: [MdcLineRipple, { static: false },] }],
_notchedOutline: [{ type: ViewChild, args: [MdcNotchedOutline, { static: false },] }],
_selectAnchor: [{ type: ViewChild, args: [MdcSelectAnchor, { static: false },] }],
_selectedText: [{ type: ViewChild, args: [MdcSelectedText, { static: false },] }],
_menu: [{ type: ContentChild, args: [MdcMenu, { static: false },] }],
leadingIcon: [{ type: ContentChild, args: [MdcSelectIcon, { static: false },] }]
};
return MdcSelect;
}(_MdcSelectMixinBase));
/**
* @fileoverview added by tsickle
* Generated from: select/select-helper-text.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var MDCSelectHelperText = /** @class */ (function (_super) {
__extends(MDCSelectHelperText, _super);
function MDCSelectHelperText(elementRef) {
var _this = _super.call(this, elementRef) || this;
_this.elementRef = elementRef;
_this._persistent = false;
_this._validation = false;
return _this;
}
Object.defineProperty(MDCSelectHelperText.prototype, "persistent", {
get: /**
* @return {?}
*/
function () {
return this._persistent;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._persistent = coerceBooleanProperty(value);
this._foundation.setPersistent(this._persistent);
},
enumerable: true,
configurable: true
});
Object.defineProperty(MDCSelectHelperText.prototype, "validation", {
get: /**
* @return {?}
*/
function () {
return this._validation;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._validation = coerceBooleanProperty(value);
this._foundation.setValidation(this._validation);
},
enumerable: true,
configurable: true
});
Object.defineProperty(MDCSelectHelperText.prototype, "foundation", {
get: /**
* @return {?}
*/
function () {
return this._foundation;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
MDCSelectHelperText.prototype.getDefaultFoundation = /**
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var adapter = {
addClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this.elementRef.nativeElement.classList.add(className); }),
removeClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this.elementRef.nativeElement.classList.remove(className); }),
hasClass: (/**
* @param {?} className
* @return {?}
*/
function (className) { return _this.elementRef.nativeElement.classList.contains(className); }),
setAttr: (/**
* @param {?} attr
* @param {?} value
* @return {?}
*/
function (attr, value) { return _this.elementRef.nativeElement.setAttribute(attr, value); }),
removeAttr: (/**
* @param {?} attr
* @return {?}
*/
function (attr) { return _this.elementRef.nativeElement.removeAttribute(attr); }),
setContent: (/**
* @return {?}
*/
function () { })
};
return new MDCSelectHelperTextFoundation(adapter);
};
/** Sets the validity of the helper text. */
/**
* Sets the validity of the helper text.
* @param {?} inputIsValid
* @return {?}
*/
MDCSelectHelperText.prototype.setValidity = /**
* Sets the validity of the helper text.
* @param {?} inputIsValid
* @return {?}
*/
function (inputIsValid) {
this._foundation.setValidity(inputIsValid);
};
/** Makes the helper text visible to the screen reader. */
/**
* Makes the helper text visible to the screen reader.
* @return {?}
*/
MDCSelectHelperText.prototype.showToScreenReader = /**
* Makes the helper text visible to the screen reader.
* @return {?}
*/
function () {
this._foundation.showToScreenReader();
};
/**
* @return {?}
*/
MDCSelectHelperText.prototype.init = /**
* @return {?}
*/
function () {
this._foundation.setPersistent(this.persistent);
this._foundation.setValidation(this.validation);
};
MDCSelectHelperText.decorators = [
{ type: Component, args: [{selector: "mdc-select-helper-text, [mdcSelectHelperText]",
exportAs: 'mdcSelectHelperText',
host: { 'class': 'mdc-select-helper-text' },
template: "<ng-content></ng-content>",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
},] },
];
/** @nocollapse */
MDCSelectHelperText.ctorParameters = function () { return [
{ type: ElementRef }
]; };
MDCSelectHelperText.propDecorators = {
id: [{ type: Input }],
persistent: [{ type: Input }],
validation: [{ type: Input }]
};
return MDCSelectHelperText;
}(MDCComponent));
/**
* @fileoverview added by tsickle
* Generated from: select/module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var SELECT_DECLARATIONS = [
MdcSelect,
MdcSelectAnchor,
MDCSelectHelperText,
MdcSelectIcon,
MdcSelectedText
];
var MdcSelectModule = /** @class */ (function () {
function MdcSelectModule() {
}
MdcSelectModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule,
MdcMenuModule,
MdcListModule,
MdcFormFieldModule,
MdcFloatingLabelModule,
MdcNotchedOutlineModule,
MdcLineRippleModule
],
exports: [
MdcMenuModule,
MdcListModule,
MdcFormFieldModule,
SELECT_DECLARATIONS
],
declarations: SELECT_DECLARATIONS
},] },
];
return MdcSelectModule;
}());
export { MDCSelectHelperText, MDC_SELECT_DEFAULT_OPTIONS, MdcSelect, MdcSelectAnchor, MdcSelectChange, MdcSelectIcon, MdcSelectModule, MdcSelectedText };
//# sourceMappingURL=select.es5.js.map