@atlaskit/top-layer 0.12.0 → 0.12.2

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 (156) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/animations/presets.js +5 -5
  3. package/dist/cjs/dialog/create-close-event.js +1 -1
  4. package/dist/cjs/dialog/dialog-content.js +5 -5
  5. package/dist/cjs/entry-points/use-arrow-navigation.js +3 -2
  6. package/dist/cjs/internal/ensure-preset-styles.js +1 -1
  7. package/dist/cjs/internal/placement-to-position-area.js +43 -0
  8. package/dist/cjs/internal/placement-to-try-fallbacks.js +82 -0
  9. package/dist/cjs/internal/reduced-motion.js +1 -1
  10. package/dist/cjs/internal/resolve-placement.js +2 -2
  11. package/dist/cjs/internal/role-types.js +1 -1
  12. package/dist/cjs/internal/slot.js +3 -3
  13. package/dist/cjs/internal/use-anchor-position.js +33 -161
  14. package/dist/cjs/internal/use-animated-visibility.js +10 -10
  15. package/dist/cjs/internal/use-animation-preset.js +1 -1
  16. package/dist/cjs/internal/use-preset-styles.js +1 -1
  17. package/dist/cjs/internal/use-width-from-anchor.js +4 -4
  18. package/dist/cjs/popover/create-close-event.js +1 -1
  19. package/dist/cjs/popover/popover.js +3 -3
  20. package/dist/cjs/popup/popup-content.js +6 -6
  21. package/dist/cjs/popup/popup-context.js +2 -38
  22. package/dist/cjs/popup/popup-provider.js +15 -0
  23. package/dist/cjs/popup/popup-trigger-function.js +2 -2
  24. package/dist/cjs/popup/popup-trigger.js +2 -2
  25. package/dist/cjs/popup/popup.js +2 -2
  26. package/dist/cjs/popup/use-maybe-popup-context.js +17 -0
  27. package/dist/cjs/popup/use-popup-context.js +20 -0
  28. package/dist/cjs/testing/polyfill.js +8 -8
  29. package/dist/cjs/testing/to-be-visible.js +5 -5
  30. package/dist/cjs/use-arrow-navigation/index.js +3 -2
  31. package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +94 -0
  32. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +0 -82
  33. package/dist/cjs/use-simple-light-dismiss/index.js +3 -3
  34. package/dist/es2019/animations/presets.js +5 -5
  35. package/dist/es2019/dialog/create-close-event.js +1 -1
  36. package/dist/es2019/dialog/dialog-content.js +5 -5
  37. package/dist/es2019/entry-points/use-arrow-navigation.js +2 -1
  38. package/dist/es2019/internal/ensure-preset-styles.js +1 -1
  39. package/dist/es2019/internal/placement-to-position-area.js +40 -0
  40. package/dist/es2019/internal/placement-to-try-fallbacks.js +77 -0
  41. package/dist/es2019/internal/reduced-motion.js +1 -1
  42. package/dist/es2019/internal/resolve-placement.js +2 -2
  43. package/dist/es2019/internal/role-types.js +1 -1
  44. package/dist/es2019/internal/slot.js +3 -3
  45. package/dist/es2019/internal/use-anchor-position.js +15 -132
  46. package/dist/es2019/internal/use-animated-visibility.js +10 -10
  47. package/dist/es2019/internal/use-animation-preset.js +1 -1
  48. package/dist/es2019/internal/use-preset-styles.js +1 -1
  49. package/dist/es2019/internal/use-width-from-anchor.js +4 -4
  50. package/dist/es2019/popover/create-close-event.js +1 -1
  51. package/dist/es2019/popover/popover.js +3 -3
  52. package/dist/es2019/popup/popup-content.js +6 -5
  53. package/dist/es2019/popup/popup-context.js +2 -36
  54. package/dist/es2019/popup/popup-provider.js +10 -0
  55. package/dist/es2019/popup/popup-trigger-function.js +1 -1
  56. package/dist/es2019/popup/popup-trigger.js +2 -1
  57. package/dist/es2019/popup/popup.js +1 -1
  58. package/dist/es2019/popup/use-maybe-popup-context.js +12 -0
  59. package/dist/es2019/popup/use-popup-context.js +15 -0
  60. package/dist/es2019/testing/polyfill.js +8 -8
  61. package/dist/es2019/testing/to-be-visible.js +5 -5
  62. package/dist/es2019/use-arrow-navigation/index.js +2 -1
  63. package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +88 -0
  64. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +0 -81
  65. package/dist/es2019/use-simple-light-dismiss/index.js +3 -3
  66. package/dist/esm/animations/presets.js +5 -5
  67. package/dist/esm/dialog/create-close-event.js +1 -1
  68. package/dist/esm/dialog/dialog-content.js +5 -5
  69. package/dist/esm/entry-points/use-arrow-navigation.js +2 -1
  70. package/dist/esm/internal/ensure-preset-styles.js +1 -1
  71. package/dist/esm/internal/placement-to-position-area.js +38 -0
  72. package/dist/esm/internal/placement-to-try-fallbacks.js +76 -0
  73. package/dist/esm/internal/reduced-motion.js +1 -1
  74. package/dist/esm/internal/resolve-placement.js +2 -2
  75. package/dist/esm/internal/role-types.js +1 -1
  76. package/dist/esm/internal/slot.js +3 -3
  77. package/dist/esm/internal/use-anchor-position.js +31 -157
  78. package/dist/esm/internal/use-animated-visibility.js +10 -10
  79. package/dist/esm/internal/use-animation-preset.js +1 -1
  80. package/dist/esm/internal/use-preset-styles.js +1 -1
  81. package/dist/esm/internal/use-width-from-anchor.js +4 -4
  82. package/dist/esm/popover/create-close-event.js +1 -1
  83. package/dist/esm/popover/popover.js +3 -3
  84. package/dist/esm/popup/popup-content.js +6 -5
  85. package/dist/esm/popup/popup-context.js +2 -36
  86. package/dist/esm/popup/popup-provider.js +10 -0
  87. package/dist/esm/popup/popup-trigger-function.js +1 -1
  88. package/dist/esm/popup/popup-trigger.js +2 -1
  89. package/dist/esm/popup/popup.js +1 -1
  90. package/dist/esm/popup/use-maybe-popup-context.js +12 -0
  91. package/dist/esm/popup/use-popup-context.js +15 -0
  92. package/dist/esm/testing/polyfill.js +8 -8
  93. package/dist/esm/testing/to-be-visible.js +5 -5
  94. package/dist/esm/use-arrow-navigation/index.js +2 -1
  95. package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +88 -0
  96. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +0 -81
  97. package/dist/esm/use-simple-light-dismiss/index.js +3 -3
  98. package/dist/types/dialog/create-close-event.d.ts +1 -1
  99. package/dist/types/dialog/types.d.ts +8 -0
  100. package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -1
  101. package/dist/types/internal/placement-to-position-area.d.ts +21 -0
  102. package/dist/types/internal/placement-to-try-fallbacks.d.ts +36 -0
  103. package/dist/types/internal/reduced-motion.d.ts +1 -1
  104. package/dist/types/internal/resolve-placement.d.ts +2 -2
  105. package/dist/types/internal/slot.d.ts +4 -4
  106. package/dist/types/internal/use-anchor-position.d.ts +0 -55
  107. package/dist/types/internal/use-animated-visibility.d.ts +3 -3
  108. package/dist/types/internal/use-animation-preset.d.ts +1 -1
  109. package/dist/types/internal/use-preset-styles.d.ts +1 -1
  110. package/dist/types/internal/use-width-from-anchor.d.ts +2 -2
  111. package/dist/types/popover/create-close-event.d.ts +1 -1
  112. package/dist/types/popover/popover.d.ts +1 -1
  113. package/dist/types/popup/popup-context.d.ts +2 -22
  114. package/dist/types/popup/popup-provider.d.ts +10 -0
  115. package/dist/types/popup/use-maybe-popup-context.d.ts +8 -0
  116. package/dist/types/popup/use-popup-context.d.ts +7 -0
  117. package/dist/types/testing/to-be-visible.d.ts +3 -3
  118. package/dist/types/use-arrow-navigation/index.d.ts +2 -1
  119. package/dist/types/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  120. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  121. package/dist/types/use-simple-light-dismiss/index.d.ts +1 -1
  122. package/dist/types-ts4.5/dialog/create-close-event.d.ts +1 -1
  123. package/dist/types-ts4.5/dialog/types.d.ts +8 -0
  124. package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -1
  125. package/dist/types-ts4.5/internal/placement-to-position-area.d.ts +21 -0
  126. package/dist/types-ts4.5/internal/placement-to-try-fallbacks.d.ts +36 -0
  127. package/dist/types-ts4.5/internal/reduced-motion.d.ts +1 -1
  128. package/dist/types-ts4.5/internal/resolve-placement.d.ts +2 -2
  129. package/dist/types-ts4.5/internal/slot.d.ts +4 -4
  130. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +0 -55
  131. package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +3 -3
  132. package/dist/types-ts4.5/internal/use-animation-preset.d.ts +1 -1
  133. package/dist/types-ts4.5/internal/use-preset-styles.d.ts +1 -1
  134. package/dist/types-ts4.5/internal/use-width-from-anchor.d.ts +2 -2
  135. package/dist/types-ts4.5/popover/create-close-event.d.ts +1 -1
  136. package/dist/types-ts4.5/popover/popover.d.ts +1 -1
  137. package/dist/types-ts4.5/popup/popup-context.d.ts +2 -22
  138. package/dist/types-ts4.5/popup/popup-provider.d.ts +10 -0
  139. package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +8 -0
  140. package/dist/types-ts4.5/popup/use-popup-context.d.ts +7 -0
  141. package/dist/types-ts4.5/testing/to-be-visible.d.ts +3 -3
  142. package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -1
  143. package/dist/types-ts4.5/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  144. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  145. package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +1 -1
  146. package/package.json +2 -2
  147. package/dist/cjs/arrow/index.js +0 -131
  148. package/dist/cjs/arrow/types.js +0 -5
  149. package/dist/es2019/arrow/index.js +0 -269
  150. package/dist/es2019/arrow/types.js +0 -1
  151. package/dist/esm/arrow/index.js +0 -124
  152. package/dist/esm/arrow/types.js +0 -1
  153. package/dist/types/arrow/index.d.ts +0 -24
  154. package/dist/types/arrow/types.d.ts +0 -29
  155. package/dist/types-ts4.5/arrow/index.d.ts +0 -24
  156. package/dist/types-ts4.5/arrow/types.d.ts +0 -29
