@altinn/altinn-components 0.68.5 → 0.68.6
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.
|
@@ -1,43 +1,52 @@
|
|
|
1
|
-
import { useId as
|
|
2
|
-
function
|
|
3
|
-
const { id: f, focusPanelOnOpen:
|
|
4
|
-
|
|
5
|
-
const o =
|
|
6
|
-
if (
|
|
7
|
-
requestAnimationFrame(() =>
|
|
8
|
-
|
|
1
|
+
import { useId as y, useMemo as a, useState as O, useRef as l, useCallback as d, useEffect as P } from "react";
|
|
2
|
+
function w(C = {}) {
|
|
3
|
+
const { id: f, focusPanelOnOpen: m = !0, returnFocusOnClose: p = !0 } = C, g = y(), n = a(() => f || `menu-${g}`, [f, g]), [e, t] = O(!1), [c, v] = O(void 0), u = l(null), i = l(null), A = l(e), M = d(() => t(!0), []), D = d(() => t(!1), []), E = d(() => t((o) => !o), []);
|
|
4
|
+
P(() => {
|
|
5
|
+
const o = A.current;
|
|
6
|
+
if (A.current = e, o && !e && p) {
|
|
7
|
+
const q = requestAnimationFrame(() => {
|
|
8
|
+
const r = u.current;
|
|
9
|
+
if (!r || (r.focus?.(), document.activeElement === r)) return;
|
|
10
|
+
const s = document.querySelector("dialog[open]");
|
|
11
|
+
if (!s || s.contains(r)) return;
|
|
12
|
+
const I = () => {
|
|
13
|
+
s.removeEventListener("close", I), u.current?.focus?.();
|
|
14
|
+
};
|
|
15
|
+
s.addEventListener("close", I);
|
|
16
|
+
});
|
|
17
|
+
return () => cancelAnimationFrame(q);
|
|
9
18
|
}
|
|
10
|
-
!o && e &&
|
|
11
|
-
}, [e,
|
|
12
|
-
const
|
|
19
|
+
!o && e && m && requestAnimationFrame(() => i.current?.focus?.());
|
|
20
|
+
}, [e, m, p]);
|
|
21
|
+
const F = a(
|
|
13
22
|
() => ({
|
|
14
23
|
menuId: n,
|
|
15
|
-
activeDescendantId:
|
|
16
|
-
panelRef:
|
|
24
|
+
activeDescendantId: c,
|
|
25
|
+
panelRef: i
|
|
17
26
|
}),
|
|
18
|
-
[n,
|
|
19
|
-
), R =
|
|
27
|
+
[n, c]
|
|
28
|
+
), R = a(
|
|
20
29
|
() => ({
|
|
21
30
|
id: n,
|
|
22
|
-
onActiveItemIdChange:
|
|
31
|
+
onActiveItemIdChange: v
|
|
23
32
|
}),
|
|
24
33
|
[n]
|
|
25
34
|
);
|
|
26
35
|
return {
|
|
27
36
|
open: e,
|
|
28
37
|
setOpen: t,
|
|
29
|
-
openMenu:
|
|
30
|
-
closeMenu:
|
|
31
|
-
toggleMenu:
|
|
38
|
+
openMenu: M,
|
|
39
|
+
closeMenu: D,
|
|
40
|
+
toggleMenu: E,
|
|
32
41
|
menuId: n,
|
|
33
|
-
activeDescendantId:
|
|
34
|
-
setActiveDescendantId:
|
|
35
|
-
triggerRef:
|
|
36
|
-
panelRef:
|
|
37
|
-
dropdownA11yProps:
|
|
42
|
+
activeDescendantId: c,
|
|
43
|
+
setActiveDescendantId: v,
|
|
44
|
+
triggerRef: u,
|
|
45
|
+
panelRef: i,
|
|
46
|
+
dropdownA11yProps: F,
|
|
38
47
|
menuA11yProps: R
|
|
39
48
|
};
|
|
40
49
|
}
|
|
41
50
|
export {
|
|
42
|
-
|
|
51
|
+
w as useDropdownMenuController
|
|
43
52
|
};
|
|
@@ -21,4 +21,5 @@ export declare const Description: Story;
|
|
|
21
21
|
export declare const AsLink: Story;
|
|
22
22
|
export declare const Ungrouped: Story;
|
|
23
23
|
export declare const WithExtendedStatus: Story;
|
|
24
|
+
export declare const WithContextMenu: () => import("react/jsx-runtime").JSX.Element;
|
|
24
25
|
export declare const Loading: Story;
|