UNPKG

4.7 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2020 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 } from "tslib";
24import { MDCFoundation } from '@material/base/foundation';
25import { isNavigationEvent, KEY, normalizeKey } from '@material/dom/keyboard';
26import { InteractionTrigger, strings } from './constants';
27var MDCChipTrailingActionFoundation = /** @class */ (function (_super) {
28 __extends(MDCChipTrailingActionFoundation, _super);
29 function MDCChipTrailingActionFoundation(adapter) {
30 return _super.call(this, __assign(__assign({}, MDCChipTrailingActionFoundation.defaultAdapter), adapter)) || this;
31 }
32 Object.defineProperty(MDCChipTrailingActionFoundation, "strings", {
33 get: function () {
34 return strings;
35 },
36 enumerable: false,
37 configurable: true
38 });
39 Object.defineProperty(MDCChipTrailingActionFoundation, "defaultAdapter", {
40 get: function () {
41 return {
42 focus: function () { return undefined; },
43 getAttribute: function () { return null; },
44 setAttribute: function () { return undefined; },
45 notifyInteraction: function () { return undefined; },
46 notifyNavigation: function () { return undefined; },
47 };
48 },
49 enumerable: false,
50 configurable: true
51 });
52 MDCChipTrailingActionFoundation.prototype.handleClick = function (evt) {
53 evt.stopPropagation();
54 this.adapter.notifyInteraction(InteractionTrigger.CLICK);
55 };
56 MDCChipTrailingActionFoundation.prototype.handleKeydown = function (evt) {
57 evt.stopPropagation();
58 var key = normalizeKey(evt);
59 if (this.shouldNotifyInteractionFromKey(key)) {
60 var trigger = this.getTriggerFromKey(key);
61 this.adapter.notifyInteraction(trigger);
62 return;
63 }
64 if (isNavigationEvent(evt)) {
65 this.adapter.notifyNavigation(key);
66 return;
67 }
68 };
69 MDCChipTrailingActionFoundation.prototype.removeFocus = function () {
70 this.adapter.setAttribute(strings.TAB_INDEX, '-1');
71 };
72 MDCChipTrailingActionFoundation.prototype.focus = function () {
73 this.adapter.setAttribute(strings.TAB_INDEX, '0');
74 this.adapter.focus();
75 };
76 MDCChipTrailingActionFoundation.prototype.isNavigable = function () {
77 return this.adapter.getAttribute(strings.ARIA_HIDDEN) !== 'true';
78 };
79 MDCChipTrailingActionFoundation.prototype.shouldNotifyInteractionFromKey = function (key) {
80 var isFromActionKey = key === KEY.ENTER || key === KEY.SPACEBAR;
81 var isFromDeleteKey = key === KEY.BACKSPACE || key === KEY.DELETE;
82 return isFromActionKey || isFromDeleteKey;
83 };
84 MDCChipTrailingActionFoundation.prototype.getTriggerFromKey = function (key) {
85 if (key === KEY.SPACEBAR) {
86 return InteractionTrigger.SPACEBAR_KEY;
87 }
88 if (key === KEY.ENTER) {
89 return InteractionTrigger.ENTER_KEY;
90 }
91 if (key === KEY.DELETE) {
92 return InteractionTrigger.DELETE_KEY;
93 }
94 if (key === KEY.BACKSPACE) {
95 return InteractionTrigger.BACKSPACE_KEY;
96 }
97 // Default case, should never be returned
98 return InteractionTrigger.UNSPECIFIED;
99 };
100 return MDCChipTrailingActionFoundation;
101}(MDCFoundation));
102export { MDCChipTrailingActionFoundation };
103// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
104export default MDCChipTrailingActionFoundation;
105//# sourceMappingURL=foundation.js.map
\No newline at end of file