UNPKG

5.81 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23import { __assign, __extends, __values } from "tslib";
24import { MDCFoundation } from '@material/base/foundation';
25import { strings } from './constants';
26var INTERACTION_EVENTS = ['click', 'keydown'];
27var MDCSelectIconFoundation = /** @class */ (function (_super) {
28 __extends(MDCSelectIconFoundation, _super);
29 function MDCSelectIconFoundation(adapter) {
30 var _this = _super.call(this, __assign(__assign({}, MDCSelectIconFoundation.defaultAdapter), adapter)) || this;
31 _this.savedTabIndex = null;
32 _this.interactionHandler = function (evt) {
33 _this.handleInteraction(evt);
34 };
35 return _this;
36 }
37 Object.defineProperty(MDCSelectIconFoundation, "strings", {
38 get: function () {
39 return strings;
40 },
41 enumerable: false,
42 configurable: true
43 });
44 Object.defineProperty(MDCSelectIconFoundation, "defaultAdapter", {
45 /**
46 * See {@link MDCSelectIconAdapter} for typing information on parameters and return types.
47 */
48 get: function () {
49 // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
50 return {
51 getAttr: function () { return null; },
52 setAttr: function () { return undefined; },
53 removeAttr: function () { return undefined; },
54 setContent: function () { return undefined; },
55 registerInteractionHandler: function () { return undefined; },
56 deregisterInteractionHandler: function () { return undefined; },
57 notifyIconAction: function () { return undefined; },
58 };
59 // tslint:enable:object-literal-sort-keys
60 },
61 enumerable: false,
62 configurable: true
63 });
64 MDCSelectIconFoundation.prototype.init = function () {
65 var e_1, _a;
66 this.savedTabIndex = this.adapter.getAttr('tabindex');
67 try {
68 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()) {
69 var evtType = INTERACTION_EVENTS_1_1.value;
70 this.adapter.registerInteractionHandler(evtType, this.interactionHandler);
71 }
72 }
73 catch (e_1_1) { e_1 = { error: e_1_1 }; }
74 finally {
75 try {
76 if (INTERACTION_EVENTS_1_1 && !INTERACTION_EVENTS_1_1.done && (_a = INTERACTION_EVENTS_1.return)) _a.call(INTERACTION_EVENTS_1);
77 }
78 finally { if (e_1) throw e_1.error; }
79 }
80 };
81 MDCSelectIconFoundation.prototype.destroy = function () {
82 var e_2, _a;
83 try {
84 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()) {
85 var evtType = INTERACTION_EVENTS_2_1.value;
86 this.adapter.deregisterInteractionHandler(evtType, this.interactionHandler);
87 }
88 }
89 catch (e_2_1) { e_2 = { error: e_2_1 }; }
90 finally {
91 try {
92 if (INTERACTION_EVENTS_2_1 && !INTERACTION_EVENTS_2_1.done && (_a = INTERACTION_EVENTS_2.return)) _a.call(INTERACTION_EVENTS_2);
93 }
94 finally { if (e_2) throw e_2.error; }
95 }
96 };
97 MDCSelectIconFoundation.prototype.setDisabled = function (disabled) {
98 if (!this.savedTabIndex) {
99 return;
100 }
101 if (disabled) {
102 this.adapter.setAttr('tabindex', '-1');
103 this.adapter.removeAttr('role');
104 }
105 else {
106 this.adapter.setAttr('tabindex', this.savedTabIndex);
107 this.adapter.setAttr('role', strings.ICON_ROLE);
108 }
109 };
110 MDCSelectIconFoundation.prototype.setAriaLabel = function (label) {
111 this.adapter.setAttr('aria-label', label);
112 };
113 MDCSelectIconFoundation.prototype.setContent = function (content) {
114 this.adapter.setContent(content);
115 };
116 MDCSelectIconFoundation.prototype.handleInteraction = function (evt) {
117 var isEnterKey = evt.key === 'Enter' || evt.keyCode === 13;
118 if (evt.type === 'click' || isEnterKey) {
119 this.adapter.notifyIconAction();
120 }
121 };
122 return MDCSelectIconFoundation;
123}(MDCFoundation));
124export { MDCSelectIconFoundation };
125// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
126export default MDCSelectIconFoundation;
127//# sourceMappingURL=foundation.js.map
\No newline at end of file