@atlaskit/top-layer 0.12.1 → 0.13.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 (196) hide show
  1. package/CHANGELOG.md +23 -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/focus.js +6 -4
  6. package/dist/cjs/entry-points/use-anchor-position-at-point.js +12 -0
  7. package/dist/cjs/focus/get-first-focusable.js +19 -0
  8. package/dist/cjs/focus/get-focusables.js +30 -0
  9. package/dist/cjs/focus/get-last-focusable.js +19 -0
  10. package/dist/cjs/focus/get-next-focusable.js +43 -0
  11. package/dist/cjs/focus/is-in-same-layer.js +23 -0
  12. package/dist/cjs/focus/is-nested-layer-focused.js +32 -0
  13. package/dist/cjs/focus/selectors.js +19 -0
  14. package/dist/cjs/focus/types.js +1 -0
  15. package/dist/cjs/internal/ensure-preset-styles.js +1 -1
  16. package/dist/cjs/internal/reduced-motion.js +1 -1
  17. package/dist/cjs/internal/resolve-placement.js +2 -2
  18. package/dist/cjs/internal/role-to-aria-has-popup.js +37 -0
  19. package/dist/cjs/internal/role-types.js +1 -97
  20. package/dist/cjs/internal/should-focus-into-popover.js +19 -0
  21. package/dist/cjs/internal/slot.js +3 -3
  22. package/dist/cjs/internal/use-anchor-position-at-point.js +127 -0
  23. package/dist/cjs/internal/use-anchor-position.js +22 -33
  24. package/dist/cjs/internal/use-animated-visibility.js +10 -10
  25. package/dist/cjs/internal/use-animation-preset.js +1 -1
  26. package/dist/cjs/internal/use-focus-wrap.js +8 -5
  27. package/dist/cjs/internal/use-initial-focus.js +4 -4
  28. package/dist/cjs/internal/use-preset-styles.js +1 -1
  29. package/dist/cjs/internal/use-width-from-anchor.js +4 -4
  30. package/dist/cjs/placement-map/index.js +2 -2
  31. package/dist/cjs/placement-map/legacy-placements.js +2 -101
  32. package/dist/cjs/placement-map/placement-mapping.js +103 -0
  33. package/dist/cjs/popover/create-close-event.js +1 -1
  34. package/dist/cjs/popover/popover.js +3 -3
  35. package/dist/cjs/popup/popup-content.js +8 -7
  36. package/dist/cjs/testing/polyfill.js +8 -8
  37. package/dist/cjs/testing/to-be-visible.js +5 -5
  38. package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +19 -12
  39. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +7 -5
  40. package/dist/cjs/use-simple-light-dismiss/index.js +3 -3
  41. package/dist/es2019/animations/presets.js +5 -5
  42. package/dist/es2019/dialog/create-close-event.js +1 -1
  43. package/dist/es2019/dialog/dialog-content.js +5 -5
  44. package/dist/es2019/entry-points/focus.js +3 -1
  45. package/dist/es2019/entry-points/use-anchor-position-at-point.js +1 -0
  46. package/dist/es2019/focus/get-first-focusable.js +14 -0
  47. package/dist/es2019/focus/get-focusables.js +19 -0
  48. package/dist/es2019/focus/get-last-focusable.js +14 -0
  49. package/dist/es2019/focus/get-next-focusable.js +38 -0
  50. package/dist/es2019/focus/is-in-same-layer.js +18 -0
  51. package/dist/es2019/focus/is-nested-layer-focused.js +28 -0
  52. package/dist/es2019/focus/selectors.js +11 -0
  53. package/dist/es2019/focus/types.js +0 -0
  54. package/dist/es2019/internal/ensure-preset-styles.js +1 -1
  55. package/dist/es2019/internal/reduced-motion.js +1 -1
  56. package/dist/es2019/internal/resolve-placement.js +2 -2
  57. package/dist/es2019/internal/role-to-aria-has-popup.js +32 -0
  58. package/dist/es2019/internal/role-types.js +0 -92
  59. package/dist/es2019/internal/should-focus-into-popover.js +14 -0
  60. package/dist/es2019/internal/slot.js +3 -3
  61. package/dist/es2019/internal/use-anchor-position-at-point.js +122 -0
  62. package/dist/es2019/internal/use-anchor-position.js +19 -19
  63. package/dist/es2019/internal/use-animated-visibility.js +10 -10
  64. package/dist/es2019/internal/use-animation-preset.js +1 -1
  65. package/dist/es2019/internal/use-focus-wrap.js +4 -1
  66. package/dist/es2019/internal/use-initial-focus.js +1 -1
  67. package/dist/es2019/internal/use-preset-styles.js +1 -1
  68. package/dist/es2019/internal/use-width-from-anchor.js +4 -4
  69. package/dist/es2019/placement-map/index.js +1 -1
  70. package/dist/es2019/placement-map/legacy-placements.js +1 -100
  71. package/dist/es2019/placement-map/placement-mapping.js +97 -0
  72. package/dist/es2019/popover/create-close-event.js +1 -1
  73. package/dist/es2019/popover/popover.js +3 -3
  74. package/dist/es2019/popup/popup-content.js +6 -5
  75. package/dist/es2019/testing/polyfill.js +8 -8
  76. package/dist/es2019/testing/to-be-visible.js +5 -5
  77. package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +19 -12
  78. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +3 -1
  79. package/dist/es2019/use-simple-light-dismiss/index.js +3 -3
  80. package/dist/esm/animations/presets.js +5 -5
  81. package/dist/esm/dialog/create-close-event.js +1 -1
  82. package/dist/esm/dialog/dialog-content.js +5 -5
  83. package/dist/esm/entry-points/focus.js +3 -1
  84. package/dist/esm/entry-points/use-anchor-position-at-point.js +1 -0
  85. package/dist/esm/focus/get-first-focusable.js +13 -0
  86. package/dist/esm/focus/get-focusables.js +24 -0
  87. package/dist/esm/focus/get-last-focusable.js +13 -0
  88. package/dist/esm/focus/get-next-focusable.js +37 -0
  89. package/dist/esm/focus/is-in-same-layer.js +17 -0
  90. package/dist/esm/focus/is-nested-layer-focused.js +27 -0
  91. package/dist/esm/focus/selectors.js +13 -0
  92. package/dist/esm/focus/types.js +0 -0
  93. package/dist/esm/internal/ensure-preset-styles.js +1 -1
  94. package/dist/esm/internal/reduced-motion.js +1 -1
  95. package/dist/esm/internal/resolve-placement.js +2 -2
  96. package/dist/esm/internal/role-to-aria-has-popup.js +31 -0
  97. package/dist/esm/internal/role-types.js +0 -90
  98. package/dist/esm/internal/should-focus-into-popover.js +13 -0
  99. package/dist/esm/internal/slot.js +3 -3
  100. package/dist/esm/internal/use-anchor-position-at-point.js +122 -0
  101. package/dist/esm/internal/use-anchor-position.js +22 -33
  102. package/dist/esm/internal/use-animated-visibility.js +10 -10
  103. package/dist/esm/internal/use-animation-preset.js +1 -1
  104. package/dist/esm/internal/use-focus-wrap.js +4 -1
  105. package/dist/esm/internal/use-initial-focus.js +1 -1
  106. package/dist/esm/internal/use-preset-styles.js +1 -1
  107. package/dist/esm/internal/use-width-from-anchor.js +4 -4
  108. package/dist/esm/placement-map/index.js +1 -1
  109. package/dist/esm/placement-map/legacy-placements.js +1 -100
  110. package/dist/esm/placement-map/placement-mapping.js +97 -0
  111. package/dist/esm/popover/create-close-event.js +1 -1
  112. package/dist/esm/popover/popover.js +3 -3
  113. package/dist/esm/popup/popup-content.js +6 -5
  114. package/dist/esm/testing/polyfill.js +8 -8
  115. package/dist/esm/testing/to-be-visible.js +5 -5
  116. package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +19 -12
  117. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +3 -1
  118. package/dist/esm/use-simple-light-dismiss/index.js +3 -3
  119. package/dist/types/dialog/create-close-event.d.ts +1 -1
  120. package/dist/types/dialog/types.d.ts +8 -0
  121. package/dist/types/entry-points/focus.d.ts +4 -2
  122. package/dist/types/entry-points/use-anchor-position-at-point.d.ts +1 -0
  123. package/dist/types/focus/get-first-focusable.d.ts +8 -0
  124. package/dist/types/focus/get-focusables.d.ts +13 -0
  125. package/dist/types/focus/get-last-focusable.d.ts +8 -0
  126. package/dist/types/focus/get-next-focusable.d.ts +13 -0
  127. package/dist/types/focus/is-in-same-layer.d.ts +8 -0
  128. package/dist/types/focus/is-nested-layer-focused.d.ts +8 -0
  129. package/dist/types/focus/selectors.d.ts +4 -0
  130. package/dist/types/focus/types.d.ts +5 -0
  131. package/dist/types/internal/reduced-motion.d.ts +1 -1
  132. package/dist/types/internal/resolve-placement.d.ts +2 -2
  133. package/dist/types/internal/role-to-aria-has-popup.d.ts +13 -0
  134. package/dist/types/internal/role-types.d.ts +0 -19
  135. package/dist/types/internal/should-focus-into-popover.d.ts +8 -0
  136. package/dist/types/internal/slot.d.ts +4 -4
  137. package/dist/types/internal/use-anchor-position-at-point.d.ts +62 -0
  138. package/dist/types/internal/use-anchor-position.d.ts +6 -1
  139. package/dist/types/internal/use-animated-visibility.d.ts +3 -3
  140. package/dist/types/internal/use-animation-preset.d.ts +1 -1
  141. package/dist/types/internal/use-preset-styles.d.ts +1 -1
  142. package/dist/types/internal/use-width-from-anchor.d.ts +2 -2
  143. package/dist/types/placement-map/index.d.ts +1 -1
  144. package/dist/types/placement-map/legacy-placements.d.ts +0 -12
  145. package/dist/types/placement-map/placement-mapping.d.ts +13 -0
  146. package/dist/types/popover/create-close-event.d.ts +1 -1
  147. package/dist/types/popover/popover.d.ts +1 -1
  148. package/dist/types/popup/popup-context.d.ts +1 -1
  149. package/dist/types/testing/to-be-visible.d.ts +3 -3
  150. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +1 -1
  151. package/dist/types/use-simple-light-dismiss/index.d.ts +1 -1
  152. package/dist/types-ts4.5/dialog/create-close-event.d.ts +1 -1
  153. package/dist/types-ts4.5/dialog/types.d.ts +8 -0
  154. package/dist/types-ts4.5/entry-points/focus.d.ts +4 -2
  155. package/dist/types-ts4.5/entry-points/use-anchor-position-at-point.d.ts +1 -0
  156. package/dist/types-ts4.5/focus/get-first-focusable.d.ts +8 -0
  157. package/dist/types-ts4.5/focus/get-focusables.d.ts +13 -0
  158. package/dist/types-ts4.5/focus/get-last-focusable.d.ts +8 -0
  159. package/dist/types-ts4.5/focus/get-next-focusable.d.ts +13 -0
  160. package/dist/types-ts4.5/focus/is-in-same-layer.d.ts +8 -0
  161. package/dist/types-ts4.5/focus/is-nested-layer-focused.d.ts +8 -0
  162. package/dist/types-ts4.5/focus/selectors.d.ts +4 -0
  163. package/dist/types-ts4.5/focus/types.d.ts +5 -0
  164. package/dist/types-ts4.5/internal/reduced-motion.d.ts +1 -1
  165. package/dist/types-ts4.5/internal/resolve-placement.d.ts +2 -2
  166. package/dist/types-ts4.5/internal/role-to-aria-has-popup.d.ts +13 -0
  167. package/dist/types-ts4.5/internal/role-types.d.ts +0 -19
  168. package/dist/types-ts4.5/internal/should-focus-into-popover.d.ts +8 -0
  169. package/dist/types-ts4.5/internal/slot.d.ts +4 -4
  170. package/dist/types-ts4.5/internal/use-anchor-position-at-point.d.ts +62 -0
  171. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +6 -1
  172. package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +3 -3
  173. package/dist/types-ts4.5/internal/use-animation-preset.d.ts +1 -1
  174. package/dist/types-ts4.5/internal/use-preset-styles.d.ts +1 -1
  175. package/dist/types-ts4.5/internal/use-width-from-anchor.d.ts +2 -2
  176. package/dist/types-ts4.5/placement-map/index.d.ts +1 -1
  177. package/dist/types-ts4.5/placement-map/legacy-placements.d.ts +0 -12
  178. package/dist/types-ts4.5/placement-map/placement-mapping.d.ts +13 -0
  179. package/dist/types-ts4.5/popover/create-close-event.d.ts +1 -1
  180. package/dist/types-ts4.5/popover/popover.d.ts +1 -1
  181. package/dist/types-ts4.5/popup/popup-context.d.ts +1 -1
  182. package/dist/types-ts4.5/testing/to-be-visible.d.ts +3 -3
  183. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +1 -1
  184. package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +1 -1
  185. package/package.json +1 -1
  186. package/use-anchor-position-at-point/package.json +17 -0
  187. package/dist/cjs/focus/focus.js +0 -169
  188. package/dist/cjs/focus/index.js +0 -24
  189. package/dist/es2019/focus/focus.js +0 -158
  190. package/dist/es2019/focus/index.js +0 -1
  191. package/dist/esm/focus/focus.js +0 -160
  192. package/dist/esm/focus/index.js +0 -1
  193. package/dist/types/focus/focus.d.ts +0 -50
  194. package/dist/types/focus/index.d.ts +0 -2
  195. package/dist/types-ts4.5/focus/focus.d.ts +0 -50
  196. package/dist/types-ts4.5/focus/index.d.ts +0 -2
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The full mapping record. Internal - use `fromLegacyPlacement` from the
3
+ * public entry-point so the offset-tuple translation is applied consistently.
4
+ *
5
+ * Note: `auto`, `auto-start`, `auto-end` map to `block-end` placements. This
6
+ * is a reduction in expressiveness vs Popper.js (which picked the best
7
+ * placement at runtime). CSS `position-try-fallbacks` flips at the edge but
8
+ * the initial placement is fixed. Migration consumers who relied on Popper's
9
+ * dynamic auto-flip should pick an explicit placement instead.
10
+ */
11
+ export const placementMapping = {
12
+ top: {
13
+ axis: 'block',
14
+ edge: 'start',
15
+ align: 'center'
16
+ },
17
+ 'top-start': {
18
+ axis: 'block',
19
+ edge: 'start',
20
+ align: 'start'
21
+ },
22
+ 'top-center': {
23
+ axis: 'block',
24
+ edge: 'start',
25
+ align: 'center'
26
+ },
27
+ 'top-end': {
28
+ axis: 'block',
29
+ edge: 'start',
30
+ align: 'end'
31
+ },
32
+ bottom: {
33
+ axis: 'block',
34
+ edge: 'end',
35
+ align: 'center'
36
+ },
37
+ 'bottom-start': {
38
+ axis: 'block',
39
+ edge: 'end',
40
+ align: 'start'
41
+ },
42
+ 'bottom-center': {
43
+ axis: 'block',
44
+ edge: 'end',
45
+ align: 'center'
46
+ },
47
+ 'bottom-end': {
48
+ axis: 'block',
49
+ edge: 'end',
50
+ align: 'end'
51
+ },
52
+ right: {
53
+ axis: 'inline',
54
+ edge: 'end',
55
+ align: 'center'
56
+ },
57
+ 'right-start': {
58
+ axis: 'inline',
59
+ edge: 'end',
60
+ align: 'start'
61
+ },
62
+ 'right-end': {
63
+ axis: 'inline',
64
+ edge: 'end',
65
+ align: 'end'
66
+ },
67
+ left: {
68
+ axis: 'inline',
69
+ edge: 'start',
70
+ align: 'center'
71
+ },
72
+ 'left-start': {
73
+ axis: 'inline',
74
+ edge: 'start',
75
+ align: 'start'
76
+ },
77
+ 'left-end': {
78
+ axis: 'inline',
79
+ edge: 'start',
80
+ align: 'end'
81
+ },
82
+ auto: {
83
+ axis: 'block',
84
+ edge: 'end',
85
+ align: 'center'
86
+ },
87
+ 'auto-start': {
88
+ axis: 'block',
89
+ edge: 'end',
90
+ align: 'start'
91
+ },
92
+ 'auto-end': {
93
+ axis: 'block',
94
+ edge: 'end',
95
+ align: 'end'
96
+ }
97
+ };
@@ -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
  //