@@ -7,19 +7,19 @@ import { usePresetStyles } from './use-preset-styles';
7
7
  *
8
8
  * Used by both `Popover` and `Dialog` to share the same animation lifecycle
9
9
  * logic. Those components own their own show/hide mechanisms (showPopover /
10
- * hidePopover vs showModal / close) and event handling — this hook only
10
+ * hidePopover vs showModal / close) and event handling - this hook only
11
11
  * manages the relationship between `isOpen` and when children are rendered.
12
12
  *
13
13
  * ## Problem
14
14
  *
15
15
  * We want to delay the unmount of children until a CSS exit transition has
16
16
  * finished playing. If we unmount children the moment `isOpen` becomes
17
- * `false`, the exit animation is never visible — the content just disappears.
17
+ * `false`, the exit animation is never visible - the content just disappears.
18
18
  *
19
19
  * ## How it works
20
20
  *
21
21
  * `showChildren` tracks whether the consumer's children should be in the DOM.
22
- * It does not mirror `isOpen` exactly — it intentionally lags behind during
22
+ * It does not mirror `isOpen` exactly - it intentionally lags behind during
23
23
  * exit animations:
24
24
  *
25
25
  * ```
@@ -56,12 +56,12 @@ export function useAnimatedVisibility({
56
56
  // or the user has enabled the "prefers reduced motion" OS setting.
57
57
  const willAnimate = Boolean(animate) && !prefersReducedMotion();
58
58
 
59
- // ── showChildren state ──
59
+ // showChildren state
60
60
  //
61
61
  // This is the core of the hook. `showChildren` controls whether the
62
62
  // consumer's children are in the DOM. The two `if` blocks below are
63
63
  // intentionally written as synchronous state updates during render
64
- // (React supports this pattern — setState during render is treated as
64
+ // (React supports this pattern - setState during render is treated as
65
65
  // a synchronous re-render before the browser paints).
66
66
  //
67
67
  // Mount path: isOpen went true but showChildren is still false → mount.
@@ -85,7 +85,7 @@ export function useAnimatedVisibility({
85
85
  const onExitFinishRef = useRef(onExitFinish);
86
86
  onExitFinishRef.current = onExitFinish;
87
87
 
88
- // ── Animated entry effect ──
88
+ // Animated entry effect
89
89
  //
90
90
  // Fires `onEnterFinish` after the entry transition completes.
91
91
  // When there is no animation, fires it immediately via a separate effect.
@@ -134,7 +134,7 @@ export function useAnimatedVisibility({
134
134
  };
135
135
  }, [isOpen, showChildren, willAnimate, preset === null || preset === void 0 ? void 0 : preset.enterDurationMs, elementRef]);
136
136
 
137
- // ── Non-animated entry callback ──
137
+ // Non-animated entry callback
138
138
  //
139
139
  // When there is no animation, fire `onEnterFinish` immediately on mount and after `isOpen` goes false->true.
140
140
  // The initial value is false to make sure it fires on mount if the current `isOpen` is true.
@@ -148,7 +148,7 @@ export function useAnimatedVisibility({
148
148
  }
149
149
  }, [isOpen, willAnimate]);
150
150
 
151
- // ── Animated exit effect ──
151
+ // Animated exit effect
152
152
  //
153
153
  // Runs when all three conditions are true:
154
154
  // • `isOpen` is false (consumer wants to close)
@@ -211,10 +211,10 @@ export function useAnimatedVisibility({
211
211
  };
212
212
  }, [isOpen, showChildren, willAnimate, preset === null || preset === void 0 ? void 0 : preset.exitDurationMs, elementRef]);
213
213
 
214
- // ── Non-animated exit callback ──
214
+ // Non-animated exit callback
215
215
  //
216
216
  // When there is no animation, children unmount synchronously (handled
217
- // by the `if` block above). But `onExitFinish` still needs to fire —
217
+ // by the `if` block above). But `onExitFinish` still needs to fire -
218
218
  // we do that in a follow-up effect so the consumer can react to it.
219
219
  //
220
220
  // Uses a previous-value ref (`wasOpenRef`) to detect the exact
@@ -3,7 +3,7 @@ import { ensurePresetStyles } from './ensure-preset-styles';
3
3
  /**
4
4
  * Normalizes the `animate` prop to a preset (or null) and ensures its CSS
5
5
  * is injected once into document.head. Used by PopupContent, Popover, and
6
- * DialogContent so they don't duplicate this logic.
6
+ * DialogContent so they do not duplicate this logic.
7
7
  */
8
8
  export function useAnimationPreset(animate) {
9
9
  const preset = animate != null && animate !== false ? animate : null;
@@ -4,7 +4,7 @@ import { ensurePresetStyles } from './ensure-preset-styles';
4
4
  * Normalizes a preset prop to a value (or null) and ensures its CSS
5
5
  * is injected once into `document.head`.
6
6
  *
7
- * Works with any preset that has `{ css, name }` — animation presets
7
+ * Works with any preset that has `{ css, name }` - animation presets
8
8
  * (TAnimationPreset) satisfies this shape.
9
9
  */
10
10
  export function usePresetStyles({
@@ -4,8 +4,8 @@ import { setStyle } from './set-style';
4
4
  /**
5
5
  * Sets the width of a popover element relative to its anchor element.
6
6
  *
7
- * - `'match-anchor'` → `width: anchor-size(width)` — popover matches anchor width exactly.
8
- * - `'min-anchor'` → `min-width: anchor-size(width)` — popover is at least as wide as anchor,
7
+ * - `'match-anchor'` → `width: anchor-size(width)` - popover matches anchor width exactly.
8
+ * - `'min-anchor'` → `min-width: anchor-size(width)` - popover is at least as wide as anchor,
9
9
  * but can grow wider.
10
10
  * - `'none'` → no explicit width is set (default behaviour)
11
11
  *
@@ -31,7 +31,7 @@ export function useWidthFromAnchor({
31
31
  const supportsAnchorSize = typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('width', 'anchor-size(width)');
32
32
  if (mode === 'match-anchor') {
33
33
  // Set an exact width matching the anchor.
34
- // `min-inline-size` is intentionally NOT set here — it would override the
34
+ // `min-inline-size` is intentionally NOT set here - it would override the
35
35
  // explicit width constraint, allowing the popover to grow past the anchor's width.
36
36
  if (supportsAnchorSize) {
37
37
  return setStyle({
@@ -87,7 +87,7 @@ export function useWidthFromAnchor({
87
87
  });
88
88
  }
89
89
 
90
- // No anchor available in JS fallback — still apply min-inline-size.
90
+ // No anchor available in JS fallback - still apply min-inline-size.
91
91
  return setStyle({
92
92
  el: node,
93
93
  styles: [minInlineSizeStyle]
@@ -2,7 +2,7 @@
2
2
  * Creates a synthetic DOM event from a `TPopoverCloseReason`.
3
3
  *
4
4
  * Useful when bridging the Popover primitive's `onClose({ reason })` callback
5
- * to a legacy API that expects a native DOM event — for example,
5
+ * to a legacy API that expects a native DOM event - for example,
6
6
  * `@atlaskit/inline-dialog`'s `onClose(event)` contract.
7
7
  *
8
8
  * - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
@@ -45,7 +45,7 @@ const POPUP_ROLES = new Set(['menu', 'listbox', 'dialog', 'alertdialog', 'tree',
45
45
  * Unopinionated top-layer primitive.
46
46
  *
47
47
  * Manages only visibility (isOpen) and animation (animate). Has no knowledge
48
- * of positioning — compose with `useAnchorPosition` for anchor positioning
48
+ * of positioning - compose with `useAnchorPosition` for anchor positioning
49
49
  * and optionally `useWidthFromAnchor` for setting the width of a popover element
50
50
  * relative to its anchor trigger.
51
51
  *
@@ -96,7 +96,7 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
96
96
  onExitFinish
97
97
  });
98
98
 
99
- // ── Focus management ──
99
+ // Focus management
100
100
  // Initial focus: on open, moves focus into the popover (role-dependent).
101
101
  // Focus wrap: Tab/Shift+Tab cycle within the popover for dialog roles.
102
102
  // Focus restoration: handled natively by the Popover API. The browser
@@ -112,7 +112,7 @@ export const Popover = /*#__PURE__*/forwardRef(function Popover({
112
112
  role
113
113
  });
114
114
 
115
- // ── Open layer observer registration ──
115
+ // Open layer observer registration
116
116
  // Notifies the open layer observer so app-coordination features
117
117
  // (closeLayers(), open-count subscriptions) work with top-layer popovers.
118
118
  //
@@ -8,7 +8,8 @@ import { roleToAriaHasPopup, shouldFocusIntoPopover } from '../internal/role-typ
8
8
  import { useAnchorPosition } from '../internal/use-anchor-position';
9
9
  import { useWidthFromAnchor } from '../internal/use-width-from-anchor';
10
10
  import { Popover } from '../popover/popover';
11
- import { useMaybePopupContext } from './popup-context';
11
+ import { useMaybePopupContext } from './use-maybe-popup-context';
12
+
12
13
  /**
13
14
  * Thin context wrapper that composes `Popover` + `useAnchorPosition`.
14
15
  *
@@ -88,7 +89,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
88
89
  // Note: onOpenChange composition is handled by handleOpenChange below,
89
90
  // which also adds nested-popover focus restoration.
90
91
 
91
- // ── Sync aria-haspopup on the trigger with the content's role ──
92
+ // Sync aria-haspopup on the trigger with the content's role
92
93
  const setAriaHasPopup = ctx === null || ctx === void 0 ? void 0 : ctx.setAriaHasPopup;
93
94
  useLayoutEffect(() => {
94
95
  setAriaHasPopup === null || setAriaHasPopup === void 0 ? void 0 : setAriaHasPopup(roleToAriaHasPopup({
@@ -96,7 +97,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
96
97
  }));
97
98
  }, [role, setAriaHasPopup]);
98
99
 
99
- // ── Focus restoration ──
100
+ // Focus restoration
100
101
  // The native Popover API handles focus restoration automatically for
101
102
  // popover="auto" and popover="hint":
102
103
  // - Escape → restores focus to the previously focused element (the trigger)
@@ -123,7 +124,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
123
124
  }
124
125
  consumerOnOpenChange === null || consumerOnOpenChange === void 0 ? void 0 : consumerOnOpenChange(args);
125
126
 
126
- // ── Nested popover focus restoration fallback ──
127
+ // Nested popover focus restoration fallback
127
128
  // The browser only captures `previouslyFocusedElement` for the
128
129
  // outermost popover="auto" in the stack. Inner (nested) popovers
129
130
  // have shouldRestoreFocus=false, so the browser will not restore
@@ -152,7 +153,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
152
153
  }
153
154
  }, [consumerOnOpenChange, triggerRef, role, setPopupState, willAnimate]);
154
155
 
155
- // ── Anchor positioning ──
156
+ // Anchor positioning
156
157
  // Compose useAnchorPosition with Popover. The hook positions the popover
157
158
  // relative to the trigger element via CSS Anchor Positioning (with JS fallback).
158
159
  // Use ctx.popoverRef when inside the compound (so the trigger can also
@@ -1,4 +1,4 @@
1
- import { createContext, useContext } from 'react';
1
+ import { createContext } from 'react';
2
2
 
3
3
  /**
4
4
  * Represents the lifecycle state of the popup.
@@ -17,38 +17,4 @@ import { createContext, useContext } from 'react';
17
17
  * the trigger (and thus the popup anchor) mid-animation.
18
18
  */
19
19
 
20
- const PopupContext = /*#__PURE__*/createContext(null);
21
-
22
- /**
23
- * __Popup provider__
24
- *
25
- * Provides shared popup state (placement, popoverId, triggerRef,
26
- * isOpen, onClose) to compound child components such as `Popup.Trigger` and
27
- * `Popup.Content`.
28
- */
29
- export const PopupProvider = PopupContext.Provider;
30
-
31
- /**
32
- * Returns the nearest `Popup` context value.
33
- *
34
- * Throws if called outside of a `<Popup>` compound component.
35
- */
36
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
37
- export function usePopupContext() {
38
- const ctx = useContext(PopupContext);
39
- if (ctx === null) {
40
- throw new Error('@atlaskit/top-layer: Popup compound components must be used within <Popup>.');
41
- }
42
- return ctx;
43
- }
44
-
45
- /**
46
- * Returns the popup context if available, or `null` when used outside `<Popup>`.
47
- *
48
- * Used by `PopupContent` to support standalone usage (e.g. tooltip)
49
- * where values are passed as props instead of coming from a compound component.
50
- */
51
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
52
- export function useMaybePopupContext() {
53
- return useContext(PopupContext);
54
- }
20
+ export const PopupContext = /*#__PURE__*/createContext(null);
@@ -0,0 +1,10 @@
1
+ import { PopupContext } from './popup-context';
2
+
3
+ /**
4
+ * __Popup provider__
5
+ *
6
+ * Provides shared popup state (placement, popoverId, triggerRef,
7
+ * isOpen, onClose) to compound child components such as `Popup.Trigger` and
8
+ * `Popup.Content`.
9
+ */
10
+ export const PopupProvider = PopupContext.Provider;
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useMemo } from 'react';
2
- import { usePopupContext } from './popup-context';
2
+ import { usePopupContext } from './use-popup-context';
3
3
 
4
4
  /**
5
5
  * Props passed to the `TriggerFunction` render-prop child.
@@ -1,6 +1,7 @@
1
1
  import React, { isValidElement, useCallback } from 'react';
2
2
  import { Slot } from '../internal/slot';
3
- import { usePopupContext } from './popup-context';
3
+ import { usePopupContext } from './use-popup-context';
4
+
4
5
  /**
5
6
  * Wraps a single trigger element via `cloneElement`. Attaches aria
6
7
  * attributes, the toggle handler, and the anchor-name. `aria-haspopup`
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useId, useRef, useState } from 'react';
2
- import { PopupProvider } from './popup-context';
2
+ import { PopupProvider } from './popup-provider';
3
3
  /**
4
4
  * Popup compound: trigger + popover content.
5
5
  *
@@ -0,0 +1,12 @@
1
+ import { useContext } from 'react';
2
+ import { PopupContext } from './popup-context';
3
+
4
+ /**
5
+ * Returns the popup context if available, or `null` when used outside `<Popup>`.
6
+ *
7
+ * Used by `PopupContent` to support standalone usage (e.g. tooltip)
8
+ * where values are passed as props instead of coming from a compound component.
9
+ */
10
+ export function useMaybePopupContext() {
11
+ return useContext(PopupContext);
12
+ }
@@ -0,0 +1,15 @@
1
+ import { useContext } from 'react';
2
+ import { PopupContext } from './popup-context';
3
+
4
+ /**
5
+ * Returns the nearest `Popup` context value.
6
+ *
7
+ * Throws if called outside of a `<Popup>` compound component.
8
+ */
9
+ export function usePopupContext() {
10
+ const ctx = useContext(PopupContext);
11
+ if (ctx === null) {
12
+ throw new Error('@atlaskit/top-layer: Popup compound components must be used within <Popup>.');
13
+ }
14
+ return ctx;
15
+ }
@@ -107,7 +107,7 @@ function createToggleScheduler() {
107
107
  newState
108
108
  });
109
109
 
110
- // Task queue (setTimeout) — browser fires toggle after microtasks drain, not during
110
+ // Task queue (setTimeout) - browser fires toggle after microtasks drain, not during
111
111
  setTimeout(() => {
112
112
  const entry = pending.get(element);
113
113
  if (!entry) {
@@ -178,7 +178,7 @@ function createDialogToggleScheduler() {
178
178
  };
179
179
  }
180
180
 
181
- // ─── Popover API ────────────────────────────────────────────────────────────
181
+ // Popover API
182
182
  // Spec: https://html.spec.whatwg.org/multipage/popover.html
183
183
 
184
184
  // `popover` attribute valid values. Empty / "auto" -> "auto"; unknown -> "manual".
@@ -555,7 +555,7 @@ if (typeof HTMLElement !== 'undefined') {
555
555
  if (isPopoverOpen({
556
556
  element: this
557
557
  })) {
558
- return; // already showing — no-op
558
+ return; // already showing - no-op
559
559
  }
560
560
 
561
561
  // sync, cancelable on show only
@@ -731,7 +731,7 @@ if (typeof HTMLElement !== 'undefined') {
731
731
  }
732
732
  }
733
733
 
734
- // ─── HTMLDialogElement ──────────────────────────────────────────────────────
734
+ // HTMLDialogElement
735
735
  // Spec: https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element
736
736
 
737
737
  if (typeof HTMLDialogElement !== 'undefined') {
@@ -746,7 +746,7 @@ if (typeof HTMLDialogElement !== 'undefined') {
746
746
  }
747
747
  if (this.hasAttribute('open')) {
748
748
  if (this._isModal) {
749
- return; // already modal — no-op
749
+ return; // already modal - no-op
750
750
  }
751
751
  throw new DOMException(`Failed to execute 'showModal' on 'HTMLDialogElement': ${describeElement({
752
752
  element: this
@@ -770,7 +770,7 @@ if (typeof HTMLDialogElement !== 'undefined') {
770
770
  }
771
771
  if (typeof proto.show !== 'function') {
772
772
  proto.show = function show() {
773
- // Browser does not throw for disconnected elements on show — just no-op
773
+ // Browser does not throw for disconnected elements on show - just no-op
774
774
  if (!this.isConnected || this.hasAttribute('open')) {
775
775
  return;
776
776
  }
@@ -793,10 +793,10 @@ if (typeof HTMLDialogElement !== 'undefined') {
793
793
  if (typeof proto.close !== 'function') {
794
794
  proto.close = function close(returnValue) {
795
795
  if (!this.hasAttribute('open')) {
796
- return; // already closed — no-op
796
+ return; // already closed - no-op
797
797
  }
798
798
 
799
- // Sync beforetoggle (not cancelable) — matches browser behavior
799
+ // Sync beforetoggle (not cancelable) - matches browser behavior
800
800
  fireToggleEvent({
801
801
  element: this,
802
802
  type: 'beforetoggle',
@@ -5,13 +5,13 @@
5
5
  *
6
6
  * jest-dom's `toBeVisible()` does not know about the Popover API. In real
7
7
  * browsers the UA stylesheet hides `[popover]` with `display: none`, but
8
- * jsdom has no such stylesheet — so closed popovers incorrectly appear visible.
8
+ * jsdom has no such stylesheet - so closed popovers incorrectly appear visible.
9
9
  *
10
10
  * Raw jest-dom results in jsdom:
11
11
  *
12
- * closed popover / child → true (WRONG — should be false)
12
+ * closed popover / child → true (WRONG - should be false)
13
13
  * open popover / child → true (correct)
14
- * closed dialog / child → false (correct — jsdom natively hides <dialog>)
14
+ * closed dialog / child → false (correct - jsdom natively hides <dialog>)
15
15
  * open dialog / child → true (correct)
16
16
  *
17
17
  * We correct both false positives and false negatives:
@@ -62,7 +62,7 @@ expect.extend({
62
62
  const originalResult = originalToBeVisible.call(this, element);
63
63
  const topLayerState = nearestTopLayerState(element);
64
64
  if (originalResult.pass) {
65
- // Original says visible — override if nearest top-layer host is closed.
65
+ // Original says visible - override if nearest top-layer host is closed.
66
66
  if (topLayerState === 'closed') {
67
67
  return {
68
68
  pass: false,
@@ -72,7 +72,7 @@ expect.extend({
72
72
  return originalResult;
73
73
  }
74
74
 
75
- // Original says not visible — override if nearest top-layer host is open.
75
+ // Original says not visible - override if nearest top-layer host is open.
76
76
  // jsdom may hide [popover] elements even when they are logically open.
77
77
  if (topLayerState === 'open') {
78
78
  return {
@@ -1 +1,2 @@
1
- export { useArrowNavigation, isAtCurrentMenuLevel } from './use-arrow-navigation';
1
+ export { useArrowNavigation } from './use-arrow-navigation';
2
+ export { isAtCurrentMenuLevel } from './is-at-current-menu-level';
@@ -0,0 +1,88 @@
1
+ const menuScope = '[role="menu"]';
2
+
3
+ /**
4
+ * Recursively walks from `node` toward `container`, returning `true` when
5
+ * `container` is reached without crossing another `role="menu"` ancestor.
6
+ *
7
+ * Used by `isAtCurrentMenuLevel` (pattern 2) to determine if the
8
+ * `closestMenu` is owned by the wrapper container directly. Recursion
9
+ * avoids a mutable `let parent` walk and keeps the function body linear.
10
+ */
11
+ function reachesContainerWithoutNestedMenu(node, container) {
12
+ if (!node || node === container) {
13
+ return node === container;
14
+ }
15
+ if (node.getAttribute('role') === 'menu') {
16
+ return false;
17
+ }
18
+ return reachesContainerWithoutNestedMenu(node.parentElement, container);
19
+ }
20
+
21
+ /**
22
+ * Returns true if the element belongs to the current menu level of the
23
+ * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
24
+ *
25
+ * Uses `element.closest('[role="menu"]')` to determine the nearest menu
26
+ * scope. If the nearest scope is the container's own `role="menu"` element,
27
+ * the element belongs to this level. If it is a different (nested) menu,
28
+ * the element belongs to a child level and should be excluded.
29
+ *
30
+ * Supports two container patterns:
31
+ *
32
+ * **1. Container has `role="menu"` directly** (preferred, used by avatar-group):
33
+ * ```
34
+ * <div ref={containerRef} role="menu">
35
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
36
+ * <div role="menu"> ← nested sub-menu
37
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
38
+ * </div>
39
+ * </div>
40
+ * ```
41
+ * Uses the simple check: `element.closest('[role="menu"]') === container`
42
+ *
43
+ * **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
44
+ * where `MenuGroup` owns `role="menu"` but does not accept a ref):
45
+ * ```
46
+ * <div ref={containerRef}> ← wrapper (no role="menu")
47
+ * <MenuGroup role="menu">
48
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
49
+ * <div role="menu"> ← nested sub-menu
50
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
51
+ * </div>
52
+ * </MenuGroup>
53
+ * </div>
54
+ * ```
55
+ * Falls back to walking the DOM to check that the element's closest
56
+ * `role="menu"` is the container's own menu (not doubly nested).
57
+ *
58
+ * Ideally all consumers should use pattern 1 (place the ref directly on the
59
+ * `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
60
+ * `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
61
+ * support in the future, dropdown-menu should switch to pattern 1 and the
62
+ * fallback path can be removed.
63
+ *
64
+ * Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
65
+ * a guard to prevent parent menu handlers from acting on events that
66
+ * belong to a nested menu.
67
+ */
68
+ export function isAtCurrentMenuLevel(element, container) {
69
+ const closestMenu = element.closest(menuScope);
70
+
71
+ // Container itself has role="menu". Element belongs to this level
72
+ // if its closest menu is the container.
73
+ if (container.getAttribute('role') === 'menu') {
74
+ return closestMenu === container;
75
+ }
76
+
77
+ // Container is a wrapper without role="menu" (e.g. dropdown-menu
78
+ // wraps a MenuGroup). The element belongs to the top level if its
79
+ // closest role="menu" ancestor is a direct child of the container,
80
+ // i.e. there is no nested role="menu" between them.
81
+ if (closestMenu === null) {
82
+ return true;
83
+ }
84
+
85
+ // Walk up from the closest menu to see if it is "owned" by this
86
+ // container without passing through another role="menu" first.
87
+ return reachesContainerWithoutNestedMenu(closestMenu.parentElement, container);
88
+ }
@@ -5,86 +5,6 @@ import { KEY_DOWN, KEY_END, KEY_HOME, KEY_TAB, KEY_UP } from '@atlaskit/ds-lib/k
5
5
  import { getFirstFocusable, getLastFocusable, getNextFocusable } from '../focus';
6
6
  const menuScope = '[role="menu"]';
7
7
 
8
- /**
9
- * Returns true if the element belongs to the current menu level of the
10
- * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
11
- *
12
- * Uses `element.closest('[role="menu"]')` to determine the nearest menu
13
- * scope. If the nearest scope is the container's own `role="menu"` element,
14
- * the element belongs to this level. If it is a different (nested) menu,
15
- * the element belongs to a child level and should be excluded.
16
- *
17
- * Supports two container patterns:
18
- *
19
- * **1. Container has `role="menu"` directly** (preferred, used by avatar-group):
20
- * ```
21
- * <div ref={containerRef} role="menu">
22
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
23
- * <div role="menu"> ← nested sub-menu
24
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
25
- * </div>
26
- * </div>
27
- * ```
28
- * Uses the simple check: `element.closest('[role="menu"]') === container`
29
- *
30
- * **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
31
- * where `MenuGroup` owns `role="menu"` but does not accept a ref):
32
- * ```
33
- * <div ref={containerRef}> ← wrapper (no role="menu")
34
- * <MenuGroup role="menu">
35
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
36
- * <div role="menu"> ← nested sub-menu
37
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
38
- * </div>
39
- * </MenuGroup>
40
- * </div>
41
- * ```
42
- * Falls back to walking the DOM to check that the element's closest
43
- * `role="menu"` is the container's own menu (not doubly nested).
44
- *
45
- * Ideally all consumers should use pattern 1 (place the ref directly on the
46
- * `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
47
- * `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
48
- * support in the future, dropdown-menu should switch to pattern 1 and the
49
- * fallback path can be removed.
50
- *
51
- * Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
52
- * a guard to prevent parent menu handlers from acting on events that
53
- * belong to a nested menu.
54
- */
55
- export function isAtCurrentMenuLevel(element, container) {
56
- const closestMenu = element.closest(menuScope);
57
-
58
- // Container itself has role="menu". Element belongs to this level
59
- // if its closest menu is the container.
60
- if (container.getAttribute('role') === 'menu') {
61
- return closestMenu === container;
62
- }
63
-
64
- // Container is a wrapper without role="menu" (e.g. dropdown-menu
65
- // wraps a MenuGroup). The element belongs to the top level if its
66
- // closest role="menu" ancestor is a direct child of the container,
67
- // i.e. there is no nested role="menu" between them.
68
- if (closestMenu === null) {
69
- return true;
70
- }
71
-
72
- // Walk up from the closest menu to see if it is "owned" by this
73
- // container without passing through another role="menu" first.
74
- let parent = closestMenu.parentElement;
75
- while (parent && parent !== container) {
76
- if (parent.getAttribute('role') === 'menu') {
77
- // There is a parent menu between the closest menu and the
78
- // container, so the element is in a nested sub-menu.
79
- return false;
80
- }
81
- parent = parent.parentElement;
82
- }
83
-
84
- // The closest menu is directly inside the container (no nesting).
85
- return parent === container;
86
- }
87
-
88
8
  /**
89
9
  * Args for `useArrowNavigation`.
90
10
  *
@@ -135,7 +55,6 @@ export function isAtCurrentMenuLevel(element, container) {
135
55
  * });
136
56
  * ```
137
57
  */
138
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
139
58
  export function useArrowNavigation({
140
59
  containerRef,
141
60
  onClose,
@@ -9,7 +9,7 @@ import { bind } from 'bind-event-listener';
9
9
  * **No stacking awareness:** This hook does not track a popover stack.
10
10
  * If multiple manual popovers are open and all use this hook, a single
11
11
  * Escape press or outside click will dismiss **all of them simultaneously**.
12
- * This is by design — the hook is intentionally simple for cases where
12
+ * This is by design - the hook is intentionally simple for cases where
13
13
  * only one manual popover is open at a time.
14
14
  *
15
15
  * For stacked/nested popovers that should dismiss one-at-a-time, use
@@ -47,7 +47,7 @@ export function useSimpleLightDismiss({
47
47
  // (trigger onClick → setIsOpen(true) → React render → useEffect).
48
48
  // By the time this effect runs, the opening click has finished
49
49
  // bubbling. A capture-phase listener added now cannot retroactively
50
- // fire for that event — it only fires for *future* clicks.
50
+ // fire for that event - it only fires for *future* clicks.
51
51
  //
52
52
  // This avoids the need for timestamp guards or deferred binding.
53
53
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage -- binding to document for light dismiss
@@ -59,7 +59,7 @@ export function useSimpleLightDismiss({
59
59
  return;
60
60
  }
61
61
 
62
- // If the click target is inside the popover, don't dismiss.
62
+ // If the click target is inside the popover, do not dismiss.
63
63
  if (event.target instanceof Node && el.contains(event.target)) {
64
64
  return;
65
65
  }