@atlaskit/top-layer 0.12.1 → 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 (90) hide show
  1. package/CHANGELOG.md +7 -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/internal/ensure-preset-styles.js +1 -1
  6. package/dist/cjs/internal/reduced-motion.js +1 -1
  7. package/dist/cjs/internal/resolve-placement.js +2 -2
  8. package/dist/cjs/internal/role-types.js +1 -1
  9. package/dist/cjs/internal/slot.js +3 -3
  10. package/dist/cjs/internal/use-anchor-position.js +15 -30
  11. package/dist/cjs/internal/use-animated-visibility.js +10 -10
  12. package/dist/cjs/internal/use-animation-preset.js +1 -1
  13. package/dist/cjs/internal/use-preset-styles.js +1 -1
  14. package/dist/cjs/internal/use-width-from-anchor.js +4 -4
  15. package/dist/cjs/popover/create-close-event.js +1 -1
  16. package/dist/cjs/popover/popover.js +3 -3
  17. package/dist/cjs/popup/popup-content.js +4 -4
  18. package/dist/cjs/testing/polyfill.js +8 -8
  19. package/dist/cjs/testing/to-be-visible.js +5 -5
  20. package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +19 -12
  21. package/dist/cjs/use-simple-light-dismiss/index.js +3 -3
  22. package/dist/es2019/animations/presets.js +5 -5
  23. package/dist/es2019/dialog/create-close-event.js +1 -1
  24. package/dist/es2019/dialog/dialog-content.js +5 -5
  25. package/dist/es2019/internal/ensure-preset-styles.js +1 -1
  26. package/dist/es2019/internal/reduced-motion.js +1 -1
  27. package/dist/es2019/internal/resolve-placement.js +2 -2
  28. package/dist/es2019/internal/role-types.js +1 -1
  29. package/dist/es2019/internal/slot.js +3 -3
  30. package/dist/es2019/internal/use-anchor-position.js +13 -16
  31. package/dist/es2019/internal/use-animated-visibility.js +10 -10
  32. package/dist/es2019/internal/use-animation-preset.js +1 -1
  33. package/dist/es2019/internal/use-preset-styles.js +1 -1
  34. package/dist/es2019/internal/use-width-from-anchor.js +4 -4
  35. package/dist/es2019/popover/create-close-event.js +1 -1
  36. package/dist/es2019/popover/popover.js +3 -3
  37. package/dist/es2019/popup/popup-content.js +4 -4
  38. package/dist/es2019/testing/polyfill.js +8 -8
  39. package/dist/es2019/testing/to-be-visible.js +5 -5
  40. package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +19 -12
  41. package/dist/es2019/use-simple-light-dismiss/index.js +3 -3
  42. package/dist/esm/animations/presets.js +5 -5
  43. package/dist/esm/dialog/create-close-event.js +1 -1
  44. package/dist/esm/dialog/dialog-content.js +5 -5
  45. package/dist/esm/internal/ensure-preset-styles.js +1 -1
  46. package/dist/esm/internal/reduced-motion.js +1 -1
  47. package/dist/esm/internal/resolve-placement.js +2 -2
  48. package/dist/esm/internal/role-types.js +1 -1
  49. package/dist/esm/internal/slot.js +3 -3
  50. package/dist/esm/internal/use-anchor-position.js +15 -30
  51. package/dist/esm/internal/use-animated-visibility.js +10 -10
  52. package/dist/esm/internal/use-animation-preset.js +1 -1
  53. package/dist/esm/internal/use-preset-styles.js +1 -1
  54. package/dist/esm/internal/use-width-from-anchor.js +4 -4
  55. package/dist/esm/popover/create-close-event.js +1 -1
  56. package/dist/esm/popover/popover.js +3 -3
  57. package/dist/esm/popup/popup-content.js +4 -4
  58. package/dist/esm/testing/polyfill.js +8 -8
  59. package/dist/esm/testing/to-be-visible.js +5 -5
  60. package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +19 -12
  61. package/dist/esm/use-simple-light-dismiss/index.js +3 -3
  62. package/dist/types/dialog/create-close-event.d.ts +1 -1
  63. package/dist/types/dialog/types.d.ts +8 -0
  64. package/dist/types/internal/reduced-motion.d.ts +1 -1
  65. package/dist/types/internal/resolve-placement.d.ts +2 -2
  66. package/dist/types/internal/slot.d.ts +4 -4
  67. package/dist/types/internal/use-animated-visibility.d.ts +3 -3
  68. package/dist/types/internal/use-animation-preset.d.ts +1 -1
  69. package/dist/types/internal/use-preset-styles.d.ts +1 -1
  70. package/dist/types/internal/use-width-from-anchor.d.ts +2 -2
  71. package/dist/types/popover/create-close-event.d.ts +1 -1
  72. package/dist/types/popover/popover.d.ts +1 -1
  73. package/dist/types/popup/popup-context.d.ts +1 -1
  74. package/dist/types/testing/to-be-visible.d.ts +3 -3
  75. package/dist/types/use-simple-light-dismiss/index.d.ts +1 -1
  76. package/dist/types-ts4.5/dialog/create-close-event.d.ts +1 -1
  77. package/dist/types-ts4.5/dialog/types.d.ts +8 -0
  78. package/dist/types-ts4.5/internal/reduced-motion.d.ts +1 -1
  79. package/dist/types-ts4.5/internal/resolve-placement.d.ts +2 -2
  80. package/dist/types-ts4.5/internal/slot.d.ts +4 -4
  81. package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +3 -3
  82. package/dist/types-ts4.5/internal/use-animation-preset.d.ts +1 -1
  83. package/dist/types-ts4.5/internal/use-preset-styles.d.ts +1 -1
  84. package/dist/types-ts4.5/internal/use-width-from-anchor.d.ts +2 -2
  85. package/dist/types-ts4.5/popover/create-close-event.d.ts +1 -1
  86. package/dist/types-ts4.5/popover/popover.d.ts +1 -1
  87. package/dist/types-ts4.5/popup/popup-context.d.ts +1 -1
  88. package/dist/types-ts4.5/testing/to-be-visible.d.ts +3 -3
  89. package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +1 -1
  90. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/top-layer
