@primer/view-components 0.1.6-rc.de7102db → 0.1.6-rc.e29fc534
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/assets/javascripts/primer_view_components.js +1 -1
- package/app/assets/javascripts/primer_view_components.js.map +1 -1
- package/app/components/primer/alpha/action_menu/action_menu_element.js +35 -14
- package/app/components/primer/alpha/modal_dialog.js +19 -1
- package/package.json +1 -1
- package/static/constants.json +2 -8
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _ActionMenuElement_instances, _ActionMenuElement_abortController, _ActionMenuElement_originalLabel, _ActionMenuElement_setDynamicLabel;
|
|
12
|
+
var _ActionMenuElement_instances, _ActionMenuElement_abortController, _ActionMenuElement_originalLabel, _ActionMenuElement_setDynamicLabel, _ActionMenuElement_isEnterKeydown, _ActionMenuElement_firstItem_get;
|
|
13
13
|
import '@github/include-fragment-element';
|
|
14
14
|
const popoverSelector = (() => {
|
|
15
15
|
try {
|
|
@@ -20,7 +20,7 @@ const popoverSelector = (() => {
|
|
|
20
20
|
return '.\\:open';
|
|
21
21
|
}
|
|
22
22
|
})();
|
|
23
|
-
const menuItemSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]'
|
|
23
|
+
const menuItemSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]'];
|
|
24
24
|
export class ActionMenuElement extends HTMLElement {
|
|
25
25
|
constructor() {
|
|
26
26
|
super(...arguments);
|
|
@@ -81,17 +81,21 @@ export class ActionMenuElement extends HTMLElement {
|
|
|
81
81
|
}
|
|
82
82
|
handleEvent(event) {
|
|
83
83
|
var _a, _b, _c, _d;
|
|
84
|
-
if (
|
|
84
|
+
if (event.target === this.invokerElement && __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isEnterKeydown).call(this, event)) {
|
|
85
|
+
if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)) {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
(_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.showPopover();
|
|
88
|
+
__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!((_b = this.popoverElement) === null || _b === void 0 ? void 0 : _b.matches(popoverSelector)))
|
|
85
93
|
return;
|
|
86
94
|
if (event.type === 'focusout' && !this.contains(event.relatedTarget)) {
|
|
87
|
-
(
|
|
95
|
+
(_c = this.popoverElement) === null || _c === void 0 ? void 0 : _c.hidePopover();
|
|
88
96
|
}
|
|
89
|
-
else if ((event instanceof
|
|
90
|
-
event.
|
|
91
|
-
!(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
|
|
92
|
-
event.key === 'Enter') ||
|
|
93
|
-
(event instanceof MouseEvent && event.type === 'click')) {
|
|
94
|
-
const item = (_c = event.target.closest(menuItemSelectors.join(','))) === null || _c === void 0 ? void 0 : _c.closest('li');
|
|
97
|
+
else if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isEnterKeydown).call(this, event) || (event instanceof MouseEvent && event.type === 'click')) {
|
|
98
|
+
const item = (_d = event.target.closest(menuItemSelectors.join(','))) === null || _d === void 0 ? void 0 : _d.closest('li');
|
|
95
99
|
if (!item)
|
|
96
100
|
return;
|
|
97
101
|
const ariaChecked = item.getAttribute('aria-checked');
|
|
@@ -107,8 +111,19 @@ export class ActionMenuElement extends HTMLElement {
|
|
|
107
111
|
}
|
|
108
112
|
__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
|
|
109
113
|
}
|
|
110
|
-
event.
|
|
111
|
-
|
|
114
|
+
if (event instanceof KeyboardEvent && event.target instanceof HTMLButtonElement) {
|
|
115
|
+
// prevent buttons from being clicked twice
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
}
|
|
118
|
+
// Hide popover after current event loop to prevent changes in focus from
|
|
119
|
+
// altering the target of the event. Not doing this specifically affects
|
|
120
|
+
// <a> tags. It causes the event to be sent to the currently focused element
|
|
121
|
+
// instead of the anchor, which effectively prevents navigation, i.e. it
|
|
122
|
+
// appears as if hitting enter does nothing. Curiously, clicking instead
|
|
123
|
+
// works fine.
|
|
124
|
+
if (this.selectVariant !== 'multiple') {
|
|
125
|
+
setTimeout(() => { var _a; return (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.hidePopover(); });
|
|
126
|
+
}
|
|
112
127
|
}
|
|
113
128
|
}
|
|
114
129
|
}
|
|
@@ -118,8 +133,7 @@ _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalL
|
|
|
118
133
|
const invoker = this.invokerElement;
|
|
119
134
|
if (!invoker)
|
|
120
135
|
return;
|
|
121
|
-
const
|
|
122
|
-
const item = this.querySelector(selector);
|
|
136
|
+
const item = this.querySelector('[aria-checked=true]');
|
|
123
137
|
if (item && this.dynamicLabel) {
|
|
124
138
|
__classPrivateFieldSet(this, _ActionMenuElement_originalLabel, __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f") || (invoker.textContent || ''), "f");
|
|
125
139
|
const prefixSpan = document.createElement('span');
|
|
@@ -132,6 +146,13 @@ _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalL
|
|
|
132
146
|
else {
|
|
133
147
|
invoker.textContent = __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f");
|
|
134
148
|
}
|
|
149
|
+
}, _ActionMenuElement_isEnterKeydown = function _ActionMenuElement_isEnterKeydown(event) {
|
|
150
|
+
return (event instanceof KeyboardEvent &&
|
|
151
|
+
event.type === 'keydown' &&
|
|
152
|
+
!(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
|
|
153
|
+
event.key === 'Enter');
|
|
154
|
+
}, _ActionMenuElement_firstItem_get = function _ActionMenuElement_firstItem_get() {
|
|
155
|
+
return this.querySelector(menuItemSelectors.join(','));
|
|
135
156
|
};
|
|
136
157
|
if (!window.customElements.get('action-menu')) {
|
|
137
158
|
window.ActionMenuElement = ActionMenuElement;
|
|
@@ -20,7 +20,13 @@ function focusIfNeeded(elem) {
|
|
|
20
20
|
const overlayStack = [];
|
|
21
21
|
function clickHandler(event) {
|
|
22
22
|
const target = event.target;
|
|
23
|
-
|
|
23
|
+
let button = null;
|
|
24
|
+
if (target instanceof HTMLButtonElement) {
|
|
25
|
+
button = target;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
button = target === null || target === void 0 ? void 0 : target.querySelector('button');
|
|
29
|
+
}
|
|
24
30
|
if (!button)
|
|
25
31
|
return;
|
|
26
32
|
// If the user is clicking a valid dialog trigger
|
|
@@ -49,6 +55,17 @@ function clickHandler(event) {
|
|
|
49
55
|
topLevelDialog.close(true);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
58
|
+
function keydownHandler(event) {
|
|
59
|
+
if (!(event instanceof KeyboardEvent) ||
|
|
60
|
+
event.type !== 'keydown' ||
|
|
61
|
+
event.key !== 'Enter' ||
|
|
62
|
+
event.ctrlKey ||
|
|
63
|
+
event.altKey ||
|
|
64
|
+
event.metaKey ||
|
|
65
|
+
event.shiftKey)
|
|
66
|
+
return;
|
|
67
|
+
clickHandler(event);
|
|
68
|
+
}
|
|
52
69
|
function mousedownHandler(event) {
|
|
53
70
|
const target = event.target;
|
|
54
71
|
if (target === null || target === void 0 ? void 0 : target.closest('button'))
|
|
@@ -122,6 +139,7 @@ export class ModalDialogElement extends HTMLElement {
|
|
|
122
139
|
if (!this.hasAttribute('role'))
|
|
123
140
|
this.setAttribute('role', 'dialog');
|
|
124
141
|
document.addEventListener('click', clickHandler);
|
|
142
|
+
document.addEventListener('keydown', keydownHandler);
|
|
125
143
|
document.addEventListener('mousedown', mousedownHandler);
|
|
126
144
|
this.addEventListener('keydown', e => __classPrivateFieldGet(this, _ModalDialogElement_instances, "m", _ModalDialogElement_keydown).call(this, e));
|
|
127
145
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/view-components",
|
|
3
|
-
"version": "0.1.6-rc.
|
|
3
|
+
"version": "0.1.6-rc.e29fc534",
|
|
4
4
|
"description": "ViewComponents for the Primer Design System",
|
|
5
5
|
"main": "app/assets/javascripts/primer_view_components.js",
|
|
6
6
|
"module": "app/components/primer/primer.js",
|
package/static/constants.json
CHANGED
|
@@ -102,18 +102,12 @@
|
|
|
102
102
|
]
|
|
103
103
|
},
|
|
104
104
|
"Primer::Alpha::ActionMenu::List": {
|
|
105
|
-
"DEFAULT_ITEM_TAG": "
|
|
106
|
-
"ITEM_ACTION_OPTIONS": [
|
|
107
|
-
"classes",
|
|
108
|
-
"onclick",
|
|
109
|
-
"href",
|
|
110
|
-
"value"
|
|
111
|
-
],
|
|
105
|
+
"DEFAULT_ITEM_TAG": "button",
|
|
112
106
|
"ITEM_TAG_OPTIONS": [
|
|
113
107
|
"a",
|
|
114
108
|
"button",
|
|
115
109
|
"clipboard-copy",
|
|
116
|
-
"
|
|
110
|
+
"button"
|
|
117
111
|
]
|
|
118
112
|
},
|
|
119
113
|
"Primer::Alpha::AutoComplete": {
|