@zealakit/overlay-react 1.0.1 → 1.1.0

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.
Files changed (82) hide show
  1. package/README.md +1 -0
  2. package/dist/animation/presence.js +3 -2
  3. package/dist/components/arrow.js +2 -0
  4. package/dist/components/context-menu/content.js +1 -1
  5. package/dist/components/context-menu/context-menu.js +2 -12
  6. package/dist/components/context-menu/index.d.ts +4 -4
  7. package/dist/components/context-menu/index.js +2 -2
  8. package/dist/components/context-menu/items.js +3 -3
  9. package/dist/components/context-menu/menu-navigation.js +22 -6
  10. package/dist/components/context-menu/menu-surface.d.ts +4 -4
  11. package/dist/components/context-menu/menu-surface.js +10 -11
  12. package/dist/components/context-menu/sub.d.ts +1 -1
  13. package/dist/components/context-menu/sub.js +3 -13
  14. package/dist/components/context-menu/trigger.js +0 -1
  15. package/dist/components/dialog/content.d.ts +3 -3
  16. package/dist/components/dialog/content.js +13 -15
  17. package/dist/components/dialog/dialog.js +1 -1
  18. package/dist/components/dialog/helpers.js +1 -0
  19. package/dist/components/dialog/index.d.ts +1 -1
  20. package/dist/components/dialog/trigger.js +2 -0
  21. package/dist/components/popover/content.d.ts +24 -24
  22. package/dist/components/popover/content.js +13 -17
  23. package/dist/components/popover/helpers.js +1 -0
  24. package/dist/components/popover/index.d.ts +2 -2
  25. package/dist/components/popover/index.js +1 -1
  26. package/dist/components/popover/popover.js +3 -1
  27. package/dist/components/portal.d.ts +1 -1
  28. package/dist/components/slot.js +1 -4
  29. package/dist/components/tooltip/content.d.ts +2 -2
  30. package/dist/components/tooltip/content.js +1 -3
  31. package/dist/components/tooltip/index.d.ts +5 -5
  32. package/dist/components/tooltip/index.js +4 -4
  33. package/dist/components/tooltip/provider.js +2 -2
  34. package/dist/components/tooltip/tooltip.js +19 -28
  35. package/dist/hooks/use-layer.js +4 -4
  36. package/dist/hooks/use-overlay.js +4 -4
  37. package/dist/hooks/use-positioner.js +3 -12
  38. package/dist/index.d.ts +4 -4
  39. package/dist/index.js +4 -4
  40. package/dist/vendor/core/animation/keyframes.js +3 -15
  41. package/dist/vendor/core/animation/run-animation.d.ts +1 -1
  42. package/dist/vendor/core/animation/run-animation.js +5 -10
  43. package/dist/vendor/core/controller/animator.js +2 -2
  44. package/dist/vendor/core/controller/context-menu-behavior.js +48 -37
  45. package/dist/vendor/core/controller/overlay-controller.d.ts +1 -1
  46. package/dist/vendor/core/controller/overlay-controller.js +52 -72
  47. package/dist/vendor/core/controller/tooltip-behavior.js +1 -3
  48. package/dist/vendor/core/controller/types.d.ts +15 -1
  49. package/dist/vendor/core/events/outside.d.ts +6 -3
  50. package/dist/vendor/core/events/outside.js +12 -25
  51. package/dist/vendor/core/events/pointer.d.ts +7 -7
  52. package/dist/vendor/core/events/pointer.js +7 -9
  53. package/dist/vendor/core/focus/focus.js +45 -105
  54. package/dist/vendor/core/layer/create-layer-stack.d.ts +14 -12
  55. package/dist/vendor/core/layer/create-layer-stack.js +114 -158
  56. package/dist/vendor/core/layer/create-layer.js +1 -2
  57. package/dist/vendor/core/layer/index.d.ts +1 -2
  58. package/dist/vendor/core/layer/index.js +1 -2
  59. package/dist/vendor/core/menu/index.d.ts +1 -1
  60. package/dist/vendor/core/menu/index.js +1 -1
  61. package/dist/vendor/core/menu/navigation.d.ts +0 -12
  62. package/dist/vendor/core/menu/navigation.js +0 -42
  63. package/dist/vendor/core/modal/background.js +13 -5
  64. package/dist/vendor/core/portal/index.d.ts +1 -1
  65. package/dist/vendor/core/portal/index.js +1 -1
  66. package/dist/vendor/core/positioning/compute.js +3 -3
  67. package/dist/vendor/core/positioning/coordinates.js +1 -1
  68. package/dist/vendor/core/positioning/create-positioner.d.ts +6 -3
  69. package/dist/vendor/core/positioning/create-positioner.js +86 -76
  70. package/dist/vendor/core/positioning/placement.js +1 -3
  71. package/dist/vendor/core/scroll-lock/scroll-lock.d.ts +8 -6
  72. package/dist/vendor/core/scroll-lock/scroll-lock.js +14 -60
  73. package/dist/vendor/core/types/animation.d.ts +10 -18
  74. package/dist/vendor/core/types/animation.js +3 -5
  75. package/dist/vendor/core/types/dismissal.d.ts +15 -2
  76. package/dist/vendor/core/types/geometry.d.ts +14 -5
  77. package/dist/vendor/core/types/layer.d.ts +2 -0
  78. package/dist/vendor/core/types/positioner.d.ts +8 -1
  79. package/dist/vendor/core/utils/global-state.js +6 -0
  80. package/package.json +4 -13
  81. package/dist/vendor/core/layer/manager.d.ts +0 -9
  82. package/dist/vendor/core/layer/manager.js +0 -157
