@dt-dds/react-dropdown 1.0.0-beta.100

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Dropdown Package
2
+
3
+ The Dropdown Menu provides the users with a box that can receive any content. It also provides an Option component.
4
+
5
+ ## Dropdown Usage
6
+
7
+ ```jsx
8
+ import { Dropdown } from '@dt-dds/react';
9
+
10
+ const OPTIONS = [
11
+ { text: 'Option 1', value: '1' },
12
+ { text: 'Option 2', value: '2' },
13
+ ];
14
+
15
+ export const App = () => {
16
+ return (
17
+ <Dropdown>
18
+ {options.map((option) => (
19
+ <Dropdown.Option key={option.value}>{option.text}</Dropdown.Option>
20
+ ))}
21
+ </Dropdown>
22
+ );
23
+ };
24
+ ```
25
+
26
+ ## Properties
27
+
28
+ ### Dropdown
29
+
30
+ | Property | Type | Default | Description |
31
+ | ------------ | -------------------------------- | ---------- | --------------------------------------------------------------------------- |
32
+ | `children` | `ReactNode` | — | Child components/content to be rendered inside the dropdown. |
33
+ | `style` | `React.CSSProperties` | — | Inline styles merged **after** computed positioning styles. |
34
+ | `dataTestId` | `string` | `dropdown` | Customizable test identifier applied to the dropdown root element. |
35
+ | `isOpen` | `boolean` | `false` | Controls visibility. When `false`, the element is hidden via `aria-hidden`. |
36
+ | `anchorRef` | `RefObject<HTMLElement \| null>` | - | Reference to the anchor element used for positioning. |
37
+ | `matchWidth` | `boolean` | `true` | If `true`, the dropdown width matches the anchor width. |
38
+ | `offsetX` | `number` | `4` | Horizontal offset (px) for `left`/`right` placements. |
39
+ | `offsetY` | `number` | `4` | Vertical offset (px) for `top`/`bottom` placements. |
40
+ | `onClose` | `() => void` | — | Called when a click is detected outside the dropdown/anchor. |
41
+ | `as` | `keyof JSX.IntrinsicElements` | `"div"` | Underlying HTML element (e.g., `"ul"` for list semantics). |
42
+ | `placement` | `DropdownPlacement` | `bottom` | Dropdown position. |
43
+ | `...rest` | `HTMLAttributes` | — | Standard HTML attributes. |
44
+
45
+ ### Dropdown.Option
46
+
47
+ | Property | Type | Default | Description |
48
+ | --------------- | -------------------------------------------- | ----------------- | ----------------------------------------------------------------------- |
49
+ | `style` | `React.CSSProperties` | — | Inline styles for the option element. |
50
+ | `children` | `ReactNode` | — | Content of the option. |
51
+ | `dataTestId` | `string` | `dropdown-option` | Customizable test identifier for the option element. |
52
+ | `isDisabled` | `boolean` | `false` | When `true`, sets `aria-disabled` and blocks click/keyboard activation. |
53
+ | `isSelected` | `boolean` | `false` | Reflects selection state via `aria-selected` and styling. |
54
+ | `isHighlighted` | `boolean` | `false` | Adds `data-highlighted="true"` for hover/active row styling. |
55
+ | `isMulti` | `boolean` | `false` | Optional styling hint for multi-select contexts (no selection logic). |
56
+ | `onClick` | `(event: MouseEvent<HTMLLIElement>) => void` | — | Click handler. |
57
+ | `...rest` | `HTMLAttributes` | — | Standard HTML attributes. |
58
+
59
+ ## Stack
60
+
61
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
62
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
63
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
64
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
65
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
66
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
67
+ - [ESLint](https://eslint.org/) for code linting
68
+ - [Prettier](https://prettier.io) for code formatting
69
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
70
+ - [Yarn](https://yarnpkg.com/) from managing packages
71
+
72
+ ## Commands
73
+
74
+ - `yarn build` - Build the package
75
+ - `yarn dev` - Run the package locally
76
+ - `yarn lint` - Lint all files within this package
77
+ - `yarn test` - Run all unit tests
78
+ - `yarn test:report` - Open the test coverage report
79
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
80
+
81
+ ## Compilation
82
+
83
+ Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
84
+
85
+ The `/dist` folder contains the compiled output.
86
+
87
+ ```bash
88
+ dropdown
89
+ └── dist
90
+ ├── index.d.ts <-- Types
91
+ ├── index.js <-- CommonJS version
92
+ └── index.mjs <-- ES Modules version
93
+ ...
94
+ ```
95
+
96
+ ## Versioning
97
+
98
+ Follows [semantic versioning](https://semver.org/)
99
+
100
+ ## &copy; License
101
+
102
+ Licensed under [MIT License](LICENSE)
@@ -0,0 +1,40 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react from 'react';
3
+ import { AnchorHTMLAttributes, ElementType, MouseEvent, HTMLAttributes, RefObject } from 'react';
4
+ import { BaseProps } from '@dt-dds/react-core';
5
+
6
+ interface DropdownOptionProps extends BaseProps, Omit<AnchorHTMLAttributes<HTMLElement>, 'onClick'> {
7
+ isDisabled?: boolean;
8
+ isSelected?: boolean;
9
+ isHighlighted?: boolean;
10
+ isMulti?: boolean;
11
+ as?: ElementType;
12
+ onClick?: (e: MouseEvent<HTMLElement>) => void;
13
+ }
14
+ declare const DropdownOption: react.ForwardRefExoticComponent<DropdownOptionProps & react.RefAttributes<HTMLLIElement>>;
15
+
16
+ type DropdownVariant = 'outlined' | 'bottom-line';
17
+ type DropdownFill = 'default' | 'contrast' | 'light';
18
+ type DropdownPlacement = 'bottom' | 'top' | 'left' | 'right';
19
+
20
+ interface DropdownProps extends BaseProps, HTMLAttributes<HTMLElement> {
21
+ isOpen?: boolean;
22
+ anchorRef: RefObject<HTMLElement | null>;
23
+ matchWidth?: boolean;
24
+ offsetX?: number;
25
+ offsetY?: number;
26
+ onClose?: () => void;
27
+ as?: keyof JSX.IntrinsicElements;
28
+ placement?: DropdownPlacement;
29
+ isFocusable?: boolean;
30
+ }
31
+ declare const Dropdown: react.ForwardRefExoticComponent<DropdownProps & react.RefAttributes<HTMLElement>> & {
32
+ Option: react.ForwardRefExoticComponent<DropdownOptionProps & react.RefAttributes<HTMLLIElement>>;
33
+ };
34
+
35
+ declare module '@emotion/react' {
36
+ interface Theme extends CustomTheme {
37
+ }
38
+ }
39
+
40
+ export { Dropdown, type DropdownFill, DropdownOption, type DropdownOptionProps, type DropdownPlacement, type DropdownProps, type DropdownVariant };
@@ -0,0 +1,40 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react from 'react';
3
+ import { AnchorHTMLAttributes, ElementType, MouseEvent, HTMLAttributes, RefObject } from 'react';
4
+ import { BaseProps } from '@dt-dds/react-core';
5
+
6
+ interface DropdownOptionProps extends BaseProps, Omit<AnchorHTMLAttributes<HTMLElement>, 'onClick'> {
7
+ isDisabled?: boolean;
8
+ isSelected?: boolean;
9
+ isHighlighted?: boolean;
10
+ isMulti?: boolean;
11
+ as?: ElementType;
12
+ onClick?: (e: MouseEvent<HTMLElement>) => void;
13
+ }
14
+ declare const DropdownOption: react.ForwardRefExoticComponent<DropdownOptionProps & react.RefAttributes<HTMLLIElement>>;
15
+
16
+ type DropdownVariant = 'outlined' | 'bottom-line';
17
+ type DropdownFill = 'default' | 'contrast' | 'light';
18
+ type DropdownPlacement = 'bottom' | 'top' | 'left' | 'right';
19
+
20
+ interface DropdownProps extends BaseProps, HTMLAttributes<HTMLElement> {
21
+ isOpen?: boolean;
22
+ anchorRef: RefObject<HTMLElement | null>;
23
+ matchWidth?: boolean;
24
+ offsetX?: number;
25
+ offsetY?: number;
26
+ onClose?: () => void;
27
+ as?: keyof JSX.IntrinsicElements;
28
+ placement?: DropdownPlacement;
29
+ isFocusable?: boolean;
30
+ }
31
+ declare const Dropdown: react.ForwardRefExoticComponent<DropdownProps & react.RefAttributes<HTMLElement>> & {
32
+ Option: react.ForwardRefExoticComponent<DropdownOptionProps & react.RefAttributes<HTMLLIElement>>;
33
+ };
34
+
35
+ declare module '@emotion/react' {
36
+ interface Theme extends CustomTheme {
37
+ }
38
+ }
39
+
40
+ export { Dropdown, type DropdownFill, DropdownOption, type DropdownOptionProps, type DropdownPlacement, type DropdownProps, type DropdownVariant };
package/dist/index.js ADDED
@@ -0,0 +1,403 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+
59
+ // index.ts
60
+ var index_exports = {};
61
+ __export(index_exports, {
62
+ Dropdown: () => Dropdown,
63
+ DropdownOption: () => DropdownOption
64
+ });
65
+ module.exports = __toCommonJS(index_exports);
66
+
67
+ // src/Dropdown.tsx
68
+ var import_react3 = require("react");
69
+ var import_focus_trap_react = require("focus-trap-react");
70
+ var import_react_core2 = require("@dt-dds/react-core");
71
+
72
+ // src/components/option/DropdownOption.tsx
73
+ var import_react = require("react");
74
+
75
+ // src/components/option/DropdownOption.styled.ts
76
+ var import_styled = __toESM(require("@emotion/styled"));
77
+ var DropdownOptionStyled = import_styled.default.li`
78
+ ${({ theme }) => `
79
+ ${theme.fontStyles.bodyMdRegular};
80
+
81
+ display: block;
82
+ color: ${theme.palette.content.default};
83
+ padding: ${theme.spacing.spacing_40} ${theme.spacing.spacing_50};
84
+ list-style: none;
85
+ text-overflow: ellipsis;
86
+ overflow-x: hidden;
87
+ text-wrap: nowrap;
88
+
89
+ &:not([aria-disabled="true"]) {
90
+ &[aria-selected="true"], &[aria-selected="true"] span {
91
+ ${theme.fontStyles.bodyMdBold};
92
+ }
93
+
94
+ &:hover, &[data-highlighted="true"] {
95
+ background: ${theme.palette.accent.light};
96
+ cursor: pointer;
97
+ }
98
+
99
+ &:focus-visible {
100
+ outline: 2px solid ${theme.palette.primary.default};
101
+ outline-offset: -2px;
102
+ }
103
+ }
104
+
105
+ &[aria-disabled="true"] {
106
+ color: ${theme.palette.content.light};
107
+ cursor: not-allowed;
108
+
109
+ &[aria-selected="true"] {
110
+ background-color: ${theme.palette.surface.light};
111
+ }
112
+ }
113
+ `}
114
+ `;
115
+
116
+ // src/components/option/DropdownOption.tsx
117
+ var import_jsx_runtime = require("react/jsx-runtime");
118
+ var DropdownOption = (0, import_react.forwardRef)(
119
+ (_a, ref) => {
120
+ var _b = _a, {
121
+ dataTestId,
122
+ children,
123
+ style,
124
+ isDisabled,
125
+ isSelected = false,
126
+ isHighlighted = false,
127
+ onClick
128
+ } = _b, rest = __objRest(_b, [
129
+ "dataTestId",
130
+ "children",
131
+ "style",
132
+ "isDisabled",
133
+ "isSelected",
134
+ "isHighlighted",
135
+ "onClick"
136
+ ]);
137
+ const testId = dataTestId != null ? dataTestId : "dropdown-option";
138
+ const handleClick = (e) => {
139
+ if (isDisabled) {
140
+ e.preventDefault();
141
+ e.stopPropagation();
142
+ return;
143
+ }
144
+ onClick == null ? void 0 : onClick(e);
145
+ };
146
+ const handleKeyDown = (e) => {
147
+ if (e.code === "Enter" || e.code === "Space") {
148
+ e.preventDefault();
149
+ onClick == null ? void 0 : onClick(e);
150
+ }
151
+ };
152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
153
+ DropdownOptionStyled,
154
+ __spreadProps(__spreadValues(__spreadValues({
155
+ onClick: handleClick,
156
+ onKeyDown: handleKeyDown,
157
+ tabIndex: isDisabled ? -1 : 0
158
+ }, !isSelected && { role: "menuitem" }), rest), {
159
+ "aria-disabled": isDisabled,
160
+ "aria-selected": isSelected,
161
+ "data-highlighted": isHighlighted,
162
+ "data-testid": testId,
163
+ ref,
164
+ style,
165
+ children
166
+ })
167
+ );
168
+ }
169
+ );
170
+
171
+ // src/Dropdown.styled.ts
172
+ var import_styled2 = __toESM(require("@emotion/styled"));
173
+ var DropdownStyled = import_styled2.default.div`
174
+ list-style-type: none;
175
+ width: 100%;
176
+ overflow: auto;
177
+ `;
178
+
179
+ // src/hooks/useFloatingPosition.ts
180
+ var import_react2 = require("react");
181
+ var import_react_core = require("@dt-dds/react-core");
182
+ function basePos({
183
+ placement,
184
+ anchor,
185
+ menuWidth,
186
+ menuHeight,
187
+ offsetX,
188
+ offsetY
189
+ }) {
190
+ switch (placement) {
191
+ case "bottom":
192
+ return { top: anchor.bottom + offsetY, left: anchor.left + offsetX };
193
+ case "top":
194
+ return {
195
+ top: anchor.top - offsetY - menuHeight,
196
+ left: anchor.left + offsetX
197
+ };
198
+ case "right":
199
+ return { top: anchor.top + offsetY, left: anchor.right + offsetX };
200
+ case "left":
201
+ return {
202
+ top: anchor.top + offsetY,
203
+ left: anchor.left - offsetX - menuWidth
204
+ };
205
+ }
206
+ }
207
+ function useFloatingPosition(anchorEl, open, {
208
+ offsetX = 0,
209
+ offsetY = 4,
210
+ matchWidth = true,
211
+ minViewportPadding = 8,
212
+ placement = "bottom",
213
+ menuRef
214
+ } = {}) {
215
+ const [style, setStyle] = (0, import_react2.useState)({
216
+ visibility: "hidden",
217
+ position: "fixed"
218
+ });
219
+ (0, import_react2.useLayoutEffect)(() => {
220
+ if (!open || !(anchorEl == null ? void 0 : anchorEl.current)) {
221
+ setStyle({
222
+ visibility: "hidden",
223
+ position: "fixed"
224
+ });
225
+ return;
226
+ }
227
+ const anchorElement = anchorEl == null ? void 0 : anchorEl.current;
228
+ const menuElement = menuRef == null ? void 0 : menuRef.current;
229
+ const updatePosition = () => {
230
+ var _a, _b;
231
+ const vw = window.innerWidth;
232
+ const vh = window.innerHeight;
233
+ const anchor = anchorElement.getBoundingClientRect();
234
+ const menuRect = menuElement == null ? void 0 : menuElement.getBoundingClientRect();
235
+ const menuWidth = matchWidth ? anchor.width : (_a = menuRect == null ? void 0 : menuRect.width) != null ? _a : anchor.width;
236
+ const menuHeight = (_b = menuRect == null ? void 0 : menuRect.height) != null ? _b : 0;
237
+ let { top, left } = basePos({
238
+ placement,
239
+ anchor,
240
+ menuWidth,
241
+ menuHeight,
242
+ offsetX,
243
+ offsetY
244
+ });
245
+ const maxLeft = Math.max(
246
+ minViewportPadding,
247
+ vw - menuWidth - minViewportPadding
248
+ );
249
+ const maxTop = Math.max(
250
+ minViewportPadding,
251
+ vh - menuHeight - minViewportPadding
252
+ );
253
+ left = Math.max(minViewportPadding, Math.min(left, maxLeft));
254
+ top = Math.max(minViewportPadding, Math.min(top, maxTop));
255
+ setStyle({
256
+ position: "fixed",
257
+ top,
258
+ left,
259
+ width: matchWidth ? anchor.width : void 0,
260
+ maxWidth: matchWidth ? anchor.width : 300,
261
+ boxSizing: "border-box",
262
+ zIndex: import_react_core.DROPDOWN_MENU_Z_INDEX
263
+ });
264
+ };
265
+ updatePosition();
266
+ const ro = new ResizeObserver(updatePosition);
267
+ ro.observe(anchorElement);
268
+ if (anchorElement) {
269
+ ro.observe(anchorElement);
270
+ }
271
+ const opts = { passive: true };
272
+ window.addEventListener("scroll", updatePosition, opts);
273
+ window.addEventListener("resize", updatePosition, opts);
274
+ return () => {
275
+ ro.disconnect();
276
+ window.removeEventListener("scroll", updatePosition, opts);
277
+ window.removeEventListener("resize", updatePosition, opts);
278
+ };
279
+ }, [
280
+ menuRef,
281
+ anchorEl,
282
+ open,
283
+ placement,
284
+ offsetX,
285
+ offsetY,
286
+ matchWidth,
287
+ minViewportPadding
288
+ ]);
289
+ return { style };
290
+ }
291
+
292
+ // src/utils/set-ref.ts
293
+ var setRef = (target, node) => {
294
+ if (!target) {
295
+ return;
296
+ }
297
+ if (typeof target === "function") {
298
+ target(node);
299
+ return;
300
+ }
301
+ target.current = node;
302
+ };
303
+
304
+ // src/Dropdown.tsx
305
+ var import_jsx_runtime2 = require("react/jsx-runtime");
306
+ var Dropdown = Object.assign(
307
+ (0, import_react3.forwardRef)(
308
+ (_a, forwardedRef) => {
309
+ var _b = _a, {
310
+ children,
311
+ style,
312
+ dataTestId = "dropdown",
313
+ isOpen = false,
314
+ anchorRef,
315
+ matchWidth = true,
316
+ offsetX,
317
+ offsetY,
318
+ as = "div",
319
+ onClose,
320
+ placement,
321
+ isFocusable = true
322
+ } = _b, rest = __objRest(_b, [
323
+ "children",
324
+ "style",
325
+ "dataTestId",
326
+ "isOpen",
327
+ "anchorRef",
328
+ "matchWidth",
329
+ "offsetX",
330
+ "offsetY",
331
+ "as",
332
+ "onClose",
333
+ "placement",
334
+ "isFocusable"
335
+ ]);
336
+ const localMenuRef = (0, import_react3.useRef)(null);
337
+ const setMenuRef = (0, import_react3.useCallback)(
338
+ (node) => {
339
+ localMenuRef.current = node;
340
+ setRef(forwardedRef, node);
341
+ },
342
+ [forwardedRef]
343
+ );
344
+ const { style: floatingStyle } = useFloatingPosition(
345
+ anchorRef,
346
+ isOpen,
347
+ {
348
+ matchWidth,
349
+ offsetX,
350
+ offsetY,
351
+ placement,
352
+ menuRef: localMenuRef
353
+ }
354
+ );
355
+ (0, import_react_core2.useClickOutside)({
356
+ refs: [localMenuRef, anchorRef],
357
+ handler: () => onClose == null ? void 0 : onClose()
358
+ });
359
+ const dropdownNode = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
360
+ DropdownStyled,
361
+ __spreadProps(__spreadValues(__spreadValues({
362
+ as,
363
+ "data-testid": dataTestId,
364
+ ref: setMenuRef,
365
+ role: "menu",
366
+ style: __spreadValues(__spreadValues({}, floatingStyle), style)
367
+ }, rest), !isFocusable && {
368
+ onMouseDown: (e) => e.preventDefault()
369
+ }), {
370
+ children
371
+ })
372
+ );
373
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_core2.Portal, { isOpen: true, children: isFocusable ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
374
+ import_focus_trap_react.FocusTrap,
375
+ {
376
+ active: isOpen,
377
+ focusTrapOptions: {
378
+ initialFocus: () => {
379
+ var _a2;
380
+ return (_a2 = localMenuRef == null ? void 0 : localMenuRef.current) != null ? _a2 : false;
381
+ },
382
+ fallbackFocus: () => document.body,
383
+ escapeDeactivates: true,
384
+ allowOutsideClick: true,
385
+ onDeactivate: () => {
386
+ onClose == null ? void 0 : onClose();
387
+ },
388
+ tabbableOptions: { displayCheck: "none" }
389
+ },
390
+ children: dropdownNode
391
+ }
392
+ ) : dropdownNode });
393
+ }
394
+ ),
395
+ {
396
+ Option: DropdownOption
397
+ }
398
+ );
399
+ // Annotate the CommonJS export names for ESM import in node:
400
+ 0 && (module.exports = {
401
+ Dropdown,
402
+ DropdownOption
403
+ });