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 } from "tslib";
|
24 | import { MDCFoundation } from '@material/base/foundation';
|
25 | import { isNavigationEvent, KEY, normalizeKey } from '@material/dom/keyboard';
|
26 | import { InteractionTrigger, strings } from './constants';
|
27 | var MDCChipTrailingActionFoundation = (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 |
|
98 | return InteractionTrigger.UNSPECIFIED;
|
99 | };
|
100 | return MDCChipTrailingActionFoundation;
|
101 | }(MDCFoundation));
|
102 | export { MDCChipTrailingActionFoundation };
|
103 |
|
104 | export default MDCChipTrailingActionFoundation;
|
105 |
|
\ | No newline at end of file |