2
2
 
3
+ ## 0.12.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7210e88c14f95`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7210e88c14f95) -
8
+ Internal: align package with house authoring rules (style-only refactors).
9
+
3
10
  ## 0.12.1
4
11
 
5
12
  ### Patch Changes
@@ -9,7 +9,7 @@ exports.fade = fade;
9
9
  exports.scaleAndFade = scaleAndFade;
10
10
  exports.slideAndFade = slideAndFade;
11
11
  var _resolvePlacement = require("../internal/resolve-placement");
12
- // ── slideAndFade ──
12
+ // slideAndFade
13
13
 
14
14
  function getSlideAndFadeProperties(_ref) {
15
15
  var placement = _ref.placement,
@@ -91,7 +91,7 @@ function slideAndFade(options) {
91
91
  };
92
92
  }
93
93
 
94
- // ── fade ──
94
+ // fade
95
95
 
96
96
  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";
97
97
 
@@ -117,7 +117,7 @@ function fade() {
117
117
  };
118
118
  }
119
119
 
120
- // ── scaleAndFade ──
120
+ // scaleAndFade
121
121
 
122
122
  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";
123
123
 
@@ -147,7 +147,7 @@ function scaleAndFade() {
147
147
  // Dialog presets
148
148
  // ══════════════════════════════════════════════════════════════════════════════
149
149
 
150
- // ── dialogSlideUpAndFade ──
150
+ // dialogSlideUpAndFade
151
151
 
152
152
  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";
153
153
 
@@ -183,7 +183,7 @@ function dialogSlideUpAndFade(options) {
183
183
  };
184
184
  }
185
185
 
186
- // ── dialogFade ──
186
+ // dialogFade
187
187
 
