1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { __assign, __extends, __values } from "tslib";
|
24 | import { MDCFoundation } from '@material/base/foundation';
|
25 | import { cssClasses, strings } from './constants';
|
26 | var INTERACTION_EVENTS = ['click', 'keydown'];
|
27 | var MDCTextFieldIconFoundation = (function (_super) {
|
28 | __extends(MDCTextFieldIconFoundation, _super);
|
29 | function MDCTextFieldIconFoundation(adapter) {
|
30 | var _this = _super.call(this, __assign(__assign({}, MDCTextFieldIconFoundation.defaultAdapter), adapter)) || this;
|
31 | _this.savedTabIndex = null;
|
32 | _this.interactionHandler = function (evt) {
|
33 | _this.handleInteraction(evt);
|
34 | };
|
35 | return _this;
|
36 | }
|
37 | Object.defineProperty(MDCTextFieldIconFoundation, "strings", {
|
38 | get: function () {
|
39 | return strings;
|
40 | },
|
41 | enumerable: false,
|
42 | configurable: true
|
43 | });
|
44 | Object.defineProperty(MDCTextFieldIconFoundation, "cssClasses", {
|
45 | get: function () {
|
46 | return cssClasses;
|
47 | },
|
48 | enumerable: false,
|
49 | configurable: true
|
50 | });
|
51 | Object.defineProperty(MDCTextFieldIconFoundation, "defaultAdapter", {
|
52 | |
53 |
|
54 |
|
55 | get: function () {
|
56 |
|
57 | return {
|
58 | getAttr: function () { return null; },
|
59 | setAttr: function () { return undefined; },
|
60 | removeAttr: function () { return undefined; },
|
61 | setContent: function () { return undefined; },
|
62 | registerInteractionHandler: function () { return undefined; },
|
63 | deregisterInteractionHandler: function () { return undefined; },
|
64 | notifyIconAction: function () { return undefined; },
|
65 | };
|
66 |
|
67 | },
|
68 | enumerable: false,
|
69 | configurable: true
|
70 | });
|
71 | MDCTextFieldIconFoundation.prototype.init = function () {
|
72 | var e_1, _a;
|
73 | this.savedTabIndex = this.adapter.getAttr('tabindex');
|
74 | try {
|
75 | 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()) {
|
76 | var evtType = INTERACTION_EVENTS_1_1.value;
|
77 | this.adapter.registerInteractionHandler(evtType, this.interactionHandler);
|
78 | }
|
79 | }
|
80 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
81 | finally {
|
82 | try {
|
83 | if (INTERACTION_EVENTS_1_1 && !INTERACTION_EVENTS_1_1.done && (_a = INTERACTION_EVENTS_1.return)) _a.call(INTERACTION_EVENTS_1);
|
84 | }
|
85 | finally { if (e_1) throw e_1.error; }
|
86 | }
|
87 | };
|
88 | MDCTextFieldIconFoundation.prototype.destroy = function () {
|
89 | var e_2, _a;
|
90 | try {
|
91 | 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()) {
|
92 | var evtType = INTERACTION_EVENTS_2_1.value;
|
93 | this.adapter.deregisterInteractionHandler(evtType, this.interactionHandler);
|
94 | }
|
95 | }
|
96 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
97 | finally {
|
98 | try {
|
99 | if (INTERACTION_EVENTS_2_1 && !INTERACTION_EVENTS_2_1.done && (_a = INTERACTION_EVENTS_2.return)) _a.call(INTERACTION_EVENTS_2);
|
100 | }
|
101 | finally { if (e_2) throw e_2.error; }
|
102 | }
|
103 | };
|
104 | MDCTextFieldIconFoundation.prototype.setDisabled = function (disabled) {
|
105 | if (!this.savedTabIndex) {
|
106 | return;
|
107 | }
|
108 | if (disabled) {
|
109 | this.adapter.setAttr('tabindex', '-1');
|
110 | this.adapter.removeAttr('role');
|
111 | }
|
112 | else {
|
113 | this.adapter.setAttr('tabindex', this.savedTabIndex);
|
114 | this.adapter.setAttr('role', strings.ICON_ROLE);
|
115 | }
|
116 | };
|
117 | MDCTextFieldIconFoundation.prototype.setAriaLabel = function (label) {
|
118 | this.adapter.setAttr('aria-label', label);
|
119 | };
|
120 | MDCTextFieldIconFoundation.prototype.setContent = function (content) {
|
121 | this.adapter.setContent(content);
|
122 | };
|
123 | MDCTextFieldIconFoundation.prototype.handleInteraction = function (evt) {
|
124 | var isEnterKey = evt.key === 'Enter' || evt.keyCode === 13;
|
125 | if (evt.type === 'click' || isEnterKey) {
|
126 | evt.preventDefault();
|
127 |
|
128 | this.adapter.notifyIconAction();
|
129 | }
|
130 | };
|
131 | return MDCTextFieldIconFoundation;
|
132 | }(MDCFoundation));
|
133 | export { MDCTextFieldIconFoundation };
|
134 |
|
135 | export default MDCTextFieldIconFoundation;
|
136 |
|
\ | No newline at end of file |