@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 D, useMemo as u, useState as v, useRef as c, useCallback as a, useEffect as F } from "react";
2
- function q(A = {}) {
3
- const { id: f, focusPanelOnOpen: i = !0, returnFocusOnClose: l = !0 } = A, p = D(), n = u(() => f || `menu-${p}`, [f, p]), [e, t] = v(!1), [s, d] = v(void 0), m = c(null), r = c(null), I = c(e), O = a(() => t(!0), []), g = a(() => t(!1), []), M = a(() => t((o) => !o), []);
4
- F(() => {
5
- const o = I.current;
6
- if (I.current = e, o && !e && l) {
7
- requestAnimationFrame(() => m.current?.focus?.());
8
- return;
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 && i && requestAnimationFrame(() => r.current?.focus?.());
11
- }, [e, i, l]);
12
- const C = u(
19
+ !o && e && m && requestAnimationFrame(() => i.current?.focus?.());
20
+ }, [e, m, p]);
21
+ const F = a(
13
22
  () => ({
14
23
  menuId: n,
15
- activeDescendantId: s,
16
- panelRef: r
24
+ activeDescendantId: c,
25
+ panelRef: i
17
26
  }),
18
- [n, s]
19
- ), R = u(
27
+ [n, c]
28
+ ), R = a(
20
29
  () => ({
21
30
  id: n,
22
- onActiveItemIdChange: d
31
+ onActiveItemIdChange: v
23
32
  }),
24
33
  [n]
25
34
  );
26
35
  return {
27
36
  open: e,
28
37
  setOpen: t,
29
- openMenu: O,
30
- closeMenu: g,
31
- toggleMenu: M,
38
+ openMenu: M,
39
+ closeMenu: D,
40
+ toggleMenu: E,
32
41
  menuId: n,
33
- activeDescendantId: s,
34
- setActiveDescendantId: d,
35
- triggerRef: m,
36
- panelRef: r,
37
- dropdownA11yProps: C,
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
- q as useDropdownMenuController
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.68.5",
3
+ "version": "0.68.6",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",