| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /**
- * @license
- * Copyright 2017 Google Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- import { __assign, __extends, __values } from "tslib";
- import { MDCFoundation } from '@material/base/foundation';
- import { cssClasses, strings } from './constants';
- var INTERACTION_EVENTS = ['click', 'keydown'];
- /** MDC Text Field Icon Foundation */
- var MDCTextFieldIconFoundation = /** @class */ (function (_super) {
- __extends(MDCTextFieldIconFoundation, _super);
- function MDCTextFieldIconFoundation(adapter) {
- var _this = _super.call(this, __assign(__assign({}, MDCTextFieldIconFoundation.defaultAdapter), adapter)) || this;
- _this.savedTabIndex = null;
- _this.interactionHandler = function (evt) {
- _this.handleInteraction(evt);
- };
- return _this;
- }
- Object.defineProperty(MDCTextFieldIconFoundation, "strings", {
- get: function () {
- return strings;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(MDCTextFieldIconFoundation, "cssClasses", {
- get: function () {
- return cssClasses;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(MDCTextFieldIconFoundation, "defaultAdapter", {
- /**
- * See {@link MDCTextFieldIconAdapter} for typing information on parameters
- * and return types.
- */
- get: function () {
- // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
- return {
- getAttr: function () { return null; },
- setAttr: function () { return undefined; },
- removeAttr: function () { return undefined; },
- setContent: function () { return undefined; },
- registerInteractionHandler: function () { return undefined; },
- deregisterInteractionHandler: function () { return undefined; },
- notifyIconAction: function () { return undefined; },
- };
- // tslint:enable:object-literal-sort-keys
- },
- enumerable: false,
- configurable: true
- });
- MDCTextFieldIconFoundation.prototype.init = function () {
- var e_1, _a;
- this.savedTabIndex = this.adapter.getAttr('tabindex');
- try {
- for (var INTERACTION_EVENTS_1 = __values(INTERACTION_EVENTS), INTERACTION_EVENTS_1_1 = INTERACTION_EVENTS_1.next(); !INTERACTION_EVENTS_1_1.done; INTERACTION_EVENTS_1_1 = INTERACTION_EVENTS_1.next()) {
- var evtType = INTERACTION_EVENTS_1_1.value;
- this.adapter.registerInteractionHandler(evtType, this.interactionHandler);
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (INTERACTION_EVENTS_1_1 && !INTERACTION_EVENTS_1_1.done && (_a = INTERACTION_EVENTS_1.return)) _a.call(INTERACTION_EVENTS_1);
- }
- finally { if (e_1) throw e_1.error; }
- }
- };
- MDCTextFieldIconFoundation.prototype.destroy = function () {
- var e_2, _a;
- try {
- for (var INTERACTION_EVENTS_2 = __values(INTERACTION_EVENTS), INTERACTION_EVENTS_2_1 = INTERACTION_EVENTS_2.next(); !INTERACTION_EVENTS_2_1.done; INTERACTION_EVENTS_2_1 = INTERACTION_EVENTS_2.next()) {
- var evtType = INTERACTION_EVENTS_2_1.value;
- this.adapter.deregisterInteractionHandler(evtType, this.interactionHandler);
- }
- }
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
- finally {
- try {
- if (INTERACTION_EVENTS_2_1 && !INTERACTION_EVENTS_2_1.done && (_a = INTERACTION_EVENTS_2.return)) _a.call(INTERACTION_EVENTS_2);
- }
- finally { if (e_2) throw e_2.error; }
- }
- };
- MDCTextFieldIconFoundation.prototype.setDisabled = function (disabled) {
- if (!this.savedTabIndex) {
- return;
- }
- if (disabled) {
- this.adapter.setAttr('tabindex', '-1');
- this.adapter.removeAttr('role');
- }
- else {
- this.adapter.setAttr('tabindex', this.savedTabIndex);
- this.adapter.setAttr('role', strings.ICON_ROLE);
- }
- };
- MDCTextFieldIconFoundation.prototype.setAriaLabel = function (label) {
- this.adapter.setAttr('aria-label', label);
- };
- MDCTextFieldIconFoundation.prototype.setContent = function (content) {
- this.adapter.setContent(content);
- };
- MDCTextFieldIconFoundation.prototype.handleInteraction = function (evt) {
- var isEnterKey = evt.key === 'Enter' ||
- evt.keyCode === 13;
- var isSpaceKey = evt.key === ' ';
- if (evt.type === 'click' || isEnterKey || isSpaceKey) {
- evt.preventDefault(); // stop click from causing host label to focus
- // input
- this.adapter.notifyIconAction();
- }
- };
- return MDCTextFieldIconFoundation;
- }(MDCFoundation));
- export { MDCTextFieldIconFoundation };
- // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
- export default MDCTextFieldIconFoundation;
- //# sourceMappingURL=foundation.js.map
|