@@ -4,7 +4,8 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { forwardRef, useCallback, useLayoutEffect, useRef } from 'react';
5
5
  import mergeRefs from '@atlaskit/ds-lib/merge-refs';
6
6
  import { prefersReducedMotion } from '../internal/reduced-motion';
7
- import { roleToAriaHasPopup, shouldFocusIntoPopover } from '../internal/role-types';
7
+ import { roleToAriaHasPopup } from '../internal/role-to-aria-has-popup';
8
+ import { shouldFocusIntoPopover } from '../internal/should-focus-into-popover';
8
9
  import { useAnchorPosition } from '../internal/use-anchor-position';
9
10
  import { useWidthFromAnchor } from '../internal/use-width-from-anchor';
10
11
  import { Popover } from '../popover/popover';
@@ -89,7 +90,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
89
90
  // Note: onOpenChange composition is handled by handleOpenChange below,
90
91
  // which also adds nested-popover focus restoration.
91
92
 
92
- // ── Sync aria-haspopup on the trigger with the content's role ──
93
+ // Sync aria-haspopup on the trigger with the content's role
93
94
  const setAriaHasPopup = ctx === null || ctx === void 0 ? void 0 : ctx.setAriaHasPopup;
94
95
  useLayoutEffect(() => {
95
96
  setAriaHasPopup === null || setAriaHasPopup === void 0 ? void 0 : setAriaHasPopup(roleToAriaHasPopup({
@@ -97,7 +98,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
97
98
  }));
98
99
  }, [role, setAriaHasPopup]);
