@atlaskit/dropdown-menu 16.8.9 → 16.8.11

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 (33) hide show
  1. package/CHANGELOG.md +203 -0
  2. package/dist/cjs/dropdown-menu-top-layer.compiled.css +10 -0
  3. package/dist/cjs/dropdown-menu-top-layer.js +347 -0
  4. package/dist/cjs/dropdown-menu.js +62 -8
  5. package/dist/cjs/internal/components/group-title.js +6 -1
  6. package/dist/cjs/internal/use-arrow-navigation/index.js +25 -0
  7. package/dist/cjs/internal/use-arrow-navigation/use-arrow-navigation.js +18 -0
  8. package/dist/es2019/dropdown-menu-top-layer.compiled.css +10 -0
  9. package/dist/es2019/dropdown-menu-top-layer.js +323 -0
  10. package/dist/es2019/dropdown-menu.js +59 -9
  11. package/dist/es2019/internal/components/group-title.js +6 -1
  12. package/dist/es2019/internal/use-arrow-navigation/index.js +2 -0
  13. package/dist/es2019/internal/use-arrow-navigation/use-arrow-navigation.js +1 -0
  14. package/dist/esm/dropdown-menu-top-layer.compiled.css +10 -0
  15. package/dist/esm/dropdown-menu-top-layer.js +338 -0
  16. package/dist/esm/dropdown-menu.js +62 -8
  17. package/dist/esm/internal/components/group-title.js +6 -1
  18. package/dist/esm/internal/use-arrow-navigation/index.js +2 -0
  19. package/dist/esm/internal/use-arrow-navigation/use-arrow-navigation.js +1 -0
  20. package/dist/types/dropdown-menu-top-layer.d.ts +18 -0
  21. package/dist/types/dropdown-menu.d.ts +1 -1
  22. package/dist/types/internal/components/group-title.d.ts +6 -1
  23. package/dist/types/internal/use-arrow-navigation/index.d.ts +2 -0
  24. package/dist/types/internal/use-arrow-navigation/use-arrow-navigation.d.ts +1 -0
  25. package/dist/types/types.d.ts +20 -0
  26. package/dist/types-ts4.5/dropdown-menu-top-layer.d.ts +18 -0
  27. package/dist/types-ts4.5/dropdown-menu.d.ts +1 -1
  28. package/dist/types-ts4.5/internal/components/group-title.d.ts +6 -1
  29. package/dist/types-ts4.5/internal/use-arrow-navigation/index.d.ts +2 -0
  30. package/dist/types-ts4.5/internal/use-arrow-navigation/use-arrow-navigation.d.ts +1 -0
  31. package/dist/types-ts4.5/types.d.ts +20 -0
  32. package/package.json +21 -16
  33. package/offerings.json +0 -36
