@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
@@ -8,7 +8,7 @@ exports.createPopoverCloseEvent = createPopoverCloseEvent;
8
8
  * Creates a synthetic DOM event from a `TPopoverCloseReason`.
9
9
  *
10
10
  * Useful when bridging the Popover primitive's `onClose({ reason })` callback
11
- * to a legacy API that expects a native DOM event — for example,
11
+ * to a legacy API that expects a native DOM event - for example,
12
12
  * `@atlaskit/inline-dialog`'s `onClose(event)` contract.
13
13
  *
14
14
  * - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
@@ -56,7 +56,7 @@ var POPUP_ROLES = new Set(['menu', 'listbox', 'dialog', 'alertdialog', 'tree', '
56
56
  * Unopinionated top-layer primitive.
57
57
  *
58
58
  * Manages only visibility (isOpen) and animation (animate). Has no knowledge
59
- * of positioning — compose with `useAnchorPosition` for anchor positioning
59
+ * of positioning - compose with `useAnchorPosition` for anchor positioning
60
60
  * and optionally `useWidthFromAnchor` for setting the width of a popover element
61
61
  * relative to its anchor trigger.
62
62
  *
@@ -105,7 +105,7 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
105
105
  showChildren = _useAnimatedVisibilit.showChildren,
106
106
  preset = _useAnimatedVisibilit.preset;
107
107
 
108
- // ── Focus management ──
108
+ // Focus management
109
109
  // Initial focus: on open, moves focus into the popover (role-dependent).
110
110
  // Focus wrap: Tab/Shift+Tab cycle within the popover for dialog roles.
111
111
  // Focus restoration: handled natively by the Popover API. The browser
@@ -121,7 +121,7 @@ var Popover = exports.Popover = /*#__PURE__*/(0, _react.forwardRef)(function Pop
121
121
  role: role
122
122
  });
123
123
 
124
- // ── Open layer observer registration ──
124
+ // Open layer observer registration
125
125
  // Notifies the open layer observer so app-coordination features
126
126
  // (closeLayers(), open-count subscriptions) work with top-layer popovers.
127
127
  //
@@ -12,7 +12,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
  var _mergeRefs = _interopRequireDefault(require("@atlaskit/ds-lib/merge-refs"));
14
14
  var _reducedMotion = require("../internal/reduced-motion");
15
- var _roleTypes = require("../internal/role-types");
15
+ var _roleToAriaHasPopup = require("../internal/role-to-aria-has-popup");
16
+ var _shouldFocusIntoPopover = require("../internal/should-focus-into-popover");
16
17
  var _useAnchorPosition = require("../internal/use-anchor-position");
17
18
  var _useWidthFromAnchor = require("../internal/use-width-from-anchor");
18
19
  var _popover = require("../popover/popover");
@@ -97,15 +98,15 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
97
98
  // Note: onOpenChange composition is handled by handleOpenChange below,
98
99
  // which also adds nested-popover focus restoration.
99
100
 
100
- // ── Sync aria-haspopup on the trigger with the content's role ──
101
+ // Sync aria-haspopup on the trigger with the content's role
101
102
  var setAriaHasPopup = ctx === null || ctx === void 0 ? void 0 : ctx.setAriaHasPopup;
102
103
  (0, _react.useLayoutEffect)(function () {
103
- setAriaHasPopup === null || setAriaHasPopup === void 0 || setAriaHasPopup((0, _roleTypes.roleToAriaHasPopup)({
104
+ setAriaHasPopup === null || setAriaHasPopup === void 0 || setAriaHasPopup((0, _roleToAriaHasPopup.roleToAriaHasPopup)({
104
105
  role: role
105
106
  }));
106
107
  }, [role, setAriaHasPopup]);
107
108
 
108
- // ── Focus restoration ──
109
+ // Focus restoration
109
110
  // The native Popover API handles focus restoration automatically for
110
111
  // popover="auto" and popover="hint":
111
112
  // - Escape → restores focus to the previously focused element (the trigger)
@@ -132,7 +133,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
132
133
  }
133
134
  consumerOnOpenChange === null || consumerOnOpenChange === void 0 || consumerOnOpenChange(args);
134
135
 
135
- // ── Nested popover focus restoration fallback ──
136
+ // Nested popover focus restoration fallback
136
137
  // The browser only captures `previouslyFocusedElement` for the
137
138
  // outermost popover="auto" in the stack. Inner (nested) popovers
138
139
  // have shouldRestoreFocus=false, so the browser will not restore
@@ -151,7 +152,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
151
152
  // Single source of truth for "this role moves focus on open
152
153
  // and therefore needs to be restored on close" - see
153
154
  // `shouldFocusIntoPopover` in `internal/role-types.tsx`.
154
- if (focusStillInPopover && (0, _roleTypes.shouldFocusIntoPopover)({
155
+ if (focusStillInPopover && (0, _shouldFocusIntoPopover.shouldFocusIntoPopover)({
155
156
  role: role
156
157
  })) {
157
158
  trigger.focus({
@@ -161,7 +162,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
161
162
  }
162
163
  }, [consumerOnOpenChange, triggerRef, role, setPopupState, willAnimate]);
163
164
 
164
- // ── Anchor positioning ──
165
+ // Anchor positioning
165
166
  // Compose useAnchorPosition with Popover. The hook positions the popover
166
167
  // relative to the trigger element via CSS Anchor Positioning (with JS fallback).
167
168
  // Use ctx.popoverRef when inside the compound (so the trigger can also
@@ -104,7 +104,7 @@ function createToggleScheduler() {
104
104
  newState: newState
105
105
  });
106
106
 
107
- // Task queue (setTimeout) — browser fires toggle after microtasks drain, not during
107
+ // Task queue (setTimeout) - browser fires toggle after microtasks drain, not during
108
108
  setTimeout(function () {
109
109
  var entry = pending.get(element);
110
110
  if (!entry) {
@@ -174,7 +174,7 @@ function createDialogToggleScheduler() {
174
174
  };
175
175
  }
176
176
 
177
- // ─── Popover API ────────────────────────────────────────────────────────────
177
+ // Popover API
178
178
  // Spec: https://html.spec.whatwg.org/multipage/popover.html
179
179
 
180
180
  // `popover` attribute valid values. Empty / "auto" -> "auto"; unknown -> "manual".
@@ -537,7 +537,7 @@ if (typeof HTMLElement !== 'undefined') {
537
537
  if (isPopoverOpen({
538
538
  element: this
539
539
  })) {
540
- return; // already showing — no-op
540
+ return; // already showing - no-op
541
541
  }
542
542
 
543
543
  // sync, cancelable on show only
@@ -717,7 +717,7 @@ if (typeof HTMLElement !== 'undefined') {
717
717
  }
718
718
  }
719
719
 
720
- // ─── HTMLDialogElement ──────────────────────────────────────────────────────
720
+ // HTMLDialogElement
721
721
  // Spec: https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element
722
722
 
723
723
  if (typeof HTMLDialogElement !== 'undefined') {
@@ -732,7 +732,7 @@ if (typeof HTMLDialogElement !== 'undefined') {
732
732
  }
733
733
  if (this.hasAttribute('open')) {
734
734
  if (this._isModal) {
735
- return; // already modal — no-op
735
+ return; // already modal - no-op
736
736
  }
737
737
  throw new DOMException("Failed to execute 'showModal' on 'HTMLDialogElement': ".concat(describeElement({
738
738
  element: this
@@ -756,7 +756,7 @@ if (typeof HTMLDialogElement !== 'undefined') {
756
756
  }
757
757
  if (typeof proto.show !== 'function') {
758
758
  proto.show = function show() {
759
- // Browser does not throw for disconnected elements on show — just no-op
759
+ // Browser does not throw for disconnected elements on show - just no-op
760
760
  if (!this.isConnected || this.hasAttribute('open')) {
761
761
  return;
762
762
  }
@@ -779,10 +779,10 @@ if (typeof HTMLDialogElement !== 'undefined') {
779
779
  if (typeof proto.close !== 'function') {
780
780
  proto.close = function close(returnValue) {
781
781
  if (!this.hasAttribute('open')) {
782
- return; // already closed — no-op
782
+ return; // already closed - no-op
783
783
  }
784
784
 
785
- // Sync beforetoggle (not cancelable) — matches browser behavior
785
+ // Sync beforetoggle (not cancelable) - matches browser behavior
786
786
  fireToggleEvent({
787
787
  element: this,
788
788
  type: 'beforetoggle',
@@ -8,13 +8,13 @@ var _matchers = require("@testing-library/jest-dom/matchers");
8
8
  *
9
9
  * jest-dom's `toBeVisible()` does not know about the Popover API. In real
10
10
  * browsers the UA stylesheet hides `[popover]` with `display: none`, but
11
- * jsdom has no such stylesheet — so closed popovers incorrectly appear visible.
11
+ * jsdom has no such stylesheet - so closed popovers incorrectly appear visible.
12
12
  *
13
13
  * Raw jest-dom results in jsdom:
14
14
  *
15
- * closed popover / child → true (WRONG — should be false)
15
+ * closed popover / child → true (WRONG - should be false)
16
16
  * open popover / child → true (correct)
17
- * closed dialog / child → false (correct — jsdom natively hides <dialog>)
17
+ * closed dialog / child → false (correct - jsdom natively hides <dialog>)
18
18
  * open dialog / child → true (correct)
19
19
  *
20
20
  * We correct both false positives and false negatives:
@@ -65,7 +65,7 @@ expect.extend({
65
65
  var originalResult = _matchers.toBeVisible.call(this, element);
66
66
  var topLayerState = nearestTopLayerState(element);
67
67
  if (originalResult.pass) {
68
- // Original says visible — override if nearest top-layer host is closed.
68
+ // Original says visible - override if nearest top-layer host is closed.
69
69
  if (topLayerState === 'closed') {
70
70
  return {
71
71
  pass: false,
@@ -77,7 +77,7 @@ expect.extend({
77
77
  return originalResult;
78
78
  }
79
79
 
80
- // Original says not visible — override if nearest top-layer host is open.
80
+ // Original says not visible - override if nearest top-layer host is open.
81
81
  // jsdom may hide [popover] elements even when they are logically open.
82
82
  if (topLayerState === 'open') {
83
83
  return {
@@ -6,6 +6,24 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isAtCurrentMenuLevel = isAtCurrentMenuLevel;
7
7
  var menuScope = '[role="menu"]';
8
8
 
9
+ /**
10
+ * Recursively walks from `node` toward `container`, returning `true` when
11
+ * `container` is reached without crossing another `role="menu"` ancestor.
12
+ *
13
+ * Used by `isAtCurrentMenuLevel` (pattern 2) to determine if the
14
+ * `closestMenu` is owned by the wrapper container directly. Recursion
15
+ * avoids a mutable `let parent` walk and keeps the function body linear.
16
+ */
17
+ function reachesContainerWithoutNestedMenu(node, container) {
18
+ if (!node || node === container) {
19
+ return node === container;
20
+ }
21
+ if (node.getAttribute('role') === 'menu') {
22
+ return false;
23
+ }
24
+ return reachesContainerWithoutNestedMenu(node.parentElement, container);
25
+ }
26
+
9
27
  /**
10
28
  * Returns true if the element belongs to the current menu level of the
11
29
  * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
@@ -72,16 +90,5 @@ function isAtCurrentMenuLevel(element, container) {
72
90
 
73
91
  // Walk up from the closest menu to see if it is "owned" by this
74
92
  // container without passing through another role="menu" first.
75
- var parent = closestMenu.parentElement;
76
- while (parent && parent !== container) {
77
- if (parent.getAttribute('role') === 'menu') {
78
- // There is a parent menu between the closest menu and the
79
- // container, so the element is in a nested sub-menu.
80
- return false;
81
- }
82
- parent = parent.parentElement;
83
- }
84
-
85
- // The closest menu is directly inside the container (no nesting).
86
- return parent === container;
93
+ return reachesContainerWithoutNestedMenu(closestMenu.parentElement, container);
87
94
  }
@@ -8,7 +8,9 @@ var _react = require("react");
8
8
  var _bindEventListener = require("bind-event-listener");
9
9
  var _browserApis = require("@atlaskit/browser-apis");
10
10
  var _keycodes = require("@atlaskit/ds-lib/keycodes");
11
- var _focus = require("../focus");
11
+ var _getFirstFocusable2 = require("../focus/get-first-focusable");
12
+ var _getLastFocusable2 = require("../focus/get-last-focusable");
13
+ var _getNextFocusable3 = require("../focus/get-next-focusable");
12
14
  var menuScope = '[role="menu"]';
13
15
 
14
16
  /**
@@ -96,7 +98,7 @@ function useArrowNavigation(_ref) {
96
98
  var _getNextFocusable;
97
99
  // Prevent page scroll while navigating menu items.
98
100
  event.preventDefault();
99
- (_getNextFocusable = (0, _focus.getNextFocusable)({
101
+ (_getNextFocusable = (0, _getNextFocusable3.getNextFocusable)({
100
102
  container: container,
101
103
  direction: 'forwards',
102
104
  filter: filter
@@ -107,7 +109,7 @@ function useArrowNavigation(_ref) {
107
109
  var _getNextFocusable2;
108
110
  // Prevent page scroll while navigating menu items.
109
111
  event.preventDefault();
110
- (_getNextFocusable2 = (0, _focus.getNextFocusable)({
112
+ (_getNextFocusable2 = (0, _getNextFocusable3.getNextFocusable)({
111
113
  container: container,
112
114
  direction: 'backwards',
113
115
  filter: filter
@@ -118,7 +120,7 @@ function useArrowNavigation(_ref) {
118
120
  var _getFirstFocusable;
119
121
  // Prevent browser default (e.g. scrolling to top of page).
120
122
  event.preventDefault();
121
- (_getFirstFocusable = (0, _focus.getFirstFocusable)({
123
+ (_getFirstFocusable = (0, _getFirstFocusable2.getFirstFocusable)({
122
124
  container: container,
123
125
  filter: filter
124
126
  })) === null || _getFirstFocusable === void 0 || _getFirstFocusable.focus();
@@ -128,7 +130,7 @@ function useArrowNavigation(_ref) {
128
130
  var _getLastFocusable;
129
131
  // Prevent browser default (e.g. scrolling to bottom of page).
130
132
  event.preventDefault();
131
- (_getLastFocusable = (0, _focus.getLastFocusable)({
133
+ (_getLastFocusable = (0, _getLastFocusable2.getLastFocusable)({
132
134
  container: container,
133
135
  filter: filter
134
136
  })) === null || _getLastFocusable === void 0 || _getLastFocusable.focus();
@@ -15,7 +15,7 @@ var _bindEventListener = require("bind-event-listener");
15
15
  * **No stacking awareness:** This hook does not track a popover stack.
16
16
  * If multiple manual popovers are open and all use this hook, a single
17
17
  * Escape press or outside click will dismiss **all of them simultaneously**.
18
- * This is by design — the hook is intentionally simple for cases where
18
+ * This is by design - the hook is intentionally simple for cases where
19
19
  * only one manual popover is open at a time.
20
20
  *
21
21
  * For stacked/nested popovers that should dismiss one-at-a-time, use
@@ -52,7 +52,7 @@ function useSimpleLightDismiss(_ref) {
52
52
  // (trigger onClick → setIsOpen(true) → React render → useEffect).
53
53
  // By the time this effect runs, the opening click has finished
54
54
  // bubbling. A capture-phase listener added now cannot retroactively
55
- // fire for that event — it only fires for *future* clicks.
55
+ // fire for that event - it only fires for *future* clicks.
56
56
  //
57
57
  // This avoids the need for timestamp guards or deferred binding.
58
58
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage -- binding to document for light dismiss
@@ -64,7 +64,7 @@ function useSimpleLightDismiss(_ref) {
64
64
  return;
65
65
  }
66
66
 
67
- // If the click target is inside the popover, don't dismiss.
67
+ // If the click target is inside the popover, do not dismiss.
68
68
  if (event.target instanceof Node && el.contains(event.target)) {
69
69
  return;
70
70
  }
@@ -1,6 +1,6 @@
1
1
  import { getPlacement } from '../internal/resolve-placement';
2
2
 
3
- // ── slideAndFade ──
3
+ // slideAndFade
4
4
 
5
5
  function getSlideAndFadeProperties({
6
6
  placement,
@@ -123,7 +123,7 @@ export function slideAndFade(options) {
123
123
  };
124
124
  }
125
125
 
126
- // ── fade ──
126
+ // fade
127
127
 
128
128
  const FADE_CSS = `
129
129
  [data-ds-popover-fade] {
@@ -175,7 +175,7 @@ export function fade() {
175
175
  };
176
176
  }
177
177
 
178
- // ── scaleAndFade ──
178
+ // scaleAndFade
179
179
 
180
180
  const SCALE_AND_FADE_CSS = `
181
181
  [data-ds-popover-scale-and-fade] {
@@ -235,7 +235,7 @@ export function scaleAndFade() {
235
235
  // Dialog presets
236
236
  // ══════════════════════════════════════════════════════════════════════════════
237
237
 
238
- // ── dialogSlideUpAndFade ──
238
+ // dialogSlideUpAndFade
239
239
 
240
240
  const DIALOG_SLIDE_UP_AND_FADE_CSS = `
241
241
  [data-ds-dialog-slide-up-and-fade] {
@@ -322,7 +322,7 @@ export function dialogSlideUpAndFade(options) {
322
322
  };
323
323
  }
324
324
 
325
- // ── dialogFade ──
325
+ // dialogFade
326
326
 
327
327
  const DIALOG_FADE_CSS = `
328
328
  [data-ds-dialog-fade] {
@@ -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 const Dialog = /*#__PURE__*/forwardRef(function Dialog({
49
49
  const ownRef = useRef(null);
50
50
  const combinedRef = mergeRefs([ownRef, ref]);
51
51
 
52
- // ── Animation lifecycle ──
52
+ // Animation lifecycle
53
53
  const {
54
54
  showChildren,
55
55
  preset
@@ -60,7 +60,7 @@ export const Dialog = /*#__PURE__*/forwardRef(function Dialog({
60
60
  onExitFinish
61
61
  });
62
62
 
63
- // ── Focus wrap ──
63
+ // Focus wrap
64
64
  // Native <dialog>.showModal() traps focus but wraps through <body> at
65
65
  // the boundary (A → B → C → body → A). This hook intercepts Tab to
66
66
  // wrap directly (A → B → C → A), matching the WAI-ARIA APG pattern.
@@ -69,7 +69,7 @@ export const Dialog = /*#__PURE__*/forwardRef(function Dialog({
69
69
  role: 'dialog'
70
70
  });
71
71
 
72
- // ── Open layer observer registration ──
72
+ // Open layer observer registration
73
73
  // Notifies the open layer observer so app-coordination features
74
74
  // (open-count subscriptions) work with top-layer dialogs.
75
75
  useNotifyOpenLayerObserver({
@@ -100,7 +100,7 @@ export const Dialog = /*#__PURE__*/forwardRef(function Dialog({
100
100
  }
101
101
  }, [isOpen]);
102
102
 
103
- // ── Handle native Escape (cancel event) ──
103
+ // Handle native Escape (cancel event)
104
104
  const handleCancel = useCallback(event => {
105
105
  event.preventDefault();
106
106
  onClose({
@@ -108,7 +108,7 @@ export const Dialog = /*#__PURE__*/forwardRef(function Dialog({
108
108
  });
109
109
  }, [onClose]);
110
110
 
111
- // ── Handle backdrop click ──
111
+ // Handle backdrop click
112
112
  // Attached via bind-event-listener rather than a React prop so we avoid
113
113
  // a11y lint suppressions on the <dialog> element.
114
114
  // 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,14 @@
1
+ import { getFocusables } from './get-focusables';
2
+ /**
3
+ * Returns the first focusable element within the container.
4
+ */
5
+ export function getFirstFocusable({
6
+ container,
7
+ filter
8
+ }) {
9
+ const items = getFocusables({
10
+ container,
11
+ filter
12
+ });
13
+ return items.length > 0 ? items[0] : null;
14
+ }
@@ -0,0 +1,19 @@
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({
12
+ container,
13
+ filter
14
+ }) {
15
+ return Array.from(container.querySelectorAll(selectors.focusable)).filter(element => element instanceof HTMLElement).filter(element => isInSameLayer({
16
+ element,
17
+ container
18
+ })).filter(element => !filter || filter(element, container));
19
+ }
@@ -0,0 +1,14 @@
1
+ import { getFocusables } from './get-focusables';
2
+ /**
3
+ * Returns the last focusable element within the container.
4
+ */
5
+ export function getLastFocusable({
6
+ container,
7
+ filter
8
+ }) {
9
+ const items = getFocusables({
10
+ container,
11
+ filter
12
+ });
13
+ return items.length > 0 ? items[items.length - 1] : null;
14
+ }
@@ -0,0 +1,38 @@
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({
12
+ container,
13
+ direction,
14
+ filter
15
+ }) {
16
+ var _all$nextIndex;
17
+ const all = getFocusables({
18
+ container,
19
+ filter
20
+ });
21
+ const current = container.querySelector(selectors.focused);
22
+ if (!(current instanceof HTMLElement)) {
23
+ return null;
24
+ }
25
+ const index = all.indexOf(current);
26
+ if (index === -1) {
27
+ return null;
28
+ }
29
+ const nextIndex = (() => {
30
+ if (direction === 'forwards') {
31
+ return (index + 1) % all.length;
32
+ }
33
+ const proposed = index - 1;
34
+ // if going into negative numbers, loop back to the last item
35
+ return proposed < 0 ? all.length - 1 : proposed;
36
+ })();
37
+ return (_all$nextIndex = all[nextIndex]) !== null && _all$nextIndex !== void 0 ? _all$nextIndex : null;
38
+ }
@@ -0,0 +1,18 @@
1
+ const 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({
8
+ element,
9
+ container
10
+ }) {
11
+ const elementLayer = element.closest(topLayerSelector);
12
+ const containerLayer = container.closest(topLayerSelector);
13
+ // Both elements are in the "document" layer
14
+ if (!elementLayer && !containerLayer) {
15
+ return true;
16
+ }
17
+ return elementLayer === containerLayer;
18
+ }
@@ -0,0 +1,28 @@
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({
10
+ container
11
+ }) {
12
+ var _getDocument;
13
+ const focused = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.activeElement;
14
+ if (!(focused instanceof HTMLElement)) {
15
+ return false;
16
+ }
17
+
18
+ // Cannot be in a nested layer if it is not in the container
19
+ if (!container.contains(focused)) {
20
+ return false;
21
+ }
22
+
23
+ // If not in the same layer, must be in a nested layer
24
+ return !isInSameLayer({
25
+ element: focused,
26
+ container
27
+ });
28
+ }
@@ -0,0 +1,11 @@
1
+ export const selectors = (() => {
2
+ // Common exclusion filter applied to every selector.
3
+ const not = ':not([tabindex="-1"]):not([aria-disabled="true"]):not([aria-hidden="true"])';
4
+ const notDisabled = `:not([disabled])${not}`;
5
+ const focusable = [`a[href]${not}`, `area[href]${not}`, `input${notDisabled}:not([type="hidden"])`, `select${notDisabled}`, `textarea${notDisabled}`, `button${notDisabled}`, `iframe${not}`, `audio[controls]${not}`, `video[controls]${not}`, `[contenteditable]:not([contenteditable="false"])${not}`, `[tabindex]${notDisabled}${not}`];
6
+ return {
7
+ focusable: focusable.join(','),
8
+ // Build the `:focus` selector
9
+ focused: focusable.map(selector => `${selector}:focus`).join(',')
10
+ };
11
+ })();
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
@@ -25,8 +25,8 @@ const DEFAULT_GAP = "var(--ds-space-100, 8px)";
25
25
  * CSS length string (e.g. `token('space.100')`).
26
26
  *
27
27
  * The two offset axes are named for clarity at the call site:
28
- * - `gap` — distance away from the trigger along the placement axis
29
- * - `crossAxisShift` — nudge along the trigger edge (perpendicular to the placement axis)
28
+ * - `gap` - distance away from the trigger along the placement axis
29
+ * - `crossAxisShift` - nudge along the trigger edge (perpendicular to the placement axis)
30
30
  */
31
31
 
32
32
  /**
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Maps a popover content role to the correct `aria-haspopup` value
3
+ * for its trigger element.
4
+ *
5
+ * Returns `undefined` for roles that are not popups in the ARIA sense
6
+ * (`tooltip`, `note`, `status`, `alert`, `log`). Triggers for those roles
7
+ * should not announce a popup at all - emitting `aria-haspopup="dialog"`
8
+ * on a tooltip trigger would mislead assistive technology.
9
+ */
10
+ export function roleToAriaHasPopup({
11
+ role
12
+ }) {
13
+ if (role === 'menu') {
14
+ return 'menu';
15
+ }
16
+ if (role === 'listbox') {
17
+ return 'listbox';
18
+ }
19
+ if (role === 'tree') {
20
+ return 'tree';
21
+ }
22
+ if (role === 'grid') {
23
+ return 'grid';
24
+ }
25
+ if (role === 'dialog' || role === 'alertdialog') {
26
+ return 'dialog';
27
+ }
28
+ // Non-popup roles (tooltip, note, status, alert, log) and the
29
+ // no-role case: omit `aria-haspopup` entirely. React drops the
30
+ // attribute when the value is `undefined`.
31
+ return undefined;
32
+ }