@primer/react 0.0.0-20260312164922 → 0.0.0-20260312164945
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/CHANGELOG.md +3 -3
- package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +29 -30
- package/dist/TreeView/useRovingTabIndex.d.ts +14 -0
- package/dist/TreeView/useRovingTabIndex.d.ts.map +1 -1
- package/dist/TreeView/useRovingTabIndex.js +94 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260312164945
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
- [#7625](https://github.com/primer/react/pull/7625) [`2e8c707`](https://github.com/primer/react/commit/2e8c70702d5096551049c29c8e79749bf63a919f) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Banner: stack inline actions vertically on narrow viewports.
|
|
14
14
|
|
|
15
|
-
- [#7621](https://github.com/primer/react/pull/7621) [`43c0462`](https://github.com/primer/react/commit/43c0462f96db643168a9eb2bc84cd07b6acb6b90) Thanks [@hectahertz](https://github.com/hectahertz)! - Memoize SelectPanel overlayProps, focusTrapSettings, and preventBubbling to reduce allocations on re-renders
|
|
16
|
-
|
|
17
15
|
- [#7654](https://github.com/primer/react/pull/7654) [`a09a60c`](https://github.com/primer/react/commit/a09a60cb8218adf8fe2ab71e46da76fbf8331bc6) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - SelectPanel: use `100dvh` and `env(safe-area-inset-bottom)` in fullscreen-on-narrow mode to prevent content from being obscured by iOS Safari's browser chrome.
|
|
18
16
|
|
|
17
|
+
- [#7544](https://github.com/primer/react/pull/7544) [`b3741d3`](https://github.com/primer/react/commit/b3741d30159cba8710c8db2f751d3526306aa754) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TreeView): replace O(n) TreeWalker with O(depth) sibling traversal
|
|
18
|
+
|
|
19
19
|
## 38.15.0
|
|
20
20
|
|
|
21
21
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectPanel.d.ts","sourceRoot":"","sources":["../../src/SelectPanel/SelectPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAC1F,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"SelectPanel.d.ts","sourceRoot":"","sources":["../../src/SelectPanel/SelectPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAC1F,OAAO,KAAK,EAAE,EAA+E,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AACnH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAE5D,OAAO,KAAK,EAAC,iCAAiC,EAAC,MAAM,oCAAoC,CAAA;AACzF,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,uBAAuB,CAAA;AAGlE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAY,SAAS,EAAC,MAAM,IAAI,CAAA;AAiB5C,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAkCjE,UAAU,0BAA0B;IAClC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAA;IAC/B,gBAAgB,EAAE,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAA;CAC5D;AAED,UAAU,yBAAyB;IACjC,QAAQ,EAAE,SAAS,EAAE,CAAA;IACrB,gBAAgB,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,CAAA;CACl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sB,EACtB,WAAW,EACX,GAAG,SAAS,EACb,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CA0yBhC;AAED,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAM1C,CAAA;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,GAAG,WAAW,CAM1D,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;CAItB,CAAA"}
|
|
@@ -56,9 +56,6 @@ const focusZoneSettings = {
|
|
|
56
56
|
// Let FilteredActionList handle focus zone
|
|
57
57
|
disabled: true
|
|
58
58
|
};
|
|
59
|
-
const closeButtonProps = {
|
|
60
|
-
'aria-label': 'Cancel and close'
|
|
61
|
-
};
|
|
62
59
|
const areItemsEqual = (itemA, itemB) => {
|
|
63
60
|
// prefer checking equivality by item.id
|
|
64
61
|
if (typeof itemA.id !== 'undefined') return itemA.id === itemB.id;else return itemA === itemB;
|
|
@@ -540,9 +537,9 @@ function Panel({
|
|
|
540
537
|
prevOpenRef.current = open;
|
|
541
538
|
}
|
|
542
539
|
}, [open, resetSort]);
|
|
543
|
-
const focusTrapSettings =
|
|
540
|
+
const focusTrapSettings = {
|
|
544
541
|
initialFocusRef: inputRef || undefined
|
|
545
|
-
}
|
|
542
|
+
};
|
|
546
543
|
const extendedTextInputProps = useMemo(() => {
|
|
547
544
|
return {
|
|
548
545
|
className: classes.TextInput,
|
|
@@ -618,11 +615,9 @@ function Panel({
|
|
|
618
615
|
regular: 'anchored',
|
|
619
616
|
narrow: 'fullscreen'
|
|
620
617
|
} : undefined, 'anchored');
|
|
621
|
-
const preventBubbling =
|
|
622
|
-
var _overlayProps$onKeyDo;
|
|
623
|
-
overlayProps === null || overlayProps === void 0 ? void 0 : (_overlayProps$onKeyDo = overlayProps.onKeyDown) === null || _overlayProps$onKeyDo === void 0 ? void 0 : _overlayProps$onKeyDo.call(overlayProps, event);
|
|
624
|
-
|
|
618
|
+
const preventBubbling = customOnKeyDown => event => {
|
|
625
619
|
// skip if a TextInput has focus
|
|
620
|
+
customOnKeyDown === null || customOnKeyDown === void 0 ? void 0 : customOnKeyDown(event);
|
|
626
621
|
const activeElement = document.activeElement;
|
|
627
622
|
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') return;
|
|
628
623
|
|
|
@@ -637,25 +632,7 @@ function Panel({
|
|
|
637
632
|
|
|
638
633
|
// if this is a typeahead event, don't propagate outside of menu
|
|
639
634
|
event.stopPropagation();
|
|
640
|
-
}
|
|
641
|
-
const mergedOverlayProps = useMemo(() => ({
|
|
642
|
-
role: 'dialog',
|
|
643
|
-
'aria-labelledby': titleId,
|
|
644
|
-
'aria-describedby': subtitle ? subtitleId : undefined,
|
|
645
|
-
...overlayProps,
|
|
646
|
-
...(variant === 'modal' ? {
|
|
647
|
-
top: '50vh',
|
|
648
|
-
left: '50vw',
|
|
649
|
-
anchorSide: undefined
|
|
650
|
-
} : {}),
|
|
651
|
-
style: {
|
|
652
|
-
transform: variant === 'modal' ? 'translate(-50%, -50%)' : undefined,
|
|
653
|
-
...(isKeyboardVisible ? {
|
|
654
|
-
maxHeight: availablePanelHeight !== undefined ? `${availablePanelHeight}px` : 'auto'
|
|
655
|
-
} : {})
|
|
656
|
-
},
|
|
657
|
-
onKeyDown: preventBubbling
|
|
658
|
-
}), [titleId, subtitle, subtitleId, overlayProps, variant, isKeyboardVisible, availablePanelHeight, preventBubbling]);
|
|
635
|
+
};
|
|
659
636
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
660
637
|
children: [/*#__PURE__*/jsx(AnchoredOverlay, {
|
|
661
638
|
renderAnchor: renderMenuAnchor,
|
|
@@ -664,7 +641,27 @@ function Panel({
|
|
|
664
641
|
open: open,
|
|
665
642
|
onOpen: onOpen,
|
|
666
643
|
onClose: onClose,
|
|
667
|
-
overlayProps:
|
|
644
|
+
overlayProps: {
|
|
645
|
+
role: 'dialog',
|
|
646
|
+
'aria-labelledby': titleId,
|
|
647
|
+
'aria-describedby': subtitle ? subtitleId : undefined,
|
|
648
|
+
...overlayProps,
|
|
649
|
+
...(variant === 'modal' ? {
|
|
650
|
+
/* override AnchoredOverlay position */
|
|
651
|
+
top: '50vh',
|
|
652
|
+
left: '50vw',
|
|
653
|
+
anchorSide: undefined
|
|
654
|
+
} : {}),
|
|
655
|
+
style: {
|
|
656
|
+
/* override AnchoredOverlay position */
|
|
657
|
+
transform: variant === 'modal' ? 'translate(-50%, -50%)' : undefined,
|
|
658
|
+
// set maxHeight based on calculated availablePanelHeight when keyboard is visible
|
|
659
|
+
...(isKeyboardVisible ? {
|
|
660
|
+
maxHeight: availablePanelHeight !== undefined ? `${availablePanelHeight}px` : 'auto'
|
|
661
|
+
} : {})
|
|
662
|
+
},
|
|
663
|
+
onKeyDown: preventBubbling(overlayProps === null || overlayProps === void 0 ? void 0 : overlayProps.onKeyDown)
|
|
664
|
+
},
|
|
668
665
|
focusTrapSettings: focusTrapSettings,
|
|
669
666
|
focusZoneSettings: focusZoneSettings,
|
|
670
667
|
height: height,
|
|
@@ -677,7 +674,9 @@ function Panel({
|
|
|
677
674
|
pinPosition: !height,
|
|
678
675
|
className: classes.Overlay,
|
|
679
676
|
displayCloseButton: showXCloseIcon,
|
|
680
|
-
closeButtonProps:
|
|
677
|
+
closeButtonProps: {
|
|
678
|
+
'aria-label': 'Cancel and close'
|
|
679
|
+
},
|
|
681
680
|
children: /*#__PURE__*/jsxs("div", {
|
|
682
681
|
className: classes.Wrapper,
|
|
683
682
|
"data-variant": variant,
|
|
@@ -5,6 +5,20 @@ export declare function useRovingTabIndex({ containerRef, mouseDownRef, }: {
|
|
|
5
5
|
}): void;
|
|
6
6
|
export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
|
|
7
7
|
export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
|
|
8
|
+
/**
|
|
9
|
+
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
10
|
+
*
|
|
11
|
+
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
12
|
+
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
13
|
+
* that scans from the root to find the current element on every keystroke.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
16
|
+
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
17
|
+
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
18
|
+
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
19
|
+
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
20
|
+
* for items inside collapsed parents.
|
|
21
|
+
*/
|
|
8
22
|
export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
|
|
9
23
|
export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
|
|
10
24
|
export declare function getParentElement(element: HTMLElement): HTMLElement | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAK/G;AAsFD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI9E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAuB5E"}
|
|
@@ -123,25 +123,103 @@ function getElementState(element) {
|
|
|
123
123
|
return 'end';
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
129
|
+
*
|
|
130
|
+
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
131
|
+
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
132
|
+
* that scans from the root to find the current element on every keystroke.
|
|
133
|
+
*
|
|
134
|
+
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
135
|
+
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
136
|
+
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
137
|
+
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
138
|
+
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
139
|
+
* for items inside collapsed parents.
|
|
140
|
+
*/
|
|
126
141
|
function getVisibleElement(element, direction) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
if (direction === 'next') {
|
|
143
|
+
return getNextVisibleElement(element);
|
|
144
|
+
}
|
|
145
|
+
return getPreviousVisibleElement(element);
|
|
146
|
+
}
|
|
147
|
+
function getNextVisibleElement(element) {
|
|
148
|
+
// If the current item is expanded, the next visible item is its first child
|
|
149
|
+
if (element.getAttribute('aria-expanded') === 'true') {
|
|
150
|
+
const firstChild = getFirstChildElement(element);
|
|
151
|
+
if (firstChild) return firstChild;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Otherwise, walk up the tree looking for a next sibling
|
|
155
|
+
let current = element;
|
|
156
|
+
while (current) {
|
|
157
|
+
const next = getNextSiblingTreeItem(current);
|
|
158
|
+
if (next) return next;
|
|
138
159
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
160
|
+
// No next sibling at this level, try the parent's next sibling
|
|
161
|
+
current = getParentElement(current);
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
function getPreviousVisibleElement(element) {
|
|
166
|
+
const prev = getPreviousSiblingTreeItem(element);
|
|
167
|
+
if (prev) {
|
|
168
|
+
// Navigate to the deepest last visible descendant of the previous sibling
|
|
169
|
+
return getDeepestLastDescendant(prev);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// No previous sibling, the parent is the previous visible element
|
|
173
|
+
return getParentElement(element);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Walk into expanded subtrees to find the deepest last visible descendant.
|
|
178
|
+
* For example, if the last sibling is an expanded directory whose last child
|
|
179
|
+
* is also an expanded directory, we drill all the way down.
|
|
180
|
+
*/
|
|
181
|
+
function getDeepestLastDescendant(element) {
|
|
182
|
+
let current = element;
|
|
183
|
+
while (current.getAttribute('aria-expanded') === 'true') {
|
|
184
|
+
const lastChild = getLastChildTreeItem(current);
|
|
185
|
+
if (!lastChild) break;
|
|
186
|
+
current = lastChild;
|
|
187
|
+
}
|
|
188
|
+
return current;
|
|
189
|
+
}
|
|
190
|
+
function getNextSiblingTreeItem(element) {
|
|
191
|
+
let sibling = element.nextElementSibling;
|
|
192
|
+
while (sibling) {
|
|
193
|
+
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
194
|
+
return sibling;
|
|
195
|
+
}
|
|
196
|
+
sibling = sibling.nextElementSibling;
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
function getPreviousSiblingTreeItem(element) {
|
|
201
|
+
let sibling = element.previousElementSibling;
|
|
202
|
+
while (sibling) {
|
|
203
|
+
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
204
|
+
return sibling;
|
|
205
|
+
}
|
|
206
|
+
sibling = sibling.previousElementSibling;
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
function getLastChildTreeItem(element) {
|
|
211
|
+
// Find the [role=group] child (the subtree container), then get its last treeitem
|
|
212
|
+
for (let i = element.children.length - 1; i >= 0; i--) {
|
|
213
|
+
const child = element.children[i];
|
|
214
|
+
if (child instanceof HTMLElement && child.getAttribute('role') === 'group') {
|
|
215
|
+
let lastChild = child.lastElementChild;
|
|
216
|
+
while (lastChild && !(lastChild instanceof HTMLElement && lastChild.getAttribute('role') === 'treeitem')) {
|
|
217
|
+
lastChild = lastChild.previousElementSibling;
|
|
218
|
+
}
|
|
219
|
+
return lastChild instanceof HTMLElement ? lastChild : undefined;
|
|
220
|
+
}
|
|
143
221
|
}
|
|
144
|
-
return
|
|
222
|
+
return undefined;
|
|
145
223
|
}
|
|
146
224
|
function getFirstChildElement(element) {
|
|
147
225
|
const firstChild = element.querySelector('[role=treeitem]');
|
package/package.json
CHANGED