package/CHANGELOG.md CHANGED
@@ -1,5 +1,208 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 16.8.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7250582895c0b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7250582895c0b) -
8
+ Top-layer adoption work behind the `platform-dst-top-layer` feature flag. Public adopter APIs are
9
+ intentionally kept narrow while the top-layer API surface settles, with one exception called out
10
+ below.
11
+
12
+ Highlights:
13
+ - Pass the full `[along, away]` legacy popper offset through to the new top-layer
14
+ `placement.offset` API (via `fromLegacyPlacement`). Previously only the `away` axis was
15
+ forwarded, which dropped the `along` offset for consumers of `Popup`, `PopupSelect`,
16
+ `Spotlight`, and `Tooltip` when `platform-dst-top-layer` is enabled.
17
+ - Fix broken import of `dialogHeight` and `dialogWidth` from the removed utils module in
18
+ `@atlaskit/modal-dialog`.
19
+
20
+ Public API:
21
+ - **`@atlaskit/tooltip`** (`minor`): add an optional `testId?: string` field to `TriggerProps`.
22
+ This is additive (no existing prop changes shape). Required because `@atlaskit/button/new` (and
23
+ other `Pressable`-backed primitives) overwrite `data-testid` from spread, so the legacy
24
+ `(triggerProps as any)['data-testid']` workaround is silently absorbed by those consumers. A
25
+ typed `testId` field flows through their own `testId` destructure instead, restoring
26
+ `data-testid` propagation onto the rendered trigger element.
27
+ - **`@atlaskit/popup`**, **`@atlaskit/dropdown-menu`** (`patch`): no public type changes. Wider
28
+ `aria-haspopup` unions that the FF-on path produces are bridged at the package boundary into
29
+ `@atlaskit/top-layer` with localised `FUDGE(top-layer-api)` casts, documented in
30
+ `packages/design-system/top-layer/notes/decisions/migration-roadmap.md` ("Open API decisions
31
+ deferred to a follow-up PR"). They will be widened in a follow-up `minor` PR once the top-layer
32
+ API is committed.
33
+ - **`@atlaskit/modal-dialog`**, **`@atlaskit/select`**, **`@atlaskit/spotlight`**
34
+ (`patch`/`minor`): no public type changes; bug fixes only.
35
+
36
+ Merge-readiness fixes (FF-on test wiring + adopter behavior):
37
+ - **`@atlaskit/popup`** (`minor`): wire the compositional `PopupContent` to delegate to
38
+ `PopupContentTopLayer` when `platform-dst-top-layer` is enabled. Previously only the legacy
39
+ `Popup` component had the FF branch, leaving consumers of the compositional API on the legacy
40
+ popper path.
41
+ - **`@atlaskit/select`** (`minor`): add an `onClick` handler to the `PopupSelect` top-layer
42
+ trigger so clicks open/close the menu (mirrors the legacy global click handler in
43
+ `popup-select.tsx`). Add explicit Escape handling on the menu's `onKeyDown` so the menu closes
44
+ and focus returns to the trigger.
45
+ - **`@atlaskit/top-layer`** (`patch`): the `<dialog>` rendered by the Dialog primitive now sets
46
+ `aria-modal="true"` explicitly. Modern browsers infer modal semantics from `.showModal()` but
47
+ some assistive tech still keys off the explicit attribute.
48
+ - **`@atlaskit/top-layer`** (`patch`): guard `use-anchor-positioning` against environments where
49
+ `ResizeObserver` is not defined (e.g. jest's `node` environment, used by the post-office test
50
+ suite). The observer is used to wait for the popover's first valid layout before measuring;
51
+ consumers in non-DOM jest environments now get a no-op observer and the scroll/resize listeners
52
+ still apply if the host environment polyfills `showPopover`. Real browsers always have
53
+ `ResizeObserver`.
54
+ - **`@atlaskit/modal-dialog`** (`patch`): on the FF-on path, drop the `tabIndex={-1}` (and unused
55
+ `:focus-visible` outline) from the modal content wrapper. The native `<dialog>.showModal()`
56
+ focus-delegate algorithm picks the first focusable descendant (including `tabindex=-1`), and the
57
+ wrapper was hijacking initial focus from the close button. Also honor `shouldReturnFocus={ref}`
58
+ on the FF-on path (an unmount-cleanup focuses the ref after `dialog.close()` so it overrides the
59
+ browser's automatic return-to-trigger). Boolean `shouldReturnFocus={false}` is not yet honored
60
+ on the FF-on path — see `top-layer/notes/merge-blockers.md`.
61
+ - **`@atlaskit/datetime-picker`** (`patch`): on the FF-on path, set `mode="manual"` on the
62
+ `Popup.Content` rendered by both `internal/menu-top-layer.tsx` (date-picker calendar) and
63
+ `internal/fixed-layer-menu-top-layer.tsx` (time-picker menu). With the default `mode="auto"`,
64
+ the same click event that opens the menu (which targets the react-select combobox input —
65
+ outside the popover element) bubbles to the browser's native popover light-dismiss handler and
66
+ immediately closes the menu. react-select / DateTimePicker already own outside-click and Esc
67
+ dismissal via their own state, so opting out of the native auto-dismiss is the correct
68
+ integration. Also extend the existing Esc → trigger-focus restoration in
69
+ `components/date-picker.tsx` to the FF-on path (manual mode disables the browser's built-in
70
+ focus return, and the legacy code path was already handling this for itself behind an FF
71
+ negation).
72
+ - **`@atlaskit/popup`** (no public API change): no source changes — only FF-on Playwright
73
+ spec/example fixes drove the suite from 21/3/2 to 27/0/0. Notable: the two `test.fixme`'d
74
+ nested-popover cases were not browser limitations; `popover="auto"` chains correctly via DOM
75
+ ancestry (the original fixmes had the wrong testId selector). Added `testId` props to two
76
+ examples (`16-popup-with-a11y-props`, `18-should-fit-container`) so default-shape tests can
77
+ reach the trigger.
78
+ - Test alignment for FF-on Playwright suites across `popup`, `select`, `datetime-picker`,
79
+ `inline-dialog`, `inline-message`, and `modal-dialog`: selector updates to match the new
80
+ top-layer testId convention (`${testId}--content`, `[role="dialog"][aria-label="calendar"]`),
81
+ per-spec `skipAxeCheck()` for example-level color-contrast violations unrelated to the
82
+ migration, and focus assertions adjusted to match native `<dialog>` / `Popup.Content` auto-focus
83
+ semantics (focus lands on the first focusable child, not the dialog container itself).
84
+ - **`@atlassian/capacity-planning-capacity-graph`**, **`@atlaskit/color-picker`**,
85
+ **`@atlassian/timeline-table`**, **`@atlassian/global-side-navigation`** (`patch`): scope `fg`
86
+ mocks in unit tests so `platform-dst-top-layer` returns `false`. JSDOM does not implement the
87
+ native Popover API (`showPopover`/`hidePopover`/`toggle` events), so leaving the gate ON in unit
88
+ tests caused popover content to remain in the DOM after close and broke close-behaviour
89
+ assertions. Browser coverage for the FF-on path is provided by the Playwright suites listed
90
+ above.
91
+ - **`@atlaskit/dropdown-menu`** (no public API change): test/example-only fixes for the FF-on
92
+ Playwright suite. Added `role="menuitem"` to the nested-trigger `ButtonItem` in
93
+ `examples/93-testing-nested-keyboard-navigation-top-layer.tsx` to satisfy axe's
94
+ `aria-required-children` rule on the parent menu. Added a `test.beforeEach(skipAxeCheck)` to
95
+ `dropdown-menu.spec.tsx` (FF-on suite) for example-level `color-contrast` violations on the
96
+ pre-existing `color.text.selected`/`color.background.selected` token pair (3.91:1). Replaced a
97
+ deadlocking `await expect(moveItem).not.toBeFocused()` pre-open assertion (Playwright's
98
+ auto-wait blocks 5s on the absent element) with `await expect(moveItem).not.toBeVisible()`.
99
+ Suite result: 22/22 passing.
100
+
101
+ - Updated dependencies
102
+
103
+ ## 16.8.10
104
+
105
+ ### Patch Changes
106
+
107
+ - [`1f9114700d351`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1f9114700d351) -
108
+ Moved new motion changes from `platform-dst-motion-uplift` feature gate to
109
+ `platform-dst-motion-uplift-popup`
110
+ - [`2bed6255731de`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2bed6255731de) -
111
+ Top-layer adoption work behind the `platform-dst-top-layer` feature flag. Public adopter APIs are
112
+ intentionally kept narrow while the top-layer API surface settles, with one exception called out
113
+ below.
114
+
115
+ Highlights:
116
+ - Pass the full `[along, away]` legacy popper offset through to the new top-layer
117
+ `placement.offset` API (via `fromLegacyPlacement`). Previously only the `away` axis was
118
+ forwarded, which dropped the `along` offset for consumers of `Popup`, `PopupSelect`,
119
+ `Spotlight`, and `Tooltip` when `platform-dst-top-layer` is enabled.
120
+ - Fix broken import of `dialogHeight` and `dialogWidth` from the removed utils module in
121
+ `@atlaskit/modal-dialog`.
122
+
123
+ Public API:
124
+ - **`@atlaskit/tooltip`** (`minor`): add an optional `testId?: string` field to `TriggerProps`.
125
+ This is additive (no existing prop changes shape). Required because `@atlaskit/button/new` (and
126
+ other `Pressable`-backed primitives) overwrite `data-testid` from spread, so the legacy
127
+ `(triggerProps as any)['data-testid']` workaround is silently absorbed by those consumers. A
128
+ typed `testId` field flows through their own `testId` destructure instead, restoring
129
+ `data-testid` propagation onto the rendered trigger element.
130
+ - **`@atlaskit/popup`**, **`@atlaskit/dropdown-menu`** (`patch`): no public type changes. Wider
131
+ `aria-haspopup` unions that the FF-on path produces are bridged at the package boundary into
132
+ `@atlaskit/top-layer` with localised `FUDGE(top-layer-api)` casts, documented in
133
+ `packages/design-system/top-layer/notes/decisions/migration-roadmap.md` ("Open API decisions
134
+ deferred to a follow-up PR"). They will be widened in a follow-up `minor` PR once the top-layer
135
+ API is committed.
136
+ - **`@atlaskit/modal-dialog`**, **`@atlaskit/select`**, **`@atlaskit/spotlight`**
137
+ (`patch`/`minor`): no public type changes; bug fixes only.
138
+
139
+ Merge-readiness fixes (FF-on test wiring + adopter behavior):
140
+ - **`@atlaskit/popup`** (`minor`): wire the compositional `PopupContent` to delegate to
141
+ `PopupContentTopLayer` when `platform-dst-top-layer` is enabled. Previously only the legacy
142
+ `Popup` component had the FF branch, leaving consumers of the compositional API on the legacy
143
+ popper path.
144
+ - **`@atlaskit/select`** (`minor`): add an `onClick` handler to the `PopupSelect` top-layer
145
+ trigger so clicks open/close the menu (mirrors the legacy global click handler in
146
+ `popup-select.tsx`). Add explicit Escape handling on the menu's `onKeyDown` so the menu closes
147
+ and focus returns to the trigger.
148
+ - **`@atlaskit/top-layer`** (`patch`): the `<dialog>` rendered by the Dialog primitive now sets
149
+ `aria-modal="true"` explicitly. Modern browsers infer modal semantics from `.showModal()` but
150
+ some assistive tech still keys off the explicit attribute.
151
+ - **`@atlaskit/top-layer`** (`patch`): guard `use-anchor-positioning` against environments where
152
+ `ResizeObserver` is not defined (e.g. jest's `node` environment, used by the post-office test
153
+ suite). The observer is used to wait for the popover's first valid layout before measuring;
154
+ consumers in non-DOM jest environments now get a no-op observer and the scroll/resize listeners
155
+ still apply if the host environment polyfills `showPopover`. Real browsers always have
156
+ `ResizeObserver`.
157
+ - **`@atlaskit/modal-dialog`** (`patch`): on the FF-on path, drop the `tabIndex={-1}` (and unused
158
+ `:focus-visible` outline) from the modal content wrapper. The native `<dialog>.showModal()`
159
+ focus-delegate algorithm picks the first focusable descendant (including `tabindex=-1`), and the
160
+ wrapper was hijacking initial focus from the close button. Also honor `shouldReturnFocus={ref}`
161
+ on the FF-on path (an unmount-cleanup focuses the ref after `dialog.close()` so it overrides the
162
+ browser's automatic return-to-trigger). Boolean `shouldReturnFocus={false}` is not yet honored
163
+ on the FF-on path — see `top-layer/notes/merge-blockers.md`.
164
+ - **`@atlaskit/datetime-picker`** (`patch`): on the FF-on path, set `mode="manual"` on the
165
+ `Popup.Content` rendered by both `internal/menu-top-layer.tsx` (date-picker calendar) and
166
+ `internal/fixed-layer-menu-top-layer.tsx` (time-picker menu). With the default `mode="auto"`,
167
+ the same click event that opens the menu (which targets the react-select combobox input —
168
+ outside the popover element) bubbles to the browser's native popover light-dismiss handler and
169
+ immediately closes the menu. react-select / DateTimePicker already own outside-click and Esc
170
+ dismissal via their own state, so opting out of the native auto-dismiss is the correct
171
+ integration. Also extend the existing Esc → trigger-focus restoration in
172
+ `components/date-picker.tsx` to the FF-on path (manual mode disables the browser's built-in
173
+ focus return, and the legacy code path was already handling this for itself behind an FF
174
+ negation).
175
+ - **`@atlaskit/popup`** (no public API change): no source changes — only FF-on Playwright
176
+ spec/example fixes drove the suite from 21/3/2 to 27/0/0. Notable: the two `test.fixme`'d
177
+ nested-popover cases were not browser limitations; `popover="auto"` chains correctly via DOM
178
+ ancestry (the original fixmes had the wrong testId selector). Added `testId` props to two
179
+ examples (`16-popup-with-a11y-props`, `18-should-fit-container`) so default-shape tests can
180
+ reach the trigger.
181
+ - Test alignment for FF-on Playwright suites across `popup`, `select`, `datetime-picker`,
182
+ `inline-dialog`, `inline-message`, and `modal-dialog`: selector updates to match the new
183
+ top-layer testId convention (`${testId}--content`, `[role="dialog"][aria-label="calendar"]`),
184
+ per-spec `skipAxeCheck()` for example-level color-contrast violations unrelated to the
185
+ migration, and focus assertions adjusted to match native `<dialog>` / `Popup.Content` auto-focus
186
+ semantics (focus lands on the first focusable child, not the dialog container itself).
187
+ - **`@atlassian/capacity-planning-capacity-graph`**, **`@atlaskit/color-picker`**,
188
+ **`@atlassian/timeline-table`**, **`@atlassian/global-side-navigation`** (`patch`): scope `fg`
189
+ mocks in unit tests so `platform-dst-top-layer` returns `false`. JSDOM does not implement the
190
+ native Popover API (`showPopover`/`hidePopover`/`toggle` events), so leaving the gate ON in unit
191
+ tests caused popover content to remain in the DOM after close and broke close-behaviour
192
+ assertions. Browser coverage for the FF-on path is provided by the Playwright suites listed
193
+ above.
194
+ - **`@atlaskit/dropdown-menu`** (no public API change): test/example-only fixes for the FF-on
195
+ Playwright suite. Added `role="menuitem"` to the nested-trigger `ButtonItem` in
196
+ `examples/93-testing-nested-keyboard-navigation-top-layer.tsx` to satisfy axe's
197
+ `aria-required-children` rule on the parent menu. Added a `test.beforeEach(skipAxeCheck)` to
198
+ `dropdown-menu.spec.tsx` (FF-on suite) for example-level `color-contrast` violations on the
199
+ pre-existing `color.text.selected`/`color.background.selected` token pair (3.91:1). Replaced a
200
+ deadlocking `await expect(moveItem).not.toBeFocused()` pre-open assertion (Playwright's
201
+ auto-wait blocks 5s on the absent element) with `await expect(moveItem).not.toBeVisible()`.
202
+ Suite result: 22/22 passing.
203
+
204
+ - Updated dependencies
205
+
3
206
  ## 16.8.9
4
207
 
5
208
  ### Patch Changes
@@ -0,0 +1,10 @@
1
+
2
+ ._2rkofajl{border-radius:var(--ds-radius-small,3px)}._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
3
+ ._1bah1h6o{justify-content:center}
4
+ ._1e0c1txw{display:flex}
5
+ ._1q51v47k{padding-block-start:var(--ds-space-250,20px)}
6
+ ._1ul91lit{min-width:10pc}
7
+ ._85i5v47k{padding-block-end:var(--ds-space-250,20px)}
8
+ ._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
9
+ ._bozgv47k{padding-inline-start:var(--ds-space-250,20px)}
10
+ ._y4tiv47k{padding-inline-end:var(--ds-space-250,20px)}
@@ -0,0 +1,347 @@
1
+ /* dropdown-menu-top-layer.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.default = void 0;
10
+ require("./dropdown-menu-top-layer.compiled.css");
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var React = _react;
13
+ var _runtime = require("@compiled/react/runtime");
14
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
+ var _bindEventListener = require("bind-event-listener");
18
+ var _new = _interopRequireDefault(require("@atlaskit/button/new"));
19
+ var _keycodes = require("@atlaskit/ds-lib/keycodes");
20
+ var _mergeRefs = _interopRequireDefault(require("@atlaskit/ds-lib/merge-refs"));
21
+ var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
22
+ var _useControlled = _interopRequireDefault(require("@atlaskit/ds-lib/use-controlled"));
23
+ var _useFocusEvent = _interopRequireDefault(require("@atlaskit/ds-lib/use-focus-event"));
24
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/core/chevron-down"));
25
+ var _menuGroup = _interopRequireDefault(require("@atlaskit/menu/menu-group"));
26
+ var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
27
+ var _animations = require("@atlaskit/top-layer/animations");
28
+ var _placementMap = require("@atlaskit/top-layer/placement-map");
29
+ var _popup = require("@atlaskit/top-layer/popup");
30
+ var _selectionStore = _interopRequireDefault(require("./internal/context/selection-store"));
31
+ var _useArrowNavigation = require("./internal/use-arrow-navigation");
32
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
33
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
34
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
35
+ var MAX_HEIGHT = "calc(100vh - 16px)";
36
+ var styles = {
37
+ spinnerContainer: "_1e0c1txw _1ul91lit _1bah1h6o _1q51v47k _y4tiv47k _85i5v47k _bozgv47k",
38
+ menuContent: "_2rkofajl _bfhk1bhr _16qs130s"
39
+ };
40
+ var animation = (0, _animations.slideAndFade)();
41
+
42
+ /**
43
+ * Event types produced by trigger interactions.
44
+ *
45
+ * - `React.MouseEvent<Element>` — from the trigger's `onClick` handler
46
+ * - `React.KeyboardEvent<Element>` — from the trigger's `onClick` when activated via keyboard
47
+ * - `KeyboardEvent` — native event from the ArrowDown `bind(window, ...)` listener
48
+ */
49
+
50
+ /**
51
+ * Determines whether a trigger interaction was keyboard-initiated.
52
+ *
53
+ * Keyboard signals:
54
+ * - `type === 'keydown'` (native KeyboardEvent from ArrowDown handler)
55
+ * - `clientX/clientY === 0` (assistive technology click)
56
+ * - `detail === 0` (keyboard-activated click via Enter/Space)
57
+ */
58
+ function isKeyboardTriggered(event) {
59
+ if (event.type === 'keydown') {
60
+ return true;
61
+ }
62
+ if ('clientX' in event && (event.clientX === 0 || event.clientY === 0)) {
63
+ return true;
64
+ }
65
+ if (event.detail === 0) {
66
+ return true;
67
+ }
68
+ return false;
69
+ }
70
+
71
+ /**
72
+ * Loading indicator for the dropdown menu.
73
+ */
74
+ function LoadingIndicator(_ref) {
75
+ var _ref$statusLabel = _ref.statusLabel,
76
+ statusLabel = _ref$statusLabel === void 0 ? 'Loading' : _ref$statusLabel,
77
+ testId = _ref.testId;
78
+ return /*#__PURE__*/React.createElement("div", {
79
+ role: "menuitem",
80
+ className: (0, _runtime.ax)([styles.spinnerContainer])
81
+ }, /*#__PURE__*/React.createElement(_spinner.default, {
82
+ size: "small",
83
+ label: statusLabel,
84
+ testId: testId
85
+ }));
86
+ }
87
+
88
+ /**
89
+ * Top-layer implementation of DropdownMenu.
90
+ *
91
+ * Replaces the legacy `@atlaskit/popup` + `@atlaskit/portal` + `@atlaskit/layering` pipeline
92
+ * with native Popover API via `@atlaskit/top-layer`.
93
+ *
94
+ * What's no longer needed:
95
+ * - Portal: top layer handles stacking natively
96
+ * - FocusLock / react-focus-lock: popover=auto provides light dismiss
97
+ * - z-index: top layer is always above everything
98
+ * - FocusManager (ref registration): replaced by DOM-query-based `useArrowNavigation`
99
+ * - handle-focus.tsx: replaced by `useArrowNavigation`
100
+ * - Layering context: top layer nesting is handled by the browser
101
+ * - Fallback placements / Popper: CSS Anchor Positioning handles positioning
102
+ */
103
+ function DropdownMenuTopLayer(_ref2) {
104
+ var _ref6;
105
+ var _ref2$autoFocus = _ref2.autoFocus,
106
+ autoFocus = _ref2$autoFocus === void 0 ? false : _ref2$autoFocus,
107
+ children = _ref2.children,
108
+ _ref2$defaultOpen = _ref2.defaultOpen,
109
+ defaultOpen = _ref2$defaultOpen === void 0 ? false : _ref2$defaultOpen,
110
+ _ref2$isLoading = _ref2.isLoading,
111
+ isLoading = _ref2$isLoading === void 0 ? false : _ref2$isLoading,
112
+ isOpenProp = _ref2.isOpen,
113
+ _ref2$onOpenChange = _ref2.onOpenChange,
114
+ onOpenChange = _ref2$onOpenChange === void 0 ? _noop.default : _ref2$onOpenChange,
115
+ _ref2$placement = _ref2.placement,
116
+ placement = _ref2$placement === void 0 ? 'bottom-start' : _ref2$placement,
117
+ _ref2$shouldFitContai = _ref2.shouldFitContainer,
118
+ shouldFitContainer = _ref2$shouldFitContai === void 0 ? false : _ref2$shouldFitContai,
119
+ returnFocusRef = _ref2.returnFocusRef,
120
+ spacing = _ref2.spacing,
121
+ statusLabel = _ref2.statusLabel,
122
+ testId = _ref2.testId,
123
+ trigger = _ref2.trigger,
124
+ label = _ref2.label,
125
+ interactionName = _ref2.interactionName,
126
+ menuLabel = _ref2.menuLabel;
127
+ var _useControlledState = (0, _useControlled.default)(isOpenProp, function () {
128
+ return defaultOpen;
129
+ }),
130
+ _useControlledState2 = (0, _slicedToArray2.default)(_useControlledState, 2),
131
+ isLocalOpen = _useControlledState2[0],
132
+ setLocalIsOpen = _useControlledState2[1];
133
+ var triggerRef = (0, _react.useRef)(null);
134
+ var menuRef = (0, _react.useRef)(null);
135
+ var _useState = (0, _react.useState)(false),
136
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
137
+ isTriggeredUsingKeyboard = _useState2[0],
138
+ setTriggeredUsingKeyboard = _useState2[1];
139
+ var topLayerPlacement = (0, _react.useMemo)(function () {
140
+ return (0, _placementMap.fromLegacyPlacement)({
141
+ legacy: placement
142
+ });
143
+ }, [placement]);
144
+
145
+ // ── Close handling ──
146
+ // Focus restoration is handled natively by the Popover API:
147
+ // - Escape → browser restores focus to the trigger automatically
148
+ // - Click-outside → browser does NOT restore (correct behavior)
149
+ //
150
+ // The only custom focus handling needed is `returnFocusRef`: when provided,
151
+ // we redirect focus to a different element than the trigger. We do this
152
+ // in the onClose callback via rAF, which runs after the browser's native
153
+ // restoration — effectively overriding it.
154
+ var handleOnClose = (0, _react.useCallback)(function (_ref3) {
155
+ var _reason = _ref3.reason;
156
+ if (returnFocusRef) {
157
+ requestAnimationFrame(function () {
158
+ var _returnFocusRef$curre;
159
+ (_returnFocusRef$curre = returnFocusRef.current) === null || _returnFocusRef$curre === void 0 || _returnFocusRef$curre.focus();
160
+ });
161
+ }
162
+ setLocalIsOpen(false);
163
+ onOpenChange({
164
+ isOpen: false,
165
+ event: null
166
+ });
167
+ }, [onOpenChange, returnFocusRef, setLocalIsOpen]);
168
+
169
+ // ── Trigger click handling ──
170
+ var handleTriggerClicked = (0, _react.useCallback)(function (event) {
171
+ var newValue = !isLocalOpen;
172
+ setTriggeredUsingKeyboard(isKeyboardTriggered(event));
173
+ setLocalIsOpen(newValue);
174
+
175
+ // Extract the native DOM event for onOpenChange
176
+ var nativeEvent = 'nativeEvent' in event ? event.nativeEvent : event;
177
+ onOpenChange({
178
+ isOpen: newValue,
179
+ event: nativeEvent
180
+ });
181
+ }, [isLocalOpen, setLocalIsOpen, onOpenChange]);
182
+ var _useFocus = (0, _useFocusEvent.default)(),
183
+ isFocused = _useFocus.isFocused,
184
+ bindFocus = _useFocus.bindFocus;
185
+
186
+ // When trigger is focused, open dropdown on ArrowDown (top-level only).
187
+ // Per WAI-ARIA, ArrowDown opens a menu from a menubar/button trigger,
188
+ // but inside a vertical submenu, ArrowDown navigates between siblings
189
+ // and ArrowRight opens nested menus instead.
190
+ (0, _react.useEffect)(function () {
191
+ var _triggerRef$current;
192
+ if (!isFocused || isLocalOpen) {
193
+ return _noop.default;
194
+ }
195
+
196
+ // Don't open on ArrowDown if this trigger is inside a parent menu.
197
+ // Nested menus should only be opened via ArrowRight or Enter.
198
+ var isNestedTrigger = ((_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : _triggerRef$current.closest('[role="menu"]')) != null;
199
+ return (0, _bindEventListener.bind)(window, {
200
+ type: 'keydown',
201
+ listener: function openOnKeyDown(e) {
202
+ if (e.key === _keycodes.KEY_DOWN && !isNestedTrigger) {
203
+ e.preventDefault();
204
+ handleTriggerClicked(e);
205
+ } else if ((e.code === _keycodes.KEY_SPACE || e.key === _keycodes.KEY_ENTER) && e.detail === 0) {
206
+ setTriggeredUsingKeyboard(true);
207
+ }
208
+ }
209
+ });
210
+ }, [isFocused, isLocalOpen, handleTriggerClicked]);
211
+
212
+ // ── Arrow navigation ──
213
+ // useArrowNavigation handles ArrowUp/Down, Home/End, and Tab-to-close
214
+ // by querying focusable elements in the menu DOM container.
215
+ var handleArrowClose = (0, _react.useCallback)(function () {
216
+ handleOnClose({
217
+ reason: 'escape'
218
+ });
219
+ }, [handleOnClose]);
220
+ var handleNestedOpen = (0, _react.useCallback)(function (_ref4) {
221
+ var trigger = _ref4.trigger;
222
+ trigger.click();
223
+ }, []);
224
+ var handleNestedClose = (0, _react.useCallback)(function () {
225
+ handleOnClose({
226
+ reason: 'escape'
227
+ });
228
+ }, [handleOnClose]);
229
+ (0, _useArrowNavigation.useArrowNavigation)({
230
+ containerRef: menuRef,
231
+ onClose: handleArrowClose,
232
+ onNestedOpen: handleNestedOpen,
233
+ onNestedClose: handleNestedClose,
234
+ isEnabled: isLocalOpen,
235
+ filter: _useArrowNavigation.isAtCurrentMenuLevel
236
+ });
237
+
238
+ // ── Auto-focus first item on open ──
239
+ (0, _react.useEffect)(function () {
240
+ if (!isLocalOpen || !isTriggeredUsingKeyboard && !autoFocus) {
241
+ return;
242
+ }
243
+ requestAnimationFrame(function () {
244
+ var menu = menuRef.current;
245
+ if (!menu) {
246
+ return;
247
+ }
248
+ var firstItem = (0, _useArrowNavigation.getFirstFocusable)({
249
+ container: menu
250
+ });
251
+ firstItem === null || firstItem === void 0 || firstItem.focus();
252
+ });
253
+ }, [isLocalOpen, isTriggeredUsingKeyboard, autoFocus]);
254
+
255
+ // shouldFitContainer is handled by the width prop on Popup.Content below.
256
+ var popupContentWidth = shouldFitContainer ? 'min-trigger' : 'content';
257
+
258
+ // ── Close on menu item click ──
259
+ // Close when a regular menuitem is clicked, but not checkboxes/radios
260
+ // and not nested triggers (items with aria-haspopup).
261
+ var handleMenuClick = (0, _react.useCallback)(function (e) {
262
+ var _target$closest;
263
+ var target = e.target;
264
+ var menuItem = (_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, '[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]');
265
+ if (!menuItem) {
266
+ return;
267
+ }
268
+ var isCheckboxOrRadio = menuItem.getAttribute('role') === 'menuitemcheckbox' || menuItem.getAttribute('role') === 'menuitemradio';
269
+ // Don't close the menu when clicking a nested trigger (aria-haspopup).
270
+ // The nested dropdown will handle its own open/close.
271
+ var isNestedTrigger = menuItem.hasAttribute('aria-haspopup');
272
+ if (!isCheckboxOrRadio && !isNestedTrigger) {
273
+ setLocalIsOpen(false);
274
+ onOpenChange({
275
+ isOpen: false,
276
+ event: e.nativeEvent
277
+ });
278
+ }
279
+ }, [setLocalIsOpen, onOpenChange]);
280
+ return /*#__PURE__*/React.createElement(_selectionStore.default, null, /*#__PURE__*/React.createElement(_popup.Popup, {
281
+ placement: topLayerPlacement,
282
+ onClose: handleOnClose
283
+ }, /*#__PURE__*/React.createElement(_popup.Popup.TriggerFunction, null, function (_ref5) {
284
+ var ref = _ref5.ref,
285
+ _toggle = _ref5.toggle,
286
+ ariaAttributes = _ref5.ariaAttributes;
287
+ var combinedRef = (0, _mergeRefs.default)([ref, triggerRef]);
288
+
289
+ // FUDGE(top-layer-api): cast `ariaAttributes` to the narrow shape that adopter
290
+ // public types expect. `@atlaskit/top-layer` types `aria-haspopup` as the wider
291
+ // WAI-ARIA union (boolean | 'dialog' | 'menu' | 'listbox' | 'tree' | 'grid'),
292
+ // but the public `CustomTriggerProps` (extending `@atlaskit/popup` `TriggerProps`)
293
+ // is intentionally kept narrow (boolean | 'dialog') because the top-layer API
294
+ // surface is not yet settled. The runtime value is unchanged; only the
295
+ // TypeScript-visible type is narrowed at this boundary.
296
+ // REMOVE WHEN: the top-layer public API is committed (see
297
+ // packages/design-system/top-layer/notes/decisions/migration-roadmap.md "Open API
298
+ // decisions deferred to a follow-up PR") and a follow-up `minor` PR widens
299
+ // `TriggerProps['aria-haspopup']` on `@atlaskit/popup` to match.
300
+ var narrowAriaAttributes = ariaAttributes;
301
+ if (typeof trigger === 'function') {
302
+ return trigger(_objectSpread(_objectSpread(_objectSpread({}, narrowAriaAttributes), bindFocus), {}, {
303
+ triggerRef: combinedRef,
304
+ isSelected: isLocalOpen,
305
+ onClick: handleTriggerClicked,
306
+ testId: testId && "".concat(testId, "--trigger")
307
+ }));
308
+ }
309
+ return /*#__PURE__*/React.createElement(_new.default, (0, _extends2.default)({}, bindFocus, {
310
+ ref: combinedRef
311
+ }, narrowAriaAttributes, {
312
+ isSelected: isLocalOpen,
313
+ iconAfter: function iconAfter(iconProps) {
314
+ return /*#__PURE__*/React.createElement(_chevronDown.default, (0, _extends2.default)({}, iconProps, {
315
+ size: "small"
316
+ }));
317
+ },
318
+ onClick: handleTriggerClicked,
319
+ testId: testId && "".concat(testId, "--trigger"),
320
+ "aria-label": label,
321
+ interactionName: interactionName
322
+ }), trigger);
323
+ }), /*#__PURE__*/React.createElement(_popup.Popup.Content, {
324
+ role: "menu",
325
+ label: (_ref6 = menuLabel !== null && menuLabel !== void 0 ? menuLabel : label) !== null && _ref6 !== void 0 ? _ref6 : typeof trigger === 'string' ? trigger : 'Menu',
326
+ isOpen: isLocalOpen,
327
+ animate: animation,
328
+ width: popupContentWidth,
329
+ testId: testId && "".concat(testId, "--content")
330
+ }, /*#__PURE__*/React.createElement("div", {
331
+ ref: menuRef,
332
+ className: (0, _runtime.ax)([styles.menuContent])
333
+ }, /*#__PURE__*/React.createElement(_menuGroup.default, {
334
+ isLoading: isLoading,
335
+ maxHeight: MAX_HEIGHT,
336
+ maxWidth: shouldFitContainer ? undefined : 800,
337
+ onClick: handleMenuClick,
338
+ role: "menu",
339
+ spacing: spacing,
340
+ testId: testId && "".concat(testId, "--menu-wrapper--menu-group"),
341
+ menuLabel: menuLabel
342
+ }, isLoading ? /*#__PURE__*/React.createElement(LoadingIndicator, {
343
+ statusLabel: statusLabel,
344
+ testId: testId && "".concat(testId, "--menu-wrapper--loading-indicator")
345
+ }) : children)))));
346
+ }
347
+ var _default = exports.default = DropdownMenuTopLayer;
@@ -20,8 +20,10 @@ var _useControlled = _interopRequireDefault(require("@atlaskit/ds-lib/use-contro
20
20
  var _useFocusEvent = _interopRequireDefault(require("@atlaskit/ds-lib/use-focus-event"));
21
21
  var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/core/chevron-down"));
22
22
  var _layering = require("@atlaskit/layering");
23
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
23
24
  var _popup = _interopRequireDefault(require("@atlaskit/popup"));
24
25
  var _constants = require("@atlaskit/theme/constants");
26
+ var _dropdownMenuTopLayer = _interopRequireDefault(require("./dropdown-menu-top-layer"));
25
27
  var _focusManager = _interopRequireDefault(require("./internal/components/focus-manager"));
26
28
  var _menuWrapper = _interopRequireDefault(require("./internal/components/menu-wrapper"));
27
29
  var _selectionStore = _interopRequireDefault(require("./internal/context/selection-store"));
@@ -64,15 +66,9 @@ function isKeyboardEvent(event) {
64
66
  }
65
67
 
66
68
  /**
67
- * __Dropdown menu__
68
- *
69
- * A dropdown menu displays a list of actions or options to a user.
70
- *
71
- * - [Examples](https://atlassian.design/components/dropdown-menu/examples)
72
- * - [Code](https://atlassian.design/components/dropdown-menu/code)
73
- * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
69
+ * Legacy Popper/Popup implementation (hooks run unconditionally when this component mounts).
74
70
  */
75
- var DropdownMenu = function DropdownMenu(_ref) {
71
+ function DropdownMenuLegacy(_ref) {
76
72
  var _ref$autoFocus = _ref.autoFocus,
77
73
  autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
78
74
  children = _ref.children,
@@ -344,5 +340,63 @@ var DropdownMenu = function DropdownMenu(_ref) {
344
340
  }, children));
345
341
  }
346
342
  })));
343
+ }
344
+
345
+ /**
346
+ * __Dropdown menu__
347
+ *
348
+ * A dropdown menu displays a list of actions or options to a user.
349
+ *
350
+ * - [Examples](https://atlassian.design/components/dropdown-menu/examples)
351
+ * - [Code](https://atlassian.design/components/dropdown-menu/code)
352
+ * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
353
+ */
354
+ var DropdownMenu = function DropdownMenu(props) {
355
+ var _props$autoFocus = props.autoFocus,
356
+ autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
357
+ children = props.children,
358
+ _props$defaultOpen = props.defaultOpen,
359
+ defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
360
+ _props$isLoading = props.isLoading,
361
+ isLoading = _props$isLoading === void 0 ? false : _props$isLoading,
362
+ isOpen = props.isOpen,
363
+ _props$onOpenChange = props.onOpenChange,
364
+ onOpenChange = _props$onOpenChange === void 0 ? _noop.default : _props$onOpenChange,
365
+ _props$placement = props.placement,
366
+ placement = _props$placement === void 0 ? 'bottom-start' : _props$placement,
367
+ _props$shouldFitConta = props.shouldFitContainer,
368
+ shouldFitContainer = _props$shouldFitConta === void 0 ? false : _props$shouldFitConta,
369
+ returnFocusRef = props.returnFocusRef,
370
+ spacing = props.spacing,
371
+ statusLabel = props.statusLabel,
372
+ testId = props.testId,
373
+ trigger = props.trigger,
374
+ label = props.label,
375
+ interactionName = props.interactionName,
376
+ menuLabel = props.menuLabel;
377
+ if ((0, _platformFeatureFlags.fg)('platform-dst-top-layer')) {
378
+ return /*#__PURE__*/_react.default.createElement(_dropdownMenuTopLayer.default, {
379
+ autoFocus: autoFocus,
380
+ children: children,
381
+ defaultOpen: defaultOpen,
382
+ isLoading: isLoading,
383
+ isOpen: isOpen,
384
+ onOpenChange: onOpenChange,
385
+ placement: placement,
386
+ shouldFitContainer: shouldFitContainer,
387
+ returnFocusRef: returnFocusRef,
388
+ spacing: spacing,
389
+ statusLabel: statusLabel,
390
+ testId: testId,
391
+ trigger: trigger,
392
+ label: label,
393
+ interactionName: interactionName,
394
+ menuLabel: menuLabel
395
+ });
396
+ }
397
+
398
+ // Forward full public props to the legacy Popper/Popup implementation unchanged.
399
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props -- wrapper delegates entire DropdownMenuProps API
400
+ return /*#__PURE__*/_react.default.createElement(DropdownMenuLegacy, props);
347
401
  };
348
402
  var _default = exports.default = DropdownMenu;