package/README.md CHANGED
@@ -17,6 +17,7 @@ Style the parts through `className`, `style`, and the `data-*` hooks below. Clos
17
17
 
18
18
  ```bash
19
19
  npm install @zealakit/overlay-react
20
+ npm install @zealakit/ui-engine # peer
20
21
 
21
22
  # or yarn, pnpm, ...
22
23
  ```
@@ -72,7 +72,7 @@ export function useOverlayElementAnimation({ element, phase, animation, placemen
72
72
  finishRef.current = onExitComplete;
73
73
  // Primitive dependencies on purpose: inline `animation` objects change identity
74
74
  // every render and must not restart a running animation.
75
- // biome-ignore lint/correctness/useExhaustiveDependencies: see above
75
+ // oxlint-disable react-hooks/exhaustive-deps -- see above
76
76
  useEffect(() => {
77
77
  if (!element || phase === "idle" || !animation.enabled) {
78
78
  return;
@@ -80,7 +80,7 @@ export function useOverlayElementAnimation({ element, phase, animation, placemen
80
80
  const handle = runOverlayAnimation(element, {
81
81
  phase,
82
82
  config: animation,
83
- placement,
83
+ ...(placement === undefined ? {} : { placement }),
84
84
  reducedMotion,
85
85
  });
86
86
  if (phase === "exit") {
@@ -101,4 +101,5 @@ export function useOverlayElementAnimation({ element, phase, animation, placemen
101
101
  placement,
102
102
  reducedMotion,
103
103
  ]);
104
+ // oxlint-enable react-hooks/exhaustive-deps
104
105
  }
@@ -13,6 +13,7 @@ const FloatingArrow = forwardRef(function FloatingArrow({ size, padding, interna
13
13
  const resolvedSize = size ?? config.size;
14
14
  const resolvedPadding = padding ?? config.padding;
15
15
  const [element, setElement] = useState(null);
16
+ // oxlint-disable react-hooks/exhaustive-deps -- positioner identities are stable; property deps are sufficient
16
17
  useEffect(() => {
17
18
  positioner.setArrowElement(element);
18
19
  return () => positioner.setArrowElement(null);
@@ -21,6 +22,7 @@ const FloatingArrow = forwardRef(function FloatingArrow({ size, padding, interna
21
22
  positioner.setArrowPadding(resolvedPadding);
22
23
  return () => positioner.setArrowPadding(config.padding);
23
24
  }, [config.padding, positioner.setArrowPadding, resolvedPadding]);
25
+ // oxlint-enable react-hooks/exhaustive-deps
24
26
  const placement = positioner.result?.placement ?? positioner.placement;
25
27
  const side = parsePlacement(placement).side;
26
28
  const computed = useMemo(() => getArrowStyles({
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useCallback, useMemo } from "react";
4
- import { OverlayPresenceContext, useOverlayPresence, } from "../../animation/presence.js";
4
+ import { OverlayPresenceContext, useOverlayPresence } from "../../animation/presence.js";
5
5
  import { MenuSurface } from "./menu-surface.js";
6
6
  import { useContextMenuContext } from "./context.js";
7
7
  function toMenuReason(reason) {
@@ -63,16 +63,6 @@ export function ContextMenu({ children, open: controlledOpen, defaultOpen = fals
63
63
  parentLayer: resolvedParentLayer,
64
64
  openAt,
65
65
  close,
66
- }), [
67
- close,
68
- dir,
69
- disabled,
70
- id,
71
- isOpen,
72
- openAt,
73
- point,
74
- resolvedParentLayer,
75
- triggerElement,
76
- ]);
77
- return (_jsx(ContextMenuContext.Provider, { value: contextValue, children: children }));
66
+ }), [close, dir, disabled, id, isOpen, openAt, point, resolvedParentLayer, triggerElement]);
67
+ return _jsx(ContextMenuContext.Provider, { value: contextValue, children: children });
78
68
  }
@@ -1,7 +1,7 @@
1
1
  export { ContextMenu, type ContextMenuProps } from "./context-menu.js";
2
- export { ContextMenuTrigger, type ContextMenuTriggerProps, } from "./trigger.js";
3
- export { ContextMenuContent, type ContextMenuContentProps, } from "./content.js";
2
+ export { ContextMenuTrigger, type ContextMenuTriggerProps } from "./trigger.js";
3
+ export { ContextMenuContent, type ContextMenuContentProps } from "./content.js";
4
4
  export { ContextMenuCheckboxItem, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, type ContextMenuCheckboxItemProps, type ContextMenuGroupProps, type ContextMenuItemProps, type ContextMenuLabelProps, type ContextMenuRadioGroupProps, type ContextMenuRadioItemProps, type ContextMenuSelectEvent, type ContextMenuSeparatorProps, type ContextMenuShortcutProps, } from "./items.js";
5
5
  export { ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, type ContextMenuSubContentProps, type ContextMenuSubProps, type ContextMenuSubTriggerProps, } from "./sub.js";
6
- export type { ContextMenuChangeReason, ContextMenuDirection, } from "./context.js";
7
- export type { ContextMenuAlign, ContextMenuCollisionAvoidance, ContextMenuSide, } from "./types.js";
6
+ export type { ContextMenuChangeReason, ContextMenuDirection } from "./context.js";
7
+ export type { ContextMenuAlign, ContextMenuCollisionAvoidance, ContextMenuSide } from "./types.js";
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  export { ContextMenu } from "./context-menu.js";
3
- export { ContextMenuTrigger, } from "./trigger.js";
4
- export { ContextMenuContent, } from "./content.js";
3
+ export { ContextMenuTrigger } from "./trigger.js";
4
+ export { ContextMenuContent } from "./content.js";
5
5
  export { ContextMenuCheckboxItem, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, } from "./items.js";
6
6
  export { ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, } from "./sub.js";
@@ -28,7 +28,7 @@ function useItemActivation(options) {
28
28
  }
29
29
  /** Standard command item. Selection closes the menu by default. */
30
30
  export const ContextMenuItem = forwardRef(function ContextMenuItem({ asChild = false, disabled = false, onSelect, closeOnSelect, onClick, onKeyDown, children, ...rest }, forwardedRef) {
31
- const activate = useItemActivation({ closeOnSelect });
31
+ const activate = useItemActivation(closeOnSelect === undefined ? {} : { closeOnSelect });
32
32
  const refs = useMemo(() => composeRefs(forwardedRef), [forwardedRef]);
33
33
  const handleClick = (event) => {
34
34
  onClick?.(event);
@@ -195,7 +195,7 @@ export const ContextMenuLabel = forwardRef(function ContextMenuLabel({ id, ...re
195
195
  setLabelId?.(null);
196
196
  };
197
197
  }, [labelId, setLabelId]);
198
- return (_jsx("div", { ...rest, ref: forwardedRef, id: labelId, "data-context-menu-label": "" }));
198
+ return _jsx("div", { ...rest, ref: forwardedRef, id: labelId, "data-context-menu-label": "" });
199
199
  });
200
200
  /** Non-focusable semantic menu separator. */
201
201
  export const ContextMenuSeparator = forwardRef(function ContextMenuSeparator(props, forwardedRef) {
@@ -203,5 +203,5 @@ export const ContextMenuSeparator = forwardRef(function ContextMenuSeparator(pro
203
203
  });
204
204
  /** Presentational keyboard hint. It does not register a shortcut. */
205
205
  export const ContextMenuShortcut = forwardRef(function ContextMenuShortcut(props, forwardedRef) {
206
- return (_jsx("span", { ...props, ref: forwardedRef, "aria-hidden": "true", "data-context-menu-shortcut": "" }));
206
+ return _jsx("span", { ...props, ref: forwardedRef, "aria-hidden": "true", "data-context-menu-shortcut": "" });
207
207
  });
@@ -1,6 +1,7 @@
1
1
  "use client";
2
- import { useCallback, useEffect, useMemo, } from "react";
3
- import { createTypeaheadBuffer, focusFirstMenuItem, focusLastMenuItem, focusMenuTypeahead, getActiveElement, moveMenuFocus, } from "../../vendor/core/index.js";
2
+ import { useCallback, useEffect, useMemo } from "react";
3
+ import { createTypeahead } from "@zealakit/ui-engine/keyboard";
4
+ import { focusFirstMenuItem, focusLastMenuItem, focusMenuItem, getActiveElement, getMenuItems, moveMenuFocus, } from "../../vendor/core/index.js";
4
5
  export function useMenuAutoFocus(container, enabled) {
5
6
  useEffect(() => {
6
7
  if (!enabled || !container) {
@@ -10,8 +11,20 @@ export function useMenuAutoFocus(container, enabled) {
10
11
  }, [container, enabled]);
11
12
  }
12
13
  export function useMenuNavigation(container, enabled) {
13
- const typeahead = useMemo(() => createTypeaheadBuffer(), []);
14
- useEffect(() => typeahead.clear, [typeahead]);
14
+ const typeahead = useMemo(() => createTypeahead({
15
+ items: () => (container === null ? [] : getMenuItems(container)),
16
+ getActiveIndex: () => {
17
+ if (container === null) {
18
+ return -1;
19
+ }
20
+ const active = getActiveElement(container.ownerDocument);
21
+ return active === null ? -1 : getMenuItems(container).indexOf(active);
22
+ },
23
+ onMatch: (item) => {
24
+ focusMenuItem(item);
25
+ },
26
+ }), [container]);
27
+ useEffect(() => () => typeahead.destroy(), [typeahead]);
15
28
  return useCallback((event) => {
16
29
  if (!enabled || !container || event.defaultPrevented) {
17
30
  return;
@@ -35,8 +48,11 @@ export function useMenuNavigation(container, enabled) {
35
48
  return;
36
49
  }
37
50
  if (event.key.length === 1 && event.key !== " ") {
38
- event.preventDefault();
39
- focusMenuTypeahead(container, typeahead.push(event.key), getActiveElement(container.ownerDocument));
51
+ // Engine typeahead: accent folding, repeated-character cycling, and the
52
+ // "start after the active item" rule are shared with every package.
53
+ if (typeahead.handleKeyDown(event.nativeEvent)) {
54
+ event.preventDefault();
55
+ }
40
56
  }
41
57
  }, [container, enabled, typeahead]);
42
58
  }
@@ -12,8 +12,8 @@ export type MenuSurfaceProps = HTMLAttributes<HTMLDivElement> & {
12
12
  offset?: number;
13
13
  alignOffset?: number;
14
14
  padding?: number;
15
- boundary?: PositionerBoundary;
16
- strategy?: Strategy;
15
+ boundary?: PositionerBoundary | undefined;
16
+ strategy?: Strategy | undefined;
17
17
  flip?: boolean;
18
18
  shift?: boolean;
19
19
  portal?: boolean | Element | null;
@@ -40,8 +40,8 @@ export declare const MenuSurface: import("react").ForwardRefExoticComponent<HTML
40
40
  offset?: number;
41
41
  alignOffset?: number;
42
42
  padding?: number;
43
- boundary?: PositionerBoundary;
44
- strategy?: Strategy;
43
+ boundary?: PositionerBoundary | undefined;
44
+ strategy?: Strategy | undefined;
45
45
  flip?: boolean;
46
46
  shift?: boolean;
47
47
  portal?: boolean | Element | null;
@@ -7,7 +7,7 @@ import { usePositioner } from "../../hooks/use-positioner.js";
7
7
  import { Portal } from "../portal.js";
8
8
  import { OverlayLayerContext, OverlayPortalContainerContext, } from "../overlay-context.js";
9
9
  import { composeRefs } from "../slot.js";
10
- import { useOverlayElementAnimation, useOverlayPresenceContext, } from "../../animation/presence.js";
10
+ import { useOverlayElementAnimation, useOverlayPresenceContext } from "../../animation/presence.js";
11
11
  import { useMenuAutoFocus, useMenuNavigation } from "./menu-navigation.js";
12
12
  export const MenuSurface = forwardRef(function MenuSurface({ children, reference, boundaryReference, focusRestoreTarget, menuId, labelledBy, placement, offset = 0, alignOffset = 0, padding = 0, boundary, strategy, flip = true, shift = true, portal = true, parentLayer, dir, submenu = false, open = true, onDismiss, onContextMenuOutside, onSubmenuKeyDown, onPointerEnterSurface, onPointerLeaveSurface, onKeyDown, onPointerEnter, onPointerLeave, ...rest }, forwardedRef) {
13
13
  const inheritedLayer = useContext(OverlayLayerContext);
@@ -28,14 +28,14 @@ export const MenuSurface = forwardRef(function MenuSurface({ children, reference
28
28
  });
29
29
  const positioner = usePositioner({
30
30
  reference,
31
- placement,
32
- offset,
33
- alignOffset,
34
- padding,
35
- boundary,
36
- strategy,
37
- flip,
38
- shift,
31
+ ...(placement === undefined ? {} : { placement }),
32
+ ...(offset === undefined ? {} : { offset }),
33
+ ...(alignOffset === undefined ? {} : { alignOffset }),
34
+ ...(padding === undefined ? {} : { padding }),
35
+ ...(boundary === undefined ? {} : { boundary }),
36
+ ...(strategy === undefined ? {} : { strategy }),
37
+ ...(flip === undefined ? {} : { flip }),
38
+ ...(shift === undefined ? {} : { shift }),
39
39
  autoUpdate: true,
40
40
  });
41
41
  const refs = useMemo(() => composeRefs(forwardedRef, setPopupElement, positioner.floatingRef), [forwardedRef, positioner.floatingRef]);
@@ -82,8 +82,7 @@ export const MenuSurface = forwardRef(function MenuSurface({ children, reference
82
82
  return () => {
83
83
  const documentRef = popupElement.ownerDocument;
84
84
  const active = getActiveElement(documentRef);
85
- const focusWasInside = focusInsideRef.current ||
86
- (active !== null && popupElement.contains(active));
85
+ const focusWasInside = focusInsideRef.current || (active !== null && popupElement.contains(active));
87
86
  focusInsideRef.current = false;
88
87
  if (!focusWasInside && active !== null && active !== documentRef.body) {
89
88
  return;
@@ -6,7 +6,7 @@ export type ContextMenuSubProps = {
6
6
  defaultOpen?: boolean;
7
7
  };
8
8
  /** Uncontrolled submenu state. It inherits direction and layer context. */
9
- export declare function ContextMenuSub({ children, defaultOpen, }: ContextMenuSubProps): import("react").JSX.Element;
9
+ export declare function ContextMenuSub({ children, defaultOpen }: ContextMenuSubProps): import("react").JSX.Element;
10
10
  export type ContextMenuSubTriggerProps = ComponentPropsWithoutRef<"div"> & ContextMenuDataAttributes & {
11
11
  asChild?: boolean;
12
12
  disabled?: boolean;
@@ -2,12 +2,12 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
4
4
  import { Slot, composeRefs } from "../slot.js";
5
- import { OverlayPresenceContext, useOverlayPresence, } from "../../animation/presence.js";
5
+ import { OverlayPresenceContext, useOverlayPresence } from "../../animation/presence.js";
6
6
  import { MenuSurface } from "./menu-surface.js";
7
7
  import { ContextMenuSubContext, useContextMenuContext, useContextMenuSubContext, } from "./context.js";
8
8
  const SUBMENU_CLOSE_DELAY = 100;
9
9
  /** Uncontrolled submenu state. It inherits direction and layer context. */
10
- export function ContextMenuSub({ children, defaultOpen = false, }) {
10
+ export function ContextMenuSub({ children, defaultOpen = false }) {
11
11
  const menu = useContextMenuContext("ContextMenuSub");
12
12
  const [isOpen, setIsOpen] = useState(defaultOpen);
13
13
  const [triggerElement, setTriggerElement] = useState(null);
@@ -62,17 +62,7 @@ export function ContextMenuSub({ children, defaultOpen = false, }) {
62
62
  toggle,
63
63
  scheduleClose,
64
64
  cancelClose,
65
- }), [
66
- cancelClose,
67
- close,
68
- id,
69
- isOpen,
70
- menu.direction,
71
- open,
72
- scheduleClose,
73
- toggle,
74
- triggerElement,
75
- ]);
65
+ }), [cancelClose, close, id, isOpen, menu.direction, open, scheduleClose, toggle, triggerElement]);
76
66
  return (_jsx(ContextMenuSubContext.Provider, { value: contextValue, children: children }));
77
67
  }
78
68
  export const ContextMenuSubTrigger = forwardRef(function ContextMenuSubTrigger({ asChild = false, disabled = false, onPointerEnter, onPointerLeave, onClick, onKeyDown, children, ...rest }, forwardedRef) {
@@ -48,7 +48,6 @@ export const ContextMenuTrigger = forwardRef(function ContextMenuTrigger({ asChi
48
48
  id: rest.id ?? menu.triggerId,
49
49
  tabIndex: tabIndex ?? 0,
50
50
  "aria-haspopup": "menu",
51
- "aria-expanded": menu.isOpen,
52
51
  "aria-controls": menu.isOpen ? menu.contentId : undefined,
53
52
  "data-state": menu.isOpen ? "open" : "closed",
54
53
  "data-context-menu-trigger": "",
@@ -4,7 +4,7 @@ export type DialogFocusTarget = "container" | "first" | Element | (() => Element
4
4
  export type DialogPortalProps = {
5
5
  children?: ReactNode;
6
6
  /** Defaults to document.body. */
7
- container?: Element | null;
7
+ container?: Element | null | undefined;
8
8
  /** Render in place without creating a dialog portal root. */
9
9
  disabled?: boolean;
10
10
  /** Keep portal DOM mounted while closed for consumer transitions. */
@@ -31,7 +31,7 @@ export type DialogPopupProps = HTMLAttributes<HTMLDivElement> & DialogDataAttrib
31
31
  /** Keep the popup mounted while closed for consumer transitions. */
32
32
  keepMounted?: boolean;
33
33
  /** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
34
- animation?: AnimationSetting;
34
+ animation?: AnimationSetting | undefined;
35
35
  };
36
36
  export type DialogContentProps = Omit<DialogPopupProps, "children"> & {
37
37
  children?: ReactNode;
@@ -72,7 +72,7 @@ export declare const DialogPopup: import("react").ForwardRefExoticComponent<HTML
72
72
  /** Keep the popup mounted while closed for consumer transitions. */
73
73
  keepMounted?: boolean;
74
74
  /** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
75
- animation?: AnimationSetting;
75
+ animation?: AnimationSetting | undefined;
76
76
  } & import("react").RefAttributes<HTMLDivElement>>;
77
77
  /**
78
78
  * Convenience composition: Portal -> optional Backdrop -> Viewport -> Popup.
@@ -74,6 +74,9 @@ export const DialogPopup = forwardRef(function DialogPopup({ children, initialFo
74
74
  const focusInsideRef = useRef(false);
75
75
  const initialFocusAppliedRef = useRef(false);
76
76
  const capturedFocusRef = useRef(null);
77
+ // Disposed by the close cleanup before focus is restored, so the trap cannot
78
+ // pull focus back into a dialog that is leaving (and then drop it to body).
79
+ const containmentRef = useRef(null);
77
80
  const triggerElementRef = useRef(dialog.triggerElement);
78
81
  const finalFocusRef = useRef(finalFocus);
79
82
  const restoreOnCloseRef = useRef(restoreOnClose);
@@ -100,10 +103,7 @@ export const DialogPopup = forwardRef(function DialogPopup({ children, initialFo
100
103
  });
101
104
  useModalBackground(portalRoot, dialog.isOpen && dialog.modal);
102
105
  useEffect(() => {
103
- if (!dialog.isOpen ||
104
- !dialog.modal ||
105
- !dialog.lockScroll ||
106
- !popupElement) {
106
+ if (!dialog.isOpen || !dialog.modal || !dialog.lockScroll || !popupElement) {
107
107
  return;
108
108
  }
109
109
  return lockBodyScroll(popupElement.ownerDocument);
@@ -134,13 +134,13 @@ export const DialogPopup = forwardRef(function DialogPopup({ children, initialFo
134
134
  return;
135
135
  }
136
136
  capturedFocusRef.current =
137
- triggerElementRef.current ??
138
- getActiveElement(popupElement.ownerDocument);
137
+ triggerElementRef.current ?? getActiveElement(popupElement.ownerDocument);
139
138
  return () => {
139
+ containmentRef.current?.dispose();
140
+ containmentRef.current = null;
140
141
  const documentRef = popupElement.ownerDocument;
141
142
  const active = getActiveElement(documentRef);
142
- const focusWasInside = focusInsideRef.current ||
143
- (active !== null && popupElement.contains(active));
143
+ const focusWasInside = focusInsideRef.current || (active !== null && popupElement.contains(active));
144
144
  focusInsideRef.current = false;
145
145
  if (!restoreOnCloseRef.current) {
146
146
  return;
@@ -182,13 +182,7 @@ export const DialogPopup = forwardRef(function DialogPopup({ children, initialFo
182
182
  else {
183
183
  focusElement(resolveTarget(requested));
184
184
  }
185
- }, [
186
- dialog.isOpen,
187
- dialog.modal,
188
- initialFocus,
189
- layer.isTopmost,
190
- popupElement,
191
- ]);
185
+ }, [dialog.isOpen, dialog.modal, initialFocus, layer.isTopmost, popupElement]);
192
186
  useEffect(() => {
193
187
  if (!dialog.isOpen) {
194
188
  initialFocusAppliedRef.current = false;
@@ -204,8 +198,12 @@ export const DialogPopup = forwardRef(function DialogPopup({ children, initialFo
204
198
  enabled: true,
205
199
  restoreFocus: false,
206
200
  });
201
+ containmentRef.current = containment;
207
202
  return () => {
208
203
  containment.dispose();
204
+ if (containmentRef.current === containment) {
205
+ containmentRef.current = null;
206
+ }
209
207
  };
210
208
  }, [dialog.modal, layer.isTopmost, popupElement]);
211
209
  const labelContext = useMemo(() => ({ setTitleId, setDescriptionId }), []);
@@ -84,5 +84,5 @@ export function Dialog({ children, open: controlledOpen, defaultOpen = false, on
84
84
  toggle,
85
85
  triggerElement,
86
86
  ]);
87
- return (_jsx(DialogContext.Provider, { value: contextValue, children: children }));
87
+ return _jsx(DialogContext.Provider, { value: contextValue, children: children });
88
88
  }
@@ -21,6 +21,7 @@ export const DialogTitle = forwardRef(function DialogTitle({ id, ...rest }, ref)
21
21
  setTitleId(null);
22
22
  };
23
23
  }, [setTitleId, titleId]);
24
+ // oxlint-disable-next-line jsx-a11y/heading-has-content -- content is supplied through the spread rest props
24
25
  return _jsx("h2", { ...rest, id: titleId, ref: ref });
25
26
  });
26
27
  /** Optional accessible description for the Dialog. */
@@ -2,4 +2,4 @@ export { Dialog, type DialogProps } from "./dialog.js";
2
2
  export { DialogTrigger, type DialogTriggerProps } from "./trigger.js";
3
3
  export { DialogBackdrop, DialogContent, DialogPopup, DialogPortal, DialogViewport, type DialogBackdropProps, type DialogContentProps, type DialogFocusTarget, type DialogPopupProps, type DialogPortalProps, type DialogViewportProps, } from "./content.js";
4
4
  export { DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogTitle, type DialogCloseProps, type DialogDescriptionProps, type DialogFooterProps, type DialogHeaderProps, type DialogTitleProps, } from "./helpers.js";
5
- export type { DialogChangeReason, DialogDirection, } from "./context.js";
5
+ export type { DialogChangeReason, DialogDirection } from "./context.js";
@@ -25,5 +25,7 @@ export const DialogTrigger = forwardRef(function DialogTrigger({ asChild = false
25
25
  if (asChild) {
26
26
  return (_jsx(Slot, { ...shared, ...(disabled ? { disabled: true, "aria-disabled": true } : {}), ref: refs, children: children }));
27
27
  }
28
+ // oxlint-disable react/button-has-type -- `type` is a literal union with a "button" fallback
28
29
  return (_jsx("button", { ...shared, ref: refs, type: type ?? "button", disabled: disabled, children: children }));
30
+ // oxlint-enable react/button-has-type
29
31
  });
@@ -4,45 +4,45 @@ export type PopoverSide = "top" | "right" | "bottom" | "left";
4
4
  export type PopoverAlign = "start" | "center" | "end";
5
5
  export type PopoverCollisionAvoidance = {
6
6
  /** Flip to the opposite side when there is not enough room. Defaults to true. */
7
- flip?: boolean;
7
+ flip?: boolean | undefined;
8
8
  /** Shift along the cross axis to stay inside the boundary. Defaults to true. */
9
- shift?: boolean;
9
+ shift?: boolean | undefined;
10
10
  };
11
11
  export type PopoverPositionerProps = {
12
- children?: ReactNode;
12
+ children?: ReactNode | undefined;
13
13
  /** Explicit positioning reference. Defaults to the trigger element. */
14
- anchor?: Element | null;
14
+ anchor?: Element | null | undefined;
15
15
  /** Physical side. Defaults to bottom. */
16
- side?: PopoverSide;
16
+ side?: PopoverSide | undefined;
17
17
  /** Alignment within the side. Defaults to center. */
18
- align?: PopoverAlign;
18
+ align?: PopoverAlign | undefined;
19
19
  /** Main-axis gap. */
20
- sideOffset?: number;
20
+ sideOffset?: number | undefined;
21
21
  /** Cross-axis offset. */
22
- alignOffset?: number;
22
+ alignOffset?: number | undefined;
23
23
  /** Core collision boundary. */
24
- collisionBoundary?: PositionerBoundary;
24
+ collisionBoundary?: PositionerBoundary | undefined;
25
25
  /** Gap from the collision boundary. */
26
- collisionPadding?: number;
26
+ collisionPadding?: number | undefined;
27
27
  /** Toggle flip/shift collision avoidance. Both default to true. */
28
- collisionAvoidance?: PopoverCollisionAvoidance;
28
+ collisionAvoidance?: PopoverCollisionAvoidance | undefined;
29
29
  /** CSS positioning method. Defaults to automatic: absolute (scrolls with the page), or fixed for fixed/sticky anchors and viewport points. */
30
- positionMethod?: Strategy;
30
+ positionMethod?: Strategy | undefined;
31
31
  /** Render a default arrow. Disabled by default. */
32
- arrow?: boolean;
32
+ arrow?: boolean | undefined;
33
33
  /** Default arrow edge length in pixels. Defaults to 8. */
34
- arrowSize?: number;
34
+ arrowSize?: number | undefined;
35
35
  /** Default arrow padding from popup edges. Defaults to 0. */
36
- arrowPadding?: number;
36
+ arrowPadding?: number | undefined;
37
37
  /** Default arrow class name. */
38
- arrowClassName?: string;
38
+ arrowClassName?: string | undefined;
39
39
  /** Default arrow inline style; merged over base geometry. */
40
- arrowStyle?: CSSProperties;
40
+ arrowStyle?: CSSProperties | undefined;
41
41
  };
42
42
  export type PopoverPortalProps = {
43
43
  children?: ReactNode;
44
44
  /** Defaults to document.body. */
45
- container?: Element | null;
45
+ container?: Element | null | undefined;
46
46
  /** Render in place instead of portaling. */
47
47
  disabled?: boolean;
48
48
  };
@@ -57,7 +57,7 @@ export type PopoverPopupProps = HTMLAttributes<HTMLDivElement> & PopoverDataAttr
57
57
  /** Restore focus to the trigger when closing from inside. Defaults to true. */
58
58
  restoreFocus?: boolean;
59
59
  /** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
60
- animation?: AnimationSetting;
60
+ animation?: AnimationSetting | undefined;
61
61
  };
62
62
  export type PopoverContentProps = Omit<PopoverPositionerProps, "children"> & PopoverPopupProps & {
63
63
  /**
@@ -71,8 +71,8 @@ export type PopoverArrowConfig = {
71
71
  shorthand: boolean;
72
72
  size: number;
73
73
  padding: number;
74
- className?: string;
75
- style?: CSSProperties;
74
+ className?: string | undefined;
75
+ style?: CSSProperties | undefined;
76
76
  };
77
77
  export type PopoverPositionerContextValue = {
78
78
  result: PositionerResult | null;
@@ -89,7 +89,7 @@ export declare function usePopoverPositionerContext(part: string): PopoverPositi
89
89
  * Portal part for advanced composition. The convenience Content uses it by
90
90
  * default. It renders nothing while the Popover is closed.
91
91
  */
92
- export declare function PopoverPortal({ children, container, disabled, }: PopoverPortalProps): import("react").JSX.Element | null;
92
+ export declare function PopoverPortal({ children, container, disabled }: PopoverPortalProps): import("react").JSX.Element | null;
93
93
  /**
94
94
  * Advanced positioning part. Renders no DOM; provides the positioner state to
95
95
  * PopoverPopup. Positioning props are consumed here and never reach the popup.
@@ -107,7 +107,7 @@ export declare const PopoverPopup: import("react").ForwardRefExoticComponent<HTM
107
107
  /** Restore focus to the trigger when closing from inside. Defaults to true. */
108
108
  restoreFocus?: boolean;
109
109
  /** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
110
- animation?: AnimationSetting;
110
+ animation?: AnimationSetting | undefined;
111
111
  } & import("react").RefAttributes<HTMLDivElement>>;
112
112
  /**
113
113
  * Convenience composition: Portal -> Positioner -> Popup. Positioning props are
@@ -121,7 +121,7 @@ export declare const PopoverContent: import("react").ForwardRefExoticComponent<O
121
121
  /** Restore focus to the trigger when closing from inside. Defaults to true. */
122
122
  restoreFocus?: boolean;
123
123
  /** Fade/custom enter and exit animation. Disabled by default; pass true or a config. */
124
- animation?: AnimationSetting;
124
+ animation?: AnimationSetting | undefined;
125
125
  } & {
126
126
  /**
127
127
  * `true`/omitted portals to document.body, an Element selects a container,
@@ -31,15 +31,13 @@ function toPopoverReason(reason) {
31
31
  }
32
32
  }
33
33
  function sameAnchorSize(previous, next) {
34
- return (previous !== null &&
35
- previous.width === next.width &&
36
- previous.height === next.height);
34
+ return previous !== null && previous.width === next.width && previous.height === next.height;
37
35
  }
38
36
  /**
39
37
  * Portal part for advanced composition. The convenience Content uses it by
40
38
  * default. It renders nothing while the Popover is closed.
41
39
  */
42
- export function PopoverPortal({ children, container, disabled = false, }) {
40
+ export function PopoverPortal({ children, container, disabled = false }) {
43
41
  const popover = usePopoverContext("PopoverPortal");
44
42
  const presence = useOverlayPresenceContext();
45
43
  const inheritedContainer = useContext(OverlayPortalContainerContext);
@@ -47,6 +45,7 @@ export function PopoverPortal({ children, container, disabled = false, }) {
47
45
  return null;
48
46
  }
49
47
  if (disabled) {
48
+ // oxlint-disable-next-line react/jsx-no-useless-fragment -- `children` may be a fragment-safe list
50
49
  return _jsx(_Fragment, { children: children });
51
50
  }
52
51
  const target = container === undefined ? inheritedContainer : container;
@@ -65,16 +64,14 @@ export function PopoverPositioner({ children, anchor, side = "bottom", align = "
65
64
  useEffect(() => {
66
65
  setActiveArrowPadding(arrowPadding);
67
66
  }, [arrowPadding]);
68
- const arrowOptions = useMemo(() => arrowElement
69
- ? { element: arrowElement, padding: activeArrowPadding }
70
- : null, [activeArrowPadding, arrowElement]);
71
- const { referenceRef, floatingRef, referenceElement, floatingElement, result, } = usePositioner({
72
- placement,
73
- offset: sideOffset,
74
- alignOffset,
75
- padding: collisionPadding,
76
- boundary: collisionBoundary,
77
- strategy: positionMethod,
67
+ const arrowOptions = useMemo(() => (arrowElement ? { element: arrowElement, padding: activeArrowPadding } : null), [activeArrowPadding, arrowElement]);
68
+ const { referenceRef, floatingRef, referenceElement, floatingElement, result } = usePositioner({
69
+ ...(placement === undefined ? {} : { placement }),
70
+ ...(sideOffset === undefined ? {} : { offset: sideOffset }),
71
+ ...(alignOffset === undefined ? {} : { alignOffset }),
72
+ ...(collisionPadding === undefined ? {} : { padding: collisionPadding }),
73
+ ...(collisionBoundary === undefined ? {} : { boundary: collisionBoundary }),
74
+ ...(positionMethod === undefined ? {} : { strategy: positionMethod }),
78
75
  flip: collisionAvoidance?.flip ?? true,
79
76
  shift: collisionAvoidance?.shift ?? true,
80
77
  arrow: arrowOptions,
@@ -185,8 +182,7 @@ export const PopoverPopup = forwardRef(function PopoverPopup({ children, initial
185
182
  }
186
183
  return () => {
187
184
  const active = getActiveElement();
188
- const focusWasInside = focusInsideRef.current ||
189
- (active !== null && popupElement.contains(active));
185
+ const focusWasInside = focusInsideRef.current || (active !== null && popupElement.contains(active));
190
186
  focusInsideRef.current = false;
191
187
  if (focusWasInside) {
192
188
  restoreFocus(triggerElementRef.current);
@@ -214,7 +210,7 @@ export const PopoverPopup = forwardRef(function PopoverPopup({ children, initial
214
210
  }
215
211
  const rect = reference.getBoundingClientRect();
216
212
  const next = { width: rect.width, height: rect.height };
217
- setAnchorSize((previous) => sameAnchorSize(previous, next) ? previous : next);
213
+ setAnchorSize((previous) => (sameAnchorSize(previous, next) ? previous : next));
218
214
  }, [positioner.referenceElement, positioner.result]);
219
215
  const labelContext = useMemo(() => ({ setTitleId, setDescriptionId }), []);
220
216
  const layerContext = useMemo(() => ({ handle: layer.handle, isTopmost: layer.isTopmost }), [layer.handle, layer.isTopmost]);
@@ -21,6 +21,7 @@ export const PopoverTitle = forwardRef(function PopoverTitle({ id, ...rest }, re
21
21
  setTitleId(null);
22
22
  };
23
23
  }, [setTitleId, titleId]);
24
+ // oxlint-disable-next-line jsx-a11y/heading-has-content -- content is supplied through the spread rest props
24
25
  return _jsx("h2", { ...rest, id: titleId, ref: ref });
25
26
  });
26
27
  /**
@@ -1,4 +1,4 @@
1
- export { Popover, PopoverTrigger, type PopoverProps, type PopoverTriggerProps, } from "./popover.js";
2
- export type { PopoverChangeReason, PopoverDirection, } from "./context.js";
1
+ export { Popover, PopoverTrigger, type PopoverProps, type PopoverTriggerProps } from "./popover.js";
2
+ export type { PopoverChangeReason, PopoverDirection } from "./context.js";
3
3
  export { PopoverContent, PopoverPopup, PopoverPortal, PopoverPositioner, type PopoverAlign, type PopoverArrowConfig, type PopoverCollisionAvoidance, type PopoverContentProps, type PopoverPopupProps, type PopoverPortalProps, type PopoverPositionerProps, type PopoverSide, } from "./content.js";
4
4
  export { PopoverClose, PopoverDescription, PopoverHeader, PopoverTitle, type PopoverCloseProps, type PopoverDescriptionProps, type PopoverHeaderProps, type PopoverTitleProps, } from "./helpers.js";
@@ -1,4 +1,4 @@
1
1
  "use client";
2
- export { Popover, PopoverTrigger, } from "./popover.js";
2
+ export { Popover, PopoverTrigger } from "./popover.js";
3
3
  export { PopoverContent, PopoverPopup, PopoverPortal, PopoverPositioner, } from "./content.js";
4
4
  export { PopoverClose, PopoverDescription, PopoverHeader, PopoverTitle, } from "./helpers.js";