@primer/react 38.42.0-rc.485e65078 → 38.42.0-rc.68e6f6ecb
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 +2 -0
- package/dist/Overlay/Overlay.d.ts +2 -0
- package/dist/Overlay/Overlay.js +4 -2
- package/dist/hooks/useOpenAndCloseFocus.d.ts +3 -1
- package/dist/hooks/useOpenAndCloseFocus.js +28 -16
- package/dist/hooks/useOverlay.d.ts +3 -1
- package/dist/hooks/useOverlay.js +24 -22
- package/generated/components.json +12 -0
- package/generated/hooks.json +12 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- [#8513](https://github.com/primer/react/pull/8513) [`1bab81a`](https://github.com/primer/react/commit/1bab81a0eb3f613c8d6b4abd36bd92d0ac6cedc4) Thanks [@tay1orjones](https://github.com/tay1orjones)! - ActionMenu, Overlay: Add `preventFocusOnClose` to let consumers manage focus when an overlay closes.
|
|
8
|
+
|
|
7
9
|
- [#8415](https://github.com/primer/react/pull/8415) [`66a9f31`](https://github.com/primer/react/commit/66a9f31611c642209f66ed68b7d43712b09dbd88) Thanks [@rickyzhangca](https://github.com/rickyzhangca)! - DataTable: Add controlled and uncontrolled row selection.
|
|
8
10
|
|
|
9
11
|
## 38.41.0
|
|
@@ -54,6 +54,7 @@ type ContainerProps = {
|
|
|
54
54
|
portalContainerName?: string;
|
|
55
55
|
preventOverflow?: boolean;
|
|
56
56
|
preventFocusOnOpen?: boolean;
|
|
57
|
+
preventFocusOnClose?: boolean;
|
|
57
58
|
returnFocusRef: React.RefObject<HTMLElement | null>;
|
|
58
59
|
};
|
|
59
60
|
type internalOverlayProps = Merge<OwnOverlayProps, ContainerProps>;
|
|
@@ -68,6 +69,7 @@ type internalOverlayProps = Merge<OwnOverlayProps, ContainerProps>;
|
|
|
68
69
|
* @param portalContainerName Optional. The name of the portal container to render the Overlay into.
|
|
69
70
|
* @param preventOverflow Optional. The Overlay width will be adjusted responsively if there is not enough space to display the Overlay. If `preventOverflow` is `true`, the width of the `Overlay` will not be adjusted.
|
|
70
71
|
* @param preventFocusOnOpen Optional. If 'true', focus will not be applied when the component is first mounted, even if initialFocusRef prop is given.
|
|
72
|
+
* @param preventFocusOnClose Optional. If true, focus will not be returned when the component is unmounted. Consumers must manage focus themselves.
|
|
71
73
|
* @param returnFocusRef Required. Ref for the element to focus when the `Overlay` is closed.
|
|
72
74
|
* @param right Optional. Horizontal right position of the overlay, relative to its closest positioned ancestor (often its `Portal`).
|
|
73
75
|
* @param width Sets the width of the `Overlay`, pick from our set list of widths, or pass `auto` to automatically set the width based on the content of the `Overlay`. `small` corresponds to `256px`, `medium` corresponds to `320px`, `large` corresponds to `480px`, `xlarge` corresponds to `640px`, `xxlarge` corresponds to `960px`.
|
package/dist/Overlay/Overlay.js
CHANGED
|
@@ -76,12 +76,13 @@ const BaseOverlay = /*#__PURE__*/ React.forwardRef(({ visibility, height, width,
|
|
|
76
76
|
* @param portalContainerName Optional. The name of the portal container to render the Overlay into.
|
|
77
77
|
* @param preventOverflow Optional. The Overlay width will be adjusted responsively if there is not enough space to display the Overlay. If `preventOverflow` is `true`, the width of the `Overlay` will not be adjusted.
|
|
78
78
|
* @param preventFocusOnOpen Optional. If 'true', focus will not be applied when the component is first mounted, even if initialFocusRef prop is given.
|
|
79
|
+
* @param preventFocusOnClose Optional. If true, focus will not be returned when the component is unmounted. Consumers must manage focus themselves.
|
|
79
80
|
* @param returnFocusRef Required. Ref for the element to focus when the `Overlay` is closed.
|
|
80
81
|
* @param right Optional. Horizontal right position of the overlay, relative to its closest positioned ancestor (often its `Portal`).
|
|
81
82
|
* @param width Sets the width of the `Overlay`, pick from our set list of widths, or pass `auto` to automatically set the width based on the content of the `Overlay`. `small` corresponds to `256px`, `medium` corresponds to `320px`, `large` corresponds to `480px`, `xlarge` corresponds to `640px`, `xxlarge` corresponds to `960px`.
|
|
82
83
|
|
|
83
84
|
*/
|
|
84
|
-
const Overlay = /*#__PURE__*/ React.forwardRef(({ anchorSide, _PrivateDisablePortal, height = "auto", ignoreClickRefs, initialFocusRef, left, onClickOutside, onEscape, portalContainerName, preventOverflow = true, preventFocusOnOpen, returnFocusRef, right, role = "none", visibility = "visible", width = "auto", responsiveVariant, ...props }, forwardedRef) => {
|
|
85
|
+
const Overlay = /*#__PURE__*/ React.forwardRef(({ anchorSide, _PrivateDisablePortal, height = "auto", ignoreClickRefs, initialFocusRef, left, onClickOutside, onEscape, portalContainerName, preventOverflow = true, preventFocusOnOpen, preventFocusOnClose, returnFocusRef, right, role = "none", visibility = "visible", width = "auto", responsiveVariant, ...props }, forwardedRef) => {
|
|
85
86
|
const overlayRef = useRef(null);
|
|
86
87
|
const mergedOverlayRef = useMergedRefs(forwardedRef, overlayRef);
|
|
87
88
|
const slideAnimationDistance = 8;
|
|
@@ -94,7 +95,8 @@ const Overlay = /*#__PURE__*/ React.forwardRef(({ anchorSide, _PrivateDisablePor
|
|
|
94
95
|
ignoreClickRefs,
|
|
95
96
|
onClickOutside,
|
|
96
97
|
initialFocusRef,
|
|
97
|
-
preventFocusOnOpen
|
|
98
|
+
preventFocusOnOpen,
|
|
99
|
+
preventFocusOnClose
|
|
98
100
|
});
|
|
99
101
|
useEffect(() => {
|
|
100
102
|
var _overlayRef$current;
|
|
@@ -6,12 +6,14 @@ type UseOpenAndCloseFocusSettings = {
|
|
|
6
6
|
containerRef: React.RefObject<HTMLElement | null>;
|
|
7
7
|
returnFocusRef: React.RefObject<HTMLElement | null>;
|
|
8
8
|
preventFocusOnOpen?: boolean;
|
|
9
|
+
preventFocusOnClose?: boolean;
|
|
9
10
|
};
|
|
10
11
|
declare function useOpenAndCloseFocus({
|
|
11
12
|
initialFocusRef,
|
|
12
13
|
returnFocusRef,
|
|
13
14
|
containerRef,
|
|
14
|
-
preventFocusOnOpen
|
|
15
|
+
preventFocusOnOpen,
|
|
16
|
+
preventFocusOnClose
|
|
15
17
|
}: UseOpenAndCloseFocusSettings): void;
|
|
16
18
|
//#endregion
|
|
17
19
|
export { UseOpenAndCloseFocusSettings, useOpenAndCloseFocus };
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { c } from "../utils/react-compiler-runtime.js";
|
|
2
|
+
import { useEffectCallback } from "../internal/hooks/useEffectCallback.js";
|
|
2
3
|
import { useEffect } from "react";
|
|
3
4
|
import { iterateFocusableElements } from "@primer/behaviors/utils";
|
|
4
5
|
//#region src/hooks/useOpenAndCloseFocus.ts
|
|
5
6
|
function useOpenAndCloseFocus(t0) {
|
|
6
|
-
const $ = c(
|
|
7
|
-
const { initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen } = t0;
|
|
7
|
+
const $ = c(9);
|
|
8
|
+
const { initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen, preventFocusOnClose } = t0;
|
|
8
9
|
let t1;
|
|
10
|
+
if ($[0] !== preventFocusOnClose) {
|
|
11
|
+
t1 = (element) => {
|
|
12
|
+
if (!preventFocusOnClose) element === null || element === void 0 || element.focus();
|
|
13
|
+
};
|
|
14
|
+
$[0] = preventFocusOnClose;
|
|
15
|
+
$[1] = t1;
|
|
16
|
+
} else t1 = $[1];
|
|
17
|
+
const restoreFocus = useEffectCallback(t1);
|
|
9
18
|
let t2;
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
let t3;
|
|
20
|
+
if ($[2] !== containerRef || $[3] !== initialFocusRef || $[4] !== preventFocusOnOpen || $[5] !== restoreFocus || $[6] !== returnFocusRef) {
|
|
21
|
+
t2 = () => {
|
|
12
22
|
if (!preventFocusOnOpen) {
|
|
13
23
|
if (initialFocusRef && initialFocusRef.current) initialFocusRef.current.focus();
|
|
14
24
|
else if (containerRef.current) {
|
|
@@ -18,26 +28,28 @@ function useOpenAndCloseFocus(t0) {
|
|
|
18
28
|
}
|
|
19
29
|
const returnFocusRefCurrent = returnFocusRef.current;
|
|
20
30
|
return function() {
|
|
21
|
-
returnFocusRefCurrent
|
|
31
|
+
restoreFocus(returnFocusRefCurrent);
|
|
22
32
|
};
|
|
23
33
|
};
|
|
24
|
-
|
|
34
|
+
t3 = [
|
|
25
35
|
initialFocusRef,
|
|
26
36
|
returnFocusRef,
|
|
27
37
|
containerRef,
|
|
28
|
-
preventFocusOnOpen
|
|
38
|
+
preventFocusOnOpen,
|
|
39
|
+
restoreFocus
|
|
29
40
|
];
|
|
30
|
-
$[
|
|
31
|
-
$[
|
|
32
|
-
$[
|
|
33
|
-
$[
|
|
34
|
-
$[
|
|
35
|
-
$[
|
|
41
|
+
$[2] = containerRef;
|
|
42
|
+
$[3] = initialFocusRef;
|
|
43
|
+
$[4] = preventFocusOnOpen;
|
|
44
|
+
$[5] = restoreFocus;
|
|
45
|
+
$[6] = returnFocusRef;
|
|
46
|
+
$[7] = t2;
|
|
47
|
+
$[8] = t3;
|
|
36
48
|
} else {
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
t2 = $[7];
|
|
50
|
+
t3 = $[8];
|
|
39
51
|
}
|
|
40
|
-
useEffect(
|
|
52
|
+
useEffect(t2, t3);
|
|
41
53
|
}
|
|
42
54
|
//#endregion
|
|
43
55
|
export { useOpenAndCloseFocus };
|
|
@@ -9,6 +9,7 @@ type UseOverlaySettings = {
|
|
|
9
9
|
onClickOutside: (e: TouchOrMouseEvent) => void;
|
|
10
10
|
overlayRef?: React.RefObject<HTMLDivElement | null>;
|
|
11
11
|
preventFocusOnOpen?: boolean;
|
|
12
|
+
preventFocusOnClose?: boolean;
|
|
12
13
|
};
|
|
13
14
|
type OverlayReturnProps = {
|
|
14
15
|
ref: React.RefObject<HTMLDivElement | null>;
|
|
@@ -20,7 +21,8 @@ declare const useOverlay: ({
|
|
|
20
21
|
onEscape,
|
|
21
22
|
ignoreClickRefs,
|
|
22
23
|
onClickOutside,
|
|
23
|
-
preventFocusOnOpen
|
|
24
|
+
preventFocusOnOpen,
|
|
25
|
+
preventFocusOnClose
|
|
24
26
|
}: UseOverlaySettings) => OverlayReturnProps;
|
|
25
27
|
//#endregion
|
|
26
28
|
export { OverlayReturnProps, UseOverlaySettings, useOverlay };
|
package/dist/hooks/useOverlay.js
CHANGED
|
@@ -5,53 +5,55 @@ import { useOnEscapePress } from "./useOnEscapePress.js";
|
|
|
5
5
|
import { useOpenAndCloseFocus } from "./useOpenAndCloseFocus.js";
|
|
6
6
|
//#region src/hooks/useOverlay.tsx
|
|
7
7
|
const useOverlay = (t0) => {
|
|
8
|
-
const $ = c(
|
|
9
|
-
const { overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside, preventFocusOnOpen } = t0;
|
|
8
|
+
const $ = c(14);
|
|
9
|
+
const { overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside, preventFocusOnOpen, preventFocusOnClose } = t0;
|
|
10
10
|
const overlayRef = useProvidedRefOrCreate(_overlayRef);
|
|
11
11
|
let t1;
|
|
12
|
-
if ($[0] !== initialFocusRef || $[1] !== overlayRef || $[2] !==
|
|
12
|
+
if ($[0] !== initialFocusRef || $[1] !== overlayRef || $[2] !== preventFocusOnClose || $[3] !== preventFocusOnOpen || $[4] !== returnFocusRef) {
|
|
13
13
|
t1 = {
|
|
14
14
|
containerRef: overlayRef,
|
|
15
15
|
returnFocusRef,
|
|
16
16
|
initialFocusRef,
|
|
17
|
-
preventFocusOnOpen
|
|
17
|
+
preventFocusOnOpen,
|
|
18
|
+
preventFocusOnClose
|
|
18
19
|
};
|
|
19
20
|
$[0] = initialFocusRef;
|
|
20
21
|
$[1] = overlayRef;
|
|
21
|
-
$[2] =
|
|
22
|
-
$[3] =
|
|
23
|
-
$[4] =
|
|
24
|
-
|
|
22
|
+
$[2] = preventFocusOnClose;
|
|
23
|
+
$[3] = preventFocusOnOpen;
|
|
24
|
+
$[4] = returnFocusRef;
|
|
25
|
+
$[5] = t1;
|
|
26
|
+
} else t1 = $[5];
|
|
25
27
|
useOpenAndCloseFocus(t1);
|
|
26
28
|
let t2;
|
|
27
|
-
if ($[
|
|
29
|
+
if ($[6] !== ignoreClickRefs || $[7] !== onClickOutside || $[8] !== overlayRef) {
|
|
28
30
|
t2 = {
|
|
29
31
|
containerRef: overlayRef,
|
|
30
32
|
ignoreClickRefs,
|
|
31
33
|
onClickOutside
|
|
32
34
|
};
|
|
33
|
-
$[
|
|
34
|
-
$[
|
|
35
|
-
$[
|
|
36
|
-
$[
|
|
37
|
-
} else t2 = $[
|
|
35
|
+
$[6] = ignoreClickRefs;
|
|
36
|
+
$[7] = onClickOutside;
|
|
37
|
+
$[8] = overlayRef;
|
|
38
|
+
$[9] = t2;
|
|
39
|
+
} else t2 = $[9];
|
|
38
40
|
useOnOutsideClick(t2);
|
|
39
41
|
let t3;
|
|
40
|
-
if ($[
|
|
42
|
+
if ($[10] !== onEscape) {
|
|
41
43
|
t3 = (event) => {
|
|
42
44
|
onEscape(event);
|
|
43
45
|
event.preventDefault();
|
|
44
46
|
};
|
|
45
|
-
$[
|
|
46
|
-
$[
|
|
47
|
-
} else t3 = $[
|
|
47
|
+
$[10] = onEscape;
|
|
48
|
+
$[11] = t3;
|
|
49
|
+
} else t3 = $[11];
|
|
48
50
|
useOnEscapePress(t3);
|
|
49
51
|
let t4;
|
|
50
|
-
if ($[
|
|
52
|
+
if ($[12] !== overlayRef) {
|
|
51
53
|
t4 = { ref: overlayRef };
|
|
52
|
-
$[
|
|
53
|
-
$[
|
|
54
|
-
} else t4 = $[
|
|
54
|
+
$[12] = overlayRef;
|
|
55
|
+
$[13] = t4;
|
|
56
|
+
} else t4 = $[13];
|
|
55
57
|
return t4;
|
|
56
58
|
};
|
|
57
59
|
//#endregion
|
|
@@ -832,6 +832,12 @@
|
|
|
832
832
|
"defaultValue": "",
|
|
833
833
|
"description": "Callback that is called when the position of the overlay changes"
|
|
834
834
|
},
|
|
835
|
+
{
|
|
836
|
+
"name": "preventFocusOnClose",
|
|
837
|
+
"type": "boolean",
|
|
838
|
+
"defaultValue": "false",
|
|
839
|
+
"description": "If true, focus will not be returned to the anchor or returnFocusRef when the menu closes. Consumers must manage focus themselves."
|
|
840
|
+
},
|
|
835
841
|
{
|
|
836
842
|
"name": "data-test-id",
|
|
837
843
|
"type": "unknown",
|
|
@@ -4739,6 +4745,12 @@
|
|
|
4739
4745
|
],
|
|
4740
4746
|
"importPath": "@primer/react",
|
|
4741
4747
|
"props": [
|
|
4748
|
+
{
|
|
4749
|
+
"name": "preventFocusOnClose",
|
|
4750
|
+
"type": "boolean",
|
|
4751
|
+
"defaultValue": "false",
|
|
4752
|
+
"description": "If true, focus will not be returned to returnFocusRef when the Overlay is unmounted. Consumers must manage focus themselves."
|
|
4753
|
+
},
|
|
4742
4754
|
{
|
|
4743
4755
|
"name": "returnFocusRef",
|
|
4744
4756
|
"type": "React.RefObject<HTMLElement>",
|
package/generated/hooks.json
CHANGED
|
@@ -696,6 +696,12 @@
|
|
|
696
696
|
"type": "boolean",
|
|
697
697
|
"defaultValue": "false",
|
|
698
698
|
"description": "If true, focus will not be set when the container is opened."
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
"name": "preventFocusOnClose",
|
|
702
|
+
"type": "boolean",
|
|
703
|
+
"defaultValue": "false",
|
|
704
|
+
"description": "If true, focus will not be returned to returnFocusRef when the hook is cleaned up. Consumers must manage focus themselves."
|
|
699
705
|
}
|
|
700
706
|
]
|
|
701
707
|
}
|
|
@@ -769,6 +775,12 @@
|
|
|
769
775
|
"name": "preventFocusOnOpen",
|
|
770
776
|
"type": "boolean",
|
|
771
777
|
"description": "Flag to prevent focus on the overlay when it is opened."
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
"name": "preventFocusOnClose",
|
|
781
|
+
"type": "boolean",
|
|
782
|
+
"defaultValue": "false",
|
|
783
|
+
"description": "If true, focus will not be returned to returnFocusRef when the overlay is unmounted. Consumers must manage focus themselves."
|
|
772
784
|
}
|
|
773
785
|
]
|
|
774
786
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "38.42.0-rc.
|
|
4
|
+
"version": "38.42.0-rc.68e6f6ecb",
|
|
5
5
|
"description": "An implementation of GitHub's Primer Design System using React",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
"mdast-util-to-string": "4.0.0",
|
|
158
158
|
"micromark-extension-frontmatter": "2.0.0",
|
|
159
159
|
"micromark-extension-mdxjs": "3.0.0",
|
|
160
|
-
"oxc-transform-react": "^0.
|
|
160
|
+
"oxc-transform-react": "^0.153.0",
|
|
161
161
|
"postcss-preset-primer": "^0.0.0",
|
|
162
162
|
"publint": "^0.3.15",
|
|
163
163
|
"react": "18.3.1",
|