@primer/view-components 0.1.6-rc.9ad1d596 → 0.1.6-rc.b4e1d9f6
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/assets/styles/primer_view_components.css +1 -1
- package/app/assets/styles/primer_view_components.css.map +1 -1
- package/app/components/primer/alpha/action_menu/action_menu_element.d.ts +1 -0
- package/app/components/primer/alpha/action_menu/action_menu_element.js +48 -22
- package/app/components/primer/alpha/modal_dialog.js +19 -1
- package/app/components/primer/alpha/overlay.css +1 -1
- package/package.json +1 -1
- package/static/constants.json +2 -8
- package/static/info_arch.json +5 -0
- package/static/previews.json +5 -0
|
@@ -10,6 +10,7 @@ export declare class ActionMenuElement extends HTMLElement {
|
|
|
10
10
|
set dynamicLabel(value: boolean);
|
|
11
11
|
get popoverElement(): HTMLElement | null;
|
|
12
12
|
get invokerElement(): HTMLElement | null;
|
|
13
|
+
get invokerLabel(): HTMLElement | null;
|
|
13
14
|
connectedCallback(): void;
|
|
14
15
|
disconnectedCallback(): void;
|
|
15
16
|
handleEvent(event: Event): void;
|
|
@@ -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);
|
|
@@ -68,6 +68,11 @@ export class ActionMenuElement extends HTMLElement {
|
|
|
68
68
|
}
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
|
+
get invokerLabel() {
|
|
72
|
+
if (!this.invokerElement)
|
|
73
|
+
return null;
|
|
74
|
+
return this.invokerElement.querySelector('.Button-label');
|
|
75
|
+
}
|
|
71
76
|
connectedCallback() {
|
|
72
77
|
const { signal } = (__classPrivateFieldSet(this, _ActionMenuElement_abortController, new AbortController(), "f"));
|
|
73
78
|
this.addEventListener('keydown', this, { signal });
|
|
@@ -81,17 +86,21 @@ export class ActionMenuElement extends HTMLElement {
|
|
|
81
86
|
}
|
|
82
87
|
handleEvent(event) {
|
|
83
88
|
var _a, _b, _c, _d;
|
|
84
|
-
if (
|
|
89
|
+
if (event.target === this.invokerElement && __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isEnterKeydown).call(this, event)) {
|
|
90
|
+
if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)) {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
(_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.showPopover();
|
|
93
|
+
__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!((_b = this.popoverElement) === null || _b === void 0 ? void 0 : _b.matches(popoverSelector)))
|
|
85
98
|
return;
|
|
86
99
|
if (event.type === 'focusout' && !this.contains(event.relatedTarget)) {
|
|
87
|
-
(
|
|
100
|
+
(_c = this.popoverElement) === null || _c === void 0 ? void 0 : _c.hidePopover();
|
|
88
101
|
}
|
|
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');
|
|
102
|
+
else if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isEnterKeydown).call(this, event) || (event instanceof MouseEvent && event.type === 'click')) {
|
|
103
|
+
const item = (_d = event.target.closest(menuItemSelectors.join(','))) === null || _d === void 0 ? void 0 : _d.closest('li');
|
|
95
104
|
if (!item)
|
|
96
105
|
return;
|
|
97
106
|
const ariaChecked = item.getAttribute('aria-checked');
|
|
@@ -107,31 +116,48 @@ export class ActionMenuElement extends HTMLElement {
|
|
|
107
116
|
}
|
|
108
117
|
__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
|
|
109
118
|
}
|
|
110
|
-
event.
|
|
111
|
-
|
|
119
|
+
if (event instanceof KeyboardEvent && event.target instanceof HTMLButtonElement) {
|
|
120
|
+
// prevent buttons from being clicked twice
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
}
|
|
123
|
+
// Hide popover after current event loop to prevent changes in focus from
|
|
124
|
+
// altering the target of the event. Not doing this specifically affects
|
|
125
|
+
// <a> tags. It causes the event to be sent to the currently focused element
|
|
126
|
+
// instead of the anchor, which effectively prevents navigation, i.e. it
|
|
127
|
+
// appears as if hitting enter does nothing. Curiously, clicking instead
|
|
128
|
+
// works fine.
|
|
129
|
+
if (this.selectVariant !== 'multiple') {
|
|
130
|
+
setTimeout(() => { var _a; return (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.hidePopover(); });
|
|
131
|
+
}
|
|
112
132
|
}
|
|
113
133
|
}
|
|
114
134
|
}
|
|
115
135
|
_ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalLabel = new WeakMap(), _ActionMenuElement_instances = new WeakSet(), _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel() {
|
|
116
136
|
if (!this.dynamicLabel)
|
|
117
137
|
return;
|
|
118
|
-
const
|
|
119
|
-
if (!
|
|
138
|
+
const invokerLabel = this.invokerLabel;
|
|
139
|
+
if (!invokerLabel)
|
|
120
140
|
return;
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
__classPrivateFieldSet(this, _ActionMenuElement_originalLabel, __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f") || (invoker.textContent || ''), "f");
|
|
141
|
+
const itemLabel = this.querySelector('[aria-checked=true] .ActionListItem-label');
|
|
142
|
+
if (itemLabel && this.dynamicLabel) {
|
|
143
|
+
__classPrivateFieldSet(this, _ActionMenuElement_originalLabel, __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f") || (invokerLabel.textContent || ''), "f");
|
|
125
144
|
const prefixSpan = document.createElement('span');
|
|
126
145
|
prefixSpan.classList.add('color-fg-muted');
|
|
127
146
|
const contentSpan = document.createElement('span');
|
|
128
147
|
prefixSpan.textContent = this.dynamicLabelPrefix;
|
|
129
|
-
contentSpan.textContent =
|
|
130
|
-
|
|
148
|
+
contentSpan.textContent = itemLabel.textContent || '';
|
|
149
|
+
invokerLabel.replaceChildren(prefixSpan, contentSpan);
|
|
131
150
|
}
|
|
132
151
|
else {
|
|
133
|
-
|
|
134
|
-
}
|
|
152
|
+
invokerLabel.textContent = __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f");
|
|
153
|
+
}
|
|
154
|
+
}, _ActionMenuElement_isEnterKeydown = function _ActionMenuElement_isEnterKeydown(event) {
|
|
155
|
+
return (event instanceof KeyboardEvent &&
|
|
156
|
+
event.type === 'keydown' &&
|
|
157
|
+
!(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
|
|
158
|
+
event.key === 'Enter');
|
|
159
|
+
}, _ActionMenuElement_firstItem_get = function _ActionMenuElement_firstItem_get() {
|
|
160
|
+
return this.querySelector(menuItemSelectors.join(','));
|
|
135
161
|
};
|
|
136
162
|
if (!window.customElements.get('action-menu')) {
|
|
137
163
|
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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.Overlay[popover]{border-width:0;padding:0;position:absolute
|
|
1
|
+
.Overlay[popover]{border-width:0;min-width:192px;padding:0;position:absolute}.Overlay[popover]:not(:open){display:none}anchored-position{display:block}
|
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.b4e1d9f6",
|
|
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": {
|
package/static/info_arch.json
CHANGED
|
@@ -695,6 +695,11 @@
|
|
|
695
695
|
"preview_path": "/lookbook/preview/primer/alpha/action_menu/playground",
|
|
696
696
|
"name": "playground"
|
|
697
697
|
},
|
|
698
|
+
{
|
|
699
|
+
"inspect_path": "/lookbook/inspect/primer/alpha/action_menu/content_labels",
|
|
700
|
+
"preview_path": "/lookbook/preview/primer/alpha/action_menu/content_labels",
|
|
701
|
+
"name": "content_labels"
|
|
702
|
+
},
|
|
698
703
|
{
|
|
699
704
|
"inspect_path": "/lookbook/inspect/primer/alpha/action_menu/default",
|
|
700
705
|
"preview_path": "/lookbook/preview/primer/alpha/action_menu/default",
|
package/static/previews.json
CHANGED
|
@@ -123,6 +123,11 @@
|
|
|
123
123
|
"preview_path": "/lookbook/preview/primer/alpha/action_menu/playground",
|
|
124
124
|
"name": "playground"
|
|
125
125
|
},
|
|
126
|
+
{
|
|
127
|
+
"inspect_path": "/lookbook/inspect/primer/alpha/action_menu/content_labels",
|
|
128
|
+
"preview_path": "/lookbook/preview/primer/alpha/action_menu/content_labels",
|
|
129
|
+
"name": "content_labels"
|
|
130
|
+
},
|
|
126
131
|
{
|
|
127
132
|
"inspect_path": "/lookbook/inspect/primer/alpha/action_menu/default",
|
|
128
133
|
"preview_path": "/lookbook/preview/primer/alpha/action_menu/default",
|