oneslash-design-system 2.23.0 → 2.23.1
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.
|
@@ -56,16 +56,21 @@ export default function Popover(_a) {
|
|
|
56
56
|
}, [open, anchorEl, popoverElement, onClose, returnFocus]);
|
|
57
57
|
// On close, wait one task so a click outside has moved focus first: a click on something
|
|
58
58
|
// focusable keeps it there; a click on nothing leaves it on the body, and then the anchor takes it.
|
|
59
|
+
// A caller may clear `anchorEl` in the same render that closes it, so the last one set is kept.
|
|
59
60
|
var wasOpen = useRef(open);
|
|
61
|
+
var lastAnchor = useRef(anchorEl);
|
|
62
|
+
if (anchorEl)
|
|
63
|
+
lastAnchor.current = anchorEl;
|
|
60
64
|
useEffect(function () {
|
|
61
65
|
var closed = wasOpen.current && !open;
|
|
62
66
|
wasOpen.current = open;
|
|
63
|
-
|
|
67
|
+
var target = lastAnchor.current;
|
|
68
|
+
if (!closed || !returnFocus || !target)
|
|
64
69
|
return;
|
|
65
70
|
var timer = setTimeout(function () {
|
|
66
71
|
var active = document.activeElement;
|
|
67
72
|
if (!active || active === document.body || (popoverElement === null || popoverElement === void 0 ? void 0 : popoverElement.contains(active)))
|
|
68
|
-
|
|
73
|
+
target.focus();
|
|
69
74
|
}, 0);
|
|
70
75
|
return function () { return clearTimeout(timer); };
|
|
71
76
|
}, [open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -45,3 +45,20 @@ var PopoverWithMenuWrapper = function () {
|
|
|
45
45
|
export var WithMenu = {
|
|
46
46
|
render: function () { return <PopoverWithMenuWrapper />; },
|
|
47
47
|
};
|
|
48
|
+
// The caller clears the anchor as it closes: `open` and `anchorEl` change in the same render
|
|
49
|
+
var ClearAnchorProbeBox = function () {
|
|
50
|
+
var _a = useState(null), anchor = _a[0], setAnchor = _a[1];
|
|
51
|
+
return (<div style={{ padding: "100px" }}>
|
|
52
|
+
<button type="button" onClick={function (event) { return setAnchor(anchor ? null : event.currentTarget); }}>
|
|
53
|
+
Open probe
|
|
54
|
+
</button>
|
|
55
|
+
<Popover open={anchor !== null} anchorEl={anchor} onClose={function () { return setAnchor(null); }} returnFocus>
|
|
56
|
+
<input aria-label="Inside"/>
|
|
57
|
+
</Popover>
|
|
58
|
+
</div>);
|
|
59
|
+
};
|
|
60
|
+
export var ClearAnchorProbe = {
|
|
61
|
+
// For tests/interactions.spec.ts only: hidden from the sidebar and the docs, and skipped by the visual gate
|
|
62
|
+
tags: ["!dev", "!autodocs", "test-only"],
|
|
63
|
+
render: function () { return <ClearAnchorProbeBox />; },
|
|
64
|
+
};
|