99
100
 
100
- // ── Focus restoration ──
101
+ // Focus restoration
101
102
  // The native Popover API handles focus restoration automatically for
102
103
  // popover="auto" and popover="hint":
103
104
  // - Escape → restores focus to the previously focused element (the trigger)
@@ -124,7 +125,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
124
125
  }
125
126
  consumerOnOpenChange === null || consumerOnOpenChange === void 0 ? void 0 : consumerOnOpenChange(args);
126
127
 
127
- // ── Nested popover focus restoration fallback ──
128
+ // Nested popover focus restoration fallback
128
129
  // The browser only captures `previouslyFocusedElement` for the
129
130
  // outermost popover="auto" in the stack. Inner (nested) popovers
130
131
  // have shouldRestoreFocus=false, so the browser will not restore
@@ -153,7 +154,7 @@ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
153
154
  }
154
155
  }, [consumerOnOpenChange, triggerRef, role, setPopupState, willAnimate]);
155
156
 
156
- // ── Anchor positioning ──
157
+ // Anchor positioning
157
158
  // Compose useAnchorPosition with Popover. The hook positions the popover
158
159
  // relative to the trigger element via CSS Anchor Positioning (with JS fallback).
159
160
  // Use ctx.popoverRef when inside the compound (so the trigger can also