188
188
  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";
189
189
 
@@ -8,7 +8,7 @@ exports.createCloseEvent = createCloseEvent;
8
8
  * Creates a synthetic DOM event from a `TDialogCloseReason`.
9
9
  *
10
10
  * Useful when bridging the Dialog primitive's `onClose({ reason })` callback
11
- * to a legacy API that expects a `KeyboardEvent` or `MouseEvent` — for example,
11
+ * to a legacy API that expects a `KeyboardEvent` or `MouseEvent` - for example,
12
12
  * `@atlaskit/modal-dialog`'s `onClose(event, analyticsEvent)` contract.
13
13
  *
14
14
  * - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
@@ -58,7 +58,7 @@ var Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(function Dialo
58
58
  var ownRef = (0, _react.useRef)(null);
59
59
  var combinedRef = (0, _mergeRefs.default)([ownRef, ref]);
60
60
 
61
- // ── Animation lifecycle ──
61
+ // Animation lifecycle
62
62
  var _useAnimatedVisibilit = (0, _useAnimatedVisibility.useAnimatedVisibility)({
63
63
  isOpen: isOpen,
64
64
  animate: animate,
@@ -68,7 +68,7 @@ var Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(function Dialo
68
68
  showChildren = _useAnimatedVisibilit.showChildren,
69
69
  preset = _useAnimatedVisibilit.preset;
70
70
 
71
- // ── Focus wrap ──
71
+ // Focus wrap
72
72
  // Native <dialog>.showModal() traps focus but wraps through <body> at
73
73
  // the boundary (A → B → C → body → A). This hook intercepts Tab to
74
74
  // wrap directly (A → B → C → A), matching the WAI-ARIA APG pattern.
@@ -77,7 +77,7 @@ var Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(function Dialo
77
77
  role: 'dialog'
78
78
  });
79
79
 
80
- // ── Open layer observer registration ──
80
+ // Open layer observer registration
81
81
  // Notifies the open layer observer so app-coordination features
82
82
  // (open-count subscriptions) work with top-layer dialogs.
83
83
  (0, _openLayerObserver.useNotifyOpenLayerObserver)({
@@ -108,7 +108,7 @@ var Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(function Dialo
108
108
  }
109
109
  }, [isOpen]);
110
110
 
111
- // ── Handle native Escape (cancel event) ──
111
+ // Handle native Escape (cancel event)
112
112
  var handleCancel = (0, _react.useCallback)(function (event) {
113
113
  event.preventDefault();
114
114
  onClose({
@@ -116,7 +116,7 @@ var Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(function Dialo
116
116
  });
117
117
  }, [onClose]);
118
118
 
119
- // ── Handle backdrop click ──
119
+ // Handle backdrop click
120
120
  // Attached via bind-event-listener rather than a React prop so we avoid
121
121
  // a11y lint suppressions on the <dialog> element.
122
122
  // Keyboard dismiss is already handled natively (Escape → onCancel above).
@@ -10,7 +10,7 @@ exports.ensurePresetStyles = ensurePresetStyles;
10
10
  * Each preset's CSS is injected at most once into `<head>`.
11
11
  * Shared by both PopoverContent and DialogContent.
12
12
  *
13
- * Note: injected `<style>` elements and the tracking Set are append-only —
13
+ * Note: injected `<style>` elements and the tracking Set are append-only -
14
14
  * they are never removed. This is intentional: the number of distinct
15
15
  * presets is bounded (handful of animation presets), so the
16
16
  * memory footprint is negligible. Removing styles would risk breaking
@@ -13,7 +13,7 @@ var _once = _interopRequireDefault(require("@atlaskit/ds-lib/once"));
13
13
  *
14
14
  * The result is cached after the first call via `once`. This avoids
15
15
  * calling `matchMedia` on every render. The trade-off is that if a user
16
- * toggles the OS reduced-motion setting mid-session, the change won't
16
+ * toggles the OS reduced-motion setting mid-session, the change will not
17
17
  * take effect until the next page load. This is acceptable because
18
18
  * toggling this system-level preference mid-session is extremely rare,
19
19
  * and a page refresh is a reasonable expectation for system accessibility
@@ -30,8 +30,8 @@ var DEFAULT_GAP = "var(--ds-space-100, 8px)";
30
30
  * CSS length string (e.g. `token('space.100')`).
31
31
  *
32
32
  * The two offset axes are named for clarity at the call site:
33
- * - `gap` — distance away from the trigger along the placement axis
34
- * - `crossAxisShift` — nudge along the trigger edge (perpendicular to the placement axis)
33
+ * - `gap` - distance away from the trigger along the placement axis
34
+ * - `crossAxisShift` - nudge along the trigger edge (perpendicular to the placement axis)
35
35
  */
36
36
 
37
37
  /**
@@ -29,7 +29,7 @@ exports.shouldFocusIntoPopover = shouldFocusIntoPopover;
29
29
  * (e.g. a combobox labels its listbox, tooltip content IS the accessible name).
30
30
  */
31
31
 
32
- // ── Shared ARIA role discrimination types ──
32
+ // Shared ARIA role discrimination types
33
33
  //
34
34
  // These encode the WCAG 4.1.2 constraint: roles like `dialog`, `alertdialog`,
35
35
  // and `menu` MUST have an accessible name (either `label` or `labelledBy`).
@@ -32,14 +32,14 @@ function isSlotChild(child) {
32
32
  * Merges props (including ref) onto a single React element child.
33
33
  *
34
34
  * A safer alternative to raw `cloneElement` that:
35
- * 1. Guards with `isValidElement` — non-element children (strings,
35
+ * 1. Guards with `isValidElement` - non-element children (strings,
36
36
  * fragments, null) are returned as-is instead of crashing.
37
37
  * 2. Merges refs via `mergeRefs` so both the caller's ref and the
38
38
  * child's existing ref are honoured.
39
39
  * 3. Spreads any additional props (ARIA attributes, event handlers, etc.)
40
40
  * onto the child element.
41
41
  *
42
- * Event handlers (e.g. `onClick`) are **not** auto-merged — the caller's
42
+ * Event handlers (e.g. `onClick`) are **not** auto-merged - the caller's
43
43
  * handler replaces the child's. Compose handlers before passing them in.
44
44
  *
45
45
  * @example
@@ -52,7 +52,7 @@ function isSlotChild(child) {
52
52
  var Slot = exports.Slot = /*#__PURE__*/(0, _react.forwardRef)(function Slot(slotProps, ref) {
53
53
  var rawChildren = slotProps.children,
54
54
  props = (0, _objectWithoutProperties2.default)(slotProps, _excluded);
55
- // `SlotProps` intersects `Record<string, unknown>`, so `children` is typed as `unknown`.
55
+ // `TSlotProps` intersects `Record<string, unknown>`, so `children` is typed as `unknown`.
56
56
  var children = rawChildren;
57
57
  if (!isSlotChild(children)) {
58
58
  return children;
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.useAnchorPosition = useAnchorPosition;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
8
  var _react = require("react");
11
9
  var _bindEventListener = require("bind-event-listener");
12
10
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
@@ -37,25 +35,15 @@ var _setStyle = require("./set-style");
37
35
  // from `./resolve-placement` so search-and-jump lands at the source of truth.
38
36
 
39
37
  /**
40
- * Module-scope no-op `ResizeObserver` used in non-DOM jest environments where
38
+ * Module-scope no-op `ResizeObserver` stub used in non-DOM jest environments where
41
39
  * `ResizeObserver` is `undefined`. Hoisted out of the effect to avoid
42
- * allocating a new class declaration on every run.
40
+ * re-allocating on every run.
43
41
  */
44
- var NoopResizeObserver = /*#__PURE__*/function () {
45
- function NoopResizeObserver() {
46
- (0, _classCallCheck2.default)(this, NoopResizeObserver);
47
- }
48
- return (0, _createClass2.default)(NoopResizeObserver, [{
49
- key: "observe",
50
- value: function observe() {}
51
- }, {
52
- key: "unobserve",
53
- value: function unobserve() {}
54
- }, {
55
- key: "disconnect",
56
- value: function disconnect() {}
57
- }]);
58
- }();
42
+ var noopResizeObserver = {
43
+ observe: function observe() {},
44
+ unobserve: function unobserve() {},
45
+ disconnect: function disconnect() {}
46
+ };
59
47
 
60
48
  /**
61
49
  * Returns true when the popover is currently open. Wrapped because the
@@ -345,7 +333,7 @@ function useAnchorPosition(_ref3) {
345
333
  return _undoPositioning;
346
334
  }
347
335
 
348
- // ── JS fallback ──
336
+ // JS fallback
349
337
  // The popover is already in the browser's top layer via popover="auto",
350
338
  // so it does not need position:fixed. We only reset the UA defaults
351
339
  // (inset: 0; margin: auto) and set top/left based on measurements.
@@ -414,20 +402,17 @@ function useAnchorPosition(_ref3) {
414
402
  // Self-disconnects after one valid measurement; ongoing
415
403
  // scroll/resize is handled by the window listeners below.
416
404
  // `ResizeObserver` is missing in some non-DOM jest environments
417
- // (e.g. post-office's `node` environment). Fall back to a no-op
418
- // observer there. The scroll/resize listeners below still keep
419
- // the popover positioned in the rare case the consumer also
420
- // polyfilled `showPopover` but not `ResizeObserver`. Real
421
- // browsers always have it. The `NoopResizeObserver` class is
422
- // hoisted to module scope (see top of file) so we do not allocate
423
- // a new constructor on every effect run.
424
- var ResizeObserverImpl = typeof ResizeObserver !== 'undefined' ? ResizeObserver : NoopResizeObserver;
425
- var resizeObserver = new ResizeObserverImpl(function () {
405
+ // (e.g. post-office's `node` environment). Fall back to the
406
+ // module-scope `noopResizeObserver` stub there. The scroll/resize
407
+ // listeners below still keep the popover positioned in the rare
408
+ // case the consumer also polyfilled `showPopover` but not
409
+ // `ResizeObserver`. Real browsers always have it.
410
+ var resizeObserver = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(function () {
426
411
  if (popover.offsetWidth > 0 && popover.offsetHeight > 0) {
427
412
  update();
428
413
  resizeObserver.disconnect();
429
414
  }
430
- });
415
+ }) : noopResizeObserver;
431
416
 
432
417
  // If the popover is already open by the time this effect runs (for
433
418
  // example, the parent `useAnchorPosition` effect runs after the child
@@ -15,19 +15,19 @@ var _usePresetStyles = require("./use-preset-styles");
15
15
  *
16
16
  * Used by both `Popover` and `Dialog` to share the same animation lifecycle
17
17
  * logic. Those components own their own show/hide mechanisms (showPopover /
18
- * hidePopover vs showModal / close) and event handling — this hook only
18
+ * hidePopover vs showModal / close) and event handling - this hook only
19
19
  * manages the relationship between `isOpen` and when children are rendered.
20
20
  *
21
21
  * ## Problem
22
22
  *
23
23
  * We want to delay the unmount of children until a CSS exit transition has
24
24
  * finished playing. If we unmount children the moment `isOpen` becomes
25
- * `false`, the exit animation is never visible — the content just disappears.
25
+ * `false`, the exit animation is never visible - the content just disappears.
26
26
  *
27
27
  * ## How it works
28
28
  *
29
29
  * `showChildren` tracks whether the consumer's children should be in the DOM.
30
- * It does not mirror `isOpen` exactly — it intentionally lags behind during
30
+ * It does not mirror `isOpen` exactly - it intentionally lags behind during
31
31
  * exit animations:
32
32
  *
33
33
  * ```
@@ -63,12 +63,12 @@ function useAnimatedVisibility(_ref) {
63
63
  // or the user has enabled the "prefers reduced motion" OS setting.
64
64
  var willAnimate = Boolean(animate) && !(0, _reducedMotion.prefersReducedMotion)();
65
65
 
66
- // ── showChildren state ──
66
+ // showChildren state
67
67
  //
68
68
  // This is the core of the hook. `showChildren` controls whether the
69
69
  // consumer's children are in the DOM. The two `if` blocks below are
70
70
  // intentionally written as synchronous state updates during render
71
- // (React supports this pattern — setState during render is treated as
71
+ // (React supports this pattern - setState during render is treated as
72
72
  // a synchronous re-render before the browser paints).
73
73
  //
74
74
  // Mount path: isOpen went true but showChildren is still false → mount.
@@ -95,7 +95,7 @@ function useAnimatedVisibility(_ref) {
95
95
  var onExitFinishRef = (0, _react.useRef)(onExitFinish);
96
96
  onExitFinishRef.current = onExitFinish;
97
97
 
98
- // ── Animated entry effect ──
98
+ // Animated entry effect
99
99
  //
100
100
  // Fires `onEnterFinish` after the entry transition completes.
101
101
  // When there is no animation, fires it immediately via a separate effect.
@@ -144,7 +144,7 @@ function useAnimatedVisibility(_ref) {
144
144
  };
145
145
  }, [isOpen, showChildren, willAnimate, preset === null || preset === void 0 ? void 0 : preset.enterDurationMs, elementRef]);
146
146
 
147
- // ── Non-animated entry callback ──
147
+ // Non-animated entry callback
148
148
  //
149
149
  // When there is no animation, fire `onEnterFinish` immediately on mount and after `isOpen` goes false->true.
150
150
  // The initial value is false to make sure it fires on mount if the current `isOpen` is true.
@@ -158,7 +158,7 @@ function useAnimatedVisibility(_ref) {
158
158
  }
159
159
  }, [isOpen, willAnimate]);
160
160
 
161
- // ── Animated exit effect ──
161
+ // Animated exit effect
162
162
  //
163
163
  // Runs when all three conditions are true:
164
164
  // • `isOpen` is false (consumer wants to close)
@@ -221,10 +221,10 @@ function useAnimatedVisibility(_ref) {
221
221
  };
222
222
  }, [isOpen, showChildren, willAnimate, preset === null || preset === void 0 ? void 0 : preset.exitDurationMs, elementRef]);
223
223
 
224
- // ── Non-animated exit callback ──
224
+ // Non-animated exit callback
225
225
  //
226
226
  // When there is no animation, children unmount synchronously (handled
227
- // by the `if` block above). But `onExitFinish` still needs to fire —
227
+ // by the `if` block above). But `onExitFinish` still needs to fire -
228
228
  // we do that in a follow-up effect so the consumer can react to it.
229
229
  //
230
230
  // Uses a previous-value ref (`wasOpenRef`) to detect the exact
@@ -9,7 +9,7 @@ var _ensurePresetStyles = require("./ensure-preset-styles");
9
9
  /**
10
10
  * Normalizes the `animate` prop to a preset (or null) and ensures its CSS
11
11
  * is injected once into document.head. Used by PopupContent, Popover, and
12
- * DialogContent so they don't duplicate this logic.
12
+ * DialogContent so they do not duplicate this logic.
13
13
  */
14
14
  function useAnimationPreset(animate) {
15
15
  var preset = animate != null && animate !== false ? animate : null;
@@ -10,7 +10,7 @@ var _ensurePresetStyles = require("./ensure-preset-styles");
10
10
  * Normalizes a preset prop to a value (or null) and ensures its CSS
11
11
  * is injected once into `document.head`.
12
12
  *
13
- * Works with any preset that has `{ css, name }` — animation presets
13
+ * Works with any preset that has `{ css, name }` - animation presets
14
14
  * (TAnimationPreset) satisfies this shape.
15
15
  */
16
16
  function usePresetStyles(_ref) {
@@ -9,8 +9,8 @@ var _setStyle = require("./set-style");
9
9
  /**
10
10
  * Sets the width of a popover element relative to its anchor element.
11
11
  *
12
- * - `'match-anchor'` → `width: anchor-size(width)` — popover matches anchor width exactly.
13
- * - `'min-anchor'` → `min-width: anchor-size(width)` — popover is at least as wide as anchor,
12
+ * - `'match-anchor'` → `width: anchor-size(width)` - popover matches anchor width exactly.
13
+ * - `'min-anchor'` → `min-width: anchor-size(width)` - popover is at least as wide as anchor,
14
14
  * but can grow wider.
15
15
  * - `'none'` → no explicit width is set (default behaviour)
16
16
  *
@@ -35,7 +35,7 @@ function useWidthFromAnchor(_ref) {
35
35
  var supportsAnchorSize = typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('width', 'anchor-size(width)');
36
36
  if (mode === 'match-anchor') {
37
37
  // Set an exact width matching the anchor.
38
- // `min-inline-size` is intentionally NOT set here — it would override the
38
+ // `min-inline-size` is intentionally NOT set here - it would override the
39
39
  // explicit width constraint, allowing the popover to grow past the anchor's width.
40
40
  if (supportsAnchorSize) {
41
41
  return (0, _setStyle.setStyle)({
@@ -91,7 +91,7 @@ function useWidthFromAnchor(_ref) {
91
91
  });
92
92
  }
93
93
 
94
- // No anchor available in JS fallback — still apply min-inline-size.
94
+ // No anchor available in JS fallback - still apply min-inline-size.
95
95
  return (0, _setStyle.setStyle)({
96
96
  el: node,
97
97
  styles: [minInlineSizeStyle]
@@ -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
  //
@@ -97,7 +97,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
97
97
  // Note: onOpenChange composition is handled by handleOpenChange below,
98
98
  // which also adds nested-popover focus restoration.
99
99
 
100
- // ── Sync aria-haspopup on the trigger with the content's role ──
100
+ // Sync aria-haspopup on the trigger with the content's role
101
101
  var setAriaHasPopup = ctx === null || ctx === void 0 ? void 0 : ctx.setAriaHasPopup;
102
102
  (0, _react.useLayoutEffect)(function () {
103
103
  setAriaHasPopup === null || setAriaHasPopup === void 0 || setAriaHasPopup((0, _roleTypes.roleToAriaHasPopup)({
@@ -105,7 +105,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
105
105
  }));
106
106
  }, [role, setAriaHasPopup]);
107
107
 
108
- // ── Focus restoration ──
108
+ // Focus restoration
109
109
  // The native Popover API handles focus restoration automatically for
110
110
  // popover="auto" and popover="hint":
111
111
  // - Escape → restores focus to the previously focused element (the trigger)
@@ -132,7 +132,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
132
132
  }
133
133
  consumerOnOpenChange === null || consumerOnOpenChange === void 0 || consumerOnOpenChange(args);
134
134
 
135
- // ── Nested popover focus restoration fallback ──
135
+ // Nested popover focus restoration fallback
136
136
  // The browser only captures `previouslyFocusedElement` for the
137
137
  // outermost popover="auto" in the stack. Inner (nested) popovers
138
138
  // have shouldRestoreFocus=false, so the browser will not restore
@@ -161,7 +161,7 @@ var PopupContent = exports.PopupContent = /*#__PURE__*/(0, _react.forwardRef)(fu
161
161
  }
162
162
  }, [consumerOnOpenChange, triggerRef, role, setPopupState, willAnimate]);
163
163
 
164
- // ── Anchor positioning ──
164
+ // Anchor positioning
165
165
  // Compose useAnchorPosition with Popover. The hook positions the popover
166
166
  // relative to the trigger element via CSS Anchor Positioning (with JS fallback).
167
167
  // 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
  }
@@ -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
  }