@@ -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,5 +1,23 @@
1
1
  const menuScope = '[role="menu"]';
2
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
+
3
21
  /**
4
22
  * Returns true if the element belongs to the current menu level of the
5
23
  * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
@@ -66,16 +84,5 @@ export function isAtCurrentMenuLevel(element, container) {
66
84
 
67
85
  // Walk up from the closest menu to see if it is "owned" by this
68
86
  // container without passing through another role="menu" first.
69
- let parent = closestMenu.parentElement;
70
- while (parent && parent !== container) {
71
- if (parent.getAttribute('role') === 'menu') {
72
- // There is a parent menu between the closest menu and the
73
- // container, so the element is in a nested sub-menu.
74
- return false;
75
- }
76
- parent = parent.parentElement;
77
- }
78
-
79
- // The closest menu is directly inside the container (no nesting).
80
- return parent === container;
87
+ return reachesContainerWithoutNestedMenu(closestMenu.parentElement, container);
81
88
  }
@@ -2,7 +2,9 @@ import { useCallback, useEffect } from 'react';
2
2
  import { bind } from 'bind-event-listener';
3
3
  import { getDocument } from '@atlaskit/browser-apis';
4
4
  import { KEY_DOWN, KEY_END, KEY_HOME, KEY_TAB, KEY_UP } from '@atlaskit/ds-lib/keycodes';
5
- import { getFirstFocusable, getLastFocusable, getNextFocusable } from '../focus';
5
+ import { getFirstFocusable } from '../focus/get-first-focusable';
6
+ import { getLastFocusable } from '../focus/get-last-focusable';
7
+ import { getNextFocusable } from '../focus/get-next-focusable';
6
8
  const menuScope = '[role="menu"]';
7
9
 
8
10
  /**
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  import { getPlacement } from '../internal/resolve-placement';
2
2
 
3
- // ── slideAndFade ──
3
+ // slideAndFade
4
4
 
5
5
  function getSlideAndFadeProperties(_ref) {
6
6
  var placement = _ref.placement,
@@ -82,7 +82,7 @@ export function slideAndFade(options) {
82
82
  };
83
83
  }
84
84
 
85
- // ── fade ──
85
+ // fade
86
86
 
87
87
  var FADE_CSS = "\n[data-ds-popover-fade] {\n opacity: 0;\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-fade]:popover-open {\n opacity: 1;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-fade]:popover-open {\n opacity: 0;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-fade],\n [data-ds-popover-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
88
88
 
@@ -108,7 +108,7 @@ export function fade() {
108
108
  };
109
109
  }
110
110
 
111
- // ── scaleAndFade ──
111
+ // scaleAndFade
112
112
 
113
113
  var SCALE_AND_FADE_CSS = "\n[data-ds-popover-scale-and-fade] {\n opacity: 0;\n transform: scale(0.95);\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-scale-and-fade]:popover-open {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-scale-and-fade]:popover-open {\n opacity: 0;\n transform: scale(0.95);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-scale-and-fade],\n [data-ds-popover-scale-and-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
114
114
 
@@ -138,7 +138,7 @@ export function scaleAndFade() {
138
138
  // Dialog presets
139
139
  // ══════════════════════════════════════════════════════════════════════════════
140
140
 
141
- // ── dialogSlideUpAndFade ──
141
+ // dialogSlideUpAndFade
142
142
 
143
143
  var DIALOG_SLIDE_UP_AND_FADE_CSS = "\n[data-ds-dialog-slide-up-and-fade] {\n opacity: 0;\n transform: translateY(calc(-1 * var(--ds-dialog-ty, 12px)));\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-slide-up-and-fade][open] {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-slide-up-and-fade][open] {\n opacity: 0;\n transform: translateY(var(--ds-dialog-ty, 12px));\n }\n}\n\n[data-ds-dialog-slide-up-and-fade]::backdrop {\n background-color: transparent;\n transition:\n background-color 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-slide-up-and-fade][open]::backdrop {\n background-color: var(--ds-blanket, #050C1F75);\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-slide-up-and-fade][open]::backdrop {\n background-color: transparent;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-dialog-slide-up-and-fade],\n [data-ds-dialog-slide-up-and-fade][open],\n [data-ds-dialog-slide-up-and-fade]::backdrop,\n [data-ds-dialog-slide-up-and-fade][open]::backdrop {\n transition-duration: 0s;\n }\n}\n";
144
144
 
@@ -174,7 +174,7 @@ export function dialogSlideUpAndFade(options) {
174
174
  };
175
175
  }
176
176
 
177
- // ── dialogFade ──
177
+ // dialogFade
178
178
 
179
179
  var DIALOG_FADE_CSS = "\n[data-ds-dialog-fade] {\n opacity: 0;\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-fade][open] {\n opacity: 1;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-fade][open] {\n opacity: 0;\n }\n}\n\n[data-ds-dialog-fade]::backdrop {\n background-color: transparent;\n transition:\n background-color 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-fade][open]::backdrop {\n background-color: var(--ds-blanket, #050C1F75);\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-fade][open]::backdrop {\n background-color: transparent;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-dialog-fade],\n [data-ds-dialog-fade][open],\n [data-ds-dialog-fade]::backdrop,\n [data-ds-dialog-fade][open]::backdrop {\n transition-duration: 0s;\n }\n}\n";
180
180
 
@@ -2,7 +2,7 @@
2
2
  * Creates a synthetic DOM event from a `TDialogCloseReason`.
3
3
  *
4
4
  * Useful when bridging the Dialog primitive's `onClose({ reason })` callback
5
- * to a legacy API that expects a `KeyboardEvent` or `MouseEvent` — for example,
5
+ * to a legacy API that expects a `KeyboardEvent` or `MouseEvent` - for example,
6
6
  * `@atlaskit/modal-dialog`'s `onClose(event, analyticsEvent)` contract.
7
7
  *
8
8
  * - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
@@ -49,7 +49,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
49
49
  var ownRef = useRef(null);
50
50
  var combinedRef = mergeRefs([ownRef, ref]);
51
51
 
52
- // ── Animation lifecycle ──
52
+ // Animation lifecycle
53
53
  var _useAnimatedVisibilit = useAnimatedVisibility({
54
54
  isOpen: isOpen,
55
55
  animate: animate,
@@ -59,7 +59,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
59
59
  showChildren = _useAnimatedVisibilit.showChildren,
60
60
  preset = _useAnimatedVisibilit.preset;
61
61
 
62
- // ── Focus wrap ──
62
+ // Focus wrap
63
63
  // Native <dialog>.showModal() traps focus but wraps through <body> at
64
64
  // the boundary (A → B → C → body → A). This hook intercepts Tab to
65
65
  // wrap directly (A → B → C → A), matching the WAI-ARIA APG pattern.
@@ -68,7 +68,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
68
68
  role: 'dialog'
69
69
  });
70
70
 
71
- // ── Open layer observer registration ──
71
+ // Open layer observer registration
72
72
  // Notifies the open layer observer so app-coordination features
73
73
  // (open-count subscriptions) work with top-layer dialogs.
74
74
  useNotifyOpenLayerObserver({
@@ -99,7 +99,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
99
99
  }
100
100
  }, [isOpen]);
101
101
 
102
- // ── Handle native Escape (cancel event) ──
102
+ // Handle native Escape (cancel event)
103
103
  var handleCancel = useCallback(function (event) {
104
104
  event.preventDefault();
105
105
  onClose({
@@ -107,7 +107,7 @@ export var Dialog = /*#__PURE__*/forwardRef(function Dialog(_ref, ref) {
107
107
  });
108
108
  }, [onClose]);
109
109
 
110
- // ── Handle backdrop click ──
110
+ // Handle backdrop click
111
111
  // Attached via bind-event-listener rather than a React prop so we avoid
112
112
  // a11y lint suppressions on the <dialog> element.
113
113
  // Keyboard dismiss is already handled natively (Escape → onCancel above).
@@ -1 +1,3 @@
1
- export { getFirstFocusable, getLastFocusable, getNextFocusable } from '../focus';
1
+ export { getFirstFocusable } from '../focus/get-first-focusable';
2
+ export { getLastFocusable } from '../focus/get-last-focusable';
3
+ export { getNextFocusable } from '../focus/get-next-focusable';
@@ -0,0 +1 @@
1
+ export { useAnchorPositionAtPoint } from '../internal/use-anchor-position-at-point';
@@ -0,0 +1,13 @@
1
+ import { getFocusables } from './get-focusables';
2
+ /**
3
+ * Returns the first focusable element within the container.
4
+ */
5
+ export function getFirstFocusable(_ref) {
6
+ var container = _ref.container,
7
+ filter = _ref.filter;
8
+ var items = getFocusables({
9
+ container: container,
10
+ filter: filter
11
+ });
12
+ return items.length > 0 ? items[0] : null;
13
+ }
@@ -0,0 +1,24 @@
1
+ import { isInSameLayer } from './is-in-same-layer';
2
+ import { selectors } from './selectors';
3
+ /**
4
+ * Returns all focusable HTMLElements within the container, optionally filtered.
5
+ *
6
+ * Focusables that belong to a nested top-layer scope (a `[popover]` or
7
+ * `<dialog>` descendant of the container) are excluded - those elements
8
+ * are owned by the inner layer's focus management. The container itself
9
+ * is allowed to be a popover/dialog; only nested ones are filtered.
10
+ */
11
+ export function getFocusables(_ref) {
12
+ var container = _ref.container,
13
+ filter = _ref.filter;
14
+ return Array.from(container.querySelectorAll(selectors.focusable)).filter(function (element) {
15
+ return element instanceof HTMLElement;
16
+ }).filter(function (element) {
17
+ return isInSameLayer({
18
+ element: element,
19
+ container: container
20
+ });
21
+ }).filter(function (element) {
22
+ return !filter || filter(element, container);
23
+ });
24
+ }
@@ -0,0 +1,13 @@
1
+ import { getFocusables } from './get-focusables';
2
+ /**
3
+ * Returns the last focusable element within the container.
4
+ */
5
+ export function getLastFocusable(_ref) {
6
+ var container = _ref.container,
7
+ filter = _ref.filter;
8
+ var items = getFocusables({
9
+ container: container,
10
+ filter: filter
11
+ });
12
+ return items.length > 0 ? items[items.length - 1] : null;
13
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Returns the next focusable element in the given direction relative to the
3
+ * currently focused element within the container. Wraps around at both ends.
4
+ *
5
+ * Returns `null` if there is no focused element within the container or if
6
+ * the focused element is not in the list of focusable elements.
7
+ */
8
+
9
+ import { getFocusables } from './get-focusables';
10
+ import { selectors } from './selectors';
11
+ export function getNextFocusable(_ref) {
12
+ var _all$nextIndex;
13
+ var container = _ref.container,
14
+ direction = _ref.direction,
15
+ filter = _ref.filter;
16
+ var all = getFocusables({
17
+ container: container,
18
+ filter: filter
19
+ });
20
+ var current = container.querySelector(selectors.focused);
21
+ if (!(current instanceof HTMLElement)) {
22
+ return null;
23
+ }
24
+ var index = all.indexOf(current);
25
+ if (index === -1) {
26
+ return null;
27
+ }
28
+ var nextIndex = function () {
29
+ if (direction === 'forwards') {
30
+ return (index + 1) % all.length;
31
+ }
32
+ var proposed = index - 1;
33
+ // if going into negative numbers, loop back to the last item
34
+ return proposed < 0 ? all.length - 1 : proposed;
35
+ }();
36
+ return (_all$nextIndex = all[nextIndex]) !== null && _all$nextIndex !== void 0 ? _all$nextIndex : null;
37
+ }
@@ -0,0 +1,17 @@
1
+ var topLayerSelector = '[popover], dialog, [role="dialog"], [role="alertdialog"]';
2
+
3
+ /**
4
+ * Returns true when `element` and `container` resolve to the same nearest
5
+ * top-layer host (or both resolve to `null`, meaning the document layer).
6
+ */
7
+ export function isInSameLayer(_ref) {
8
+ var element = _ref.element,
9
+ container = _ref.container;
10
+ var elementLayer = element.closest(topLayerSelector);
11
+ var containerLayer = container.closest(topLayerSelector);
12
+ // Both elements are in the "document" layer
13
+ if (!elementLayer && !containerLayer) {
14
+ return true;
15
+ }
16
+ return elementLayer === containerLayer;
17
+ }
@@ -0,0 +1,27 @@
1
+ import { getDocument } from '@atlaskit/browser-apis';
2
+ import { isInSameLayer } from './is-in-same-layer';
3
+
4
+ /**
5
+ * Returns `true` when `document.activeElement` is inside a nested top-layer
6
+ * descendant of `container` (a `[popover]`, `<dialog>`, `[role="dialog"]` or
7
+ * `[role="alertdialog"]` that is itself a descendant of `container`).
8
+ */
9
+ export function isNestedLayerFocused(_ref) {
10
+ var _getDocument;
11
+ var container = _ref.container;
12
+ var focused = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.activeElement;
13
+ if (!(focused instanceof HTMLElement)) {
14
+ return false;
15
+ }
16
+
17
+ // Cannot be in a nested layer if it is not in the container
18
+ if (!container.contains(focused)) {
19
+ return false;
20
+ }
21
+
22
+ // If not in the same layer, must be in a nested layer
23
+ return !isInSameLayer({
24
+ element: focused,
25
+ container: container
26
+ });
27
+ }
@@ -0,0 +1,13 @@
1
+ export var selectors = function () {
2
+ // Common exclusion filter applied to every selector.
3
+ var not = ':not([tabindex="-1"]):not([aria-disabled="true"]):not([aria-hidden="true"])';
4
+ var notDisabled = ":not([disabled])".concat(not);
5
+ var focusable = ["a[href]".concat(not), "area[href]".concat(not), "input".concat(notDisabled, ":not([type=\"hidden\"])"), "select".concat(notDisabled), "textarea".concat(notDisabled), "button".concat(notDisabled), "iframe".concat(not), "audio[controls]".concat(not), "video[controls]".concat(not), "[contenteditable]:not([contenteditable=\"false\"])".concat(not), "[tabindex]".concat(notDisabled).concat(not)];
6
+ return {
7
+ focusable: focusable.join(','),
8
+ // Build the `:focus` selector
9
+ focused: focusable.map(function (selector) {
10
+ return "".concat(selector, ":focus");
11
+ }).join(',')
12
+ };
13
+ }();
File without changes
@@ -4,7 +4,7 @@
4
4
  * Each preset's CSS is injected at most once into `<head>`.
5
5
  * Shared by both PopoverContent and DialogContent.
6
6
  *
7
- * Note: injected `<style>` elements and the tracking Set are append-only —
7
+ * Note: injected `<style>` elements and the tracking Set are append-only -
8
8
  * they are never removed. This is intentional: the number of distinct
9
9
  * presets is bounded (handful of animation presets), so the
10
10
  * memory footprint is negligible. Removing styles would risk breaking
@@ -7,7 +7,7 @@ import once from '@atlaskit/ds-lib/once';
7
7
  *
8
8
  * The result is cached after the first call via `once`. This avoids
9
9
  * calling `matchMedia` on every render. The trade-off is that if a user
10
- * toggles the OS reduced-motion setting mid-session, the change won't
10
+ * toggles the OS reduced-motion setting mid-session, the change will not
11
11
  * take effect until the next page load. This is acceptable because
12
12
  * toggling this system-level preference mid-session is extremely rare,
13
13
  * and a page refresh is a reasonable expectation for system accessibility