@rescui/dropdown 0.13.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auto-update.d.ts +7 -0
- package/lib/auto-update.js +54 -0
- package/lib/custom-middleware.d.ts +23 -0
- package/lib/custom-middleware.js +151 -0
- package/lib/dropdown.d.ts +51 -7
- package/lib/dropdown.js +299 -187
- package/lib/dropdown.p.module.css.js +1 -1
- package/lib/focus-utils.d.ts +9 -0
- package/lib/focus-utils.js +30 -0
- package/lib/index.css +35 -19
- package/lib/index.d.ts +1 -1
- package/lib/types.d.ts +9 -0
- package/lib/use-dropdown-aria.d.ts +19 -0
- package/lib/use-dropdown-aria.js +121 -0
- package/lib/use-hide-others.d.ts +6 -0
- package/lib/use-hide-others.js +36 -0
- package/llm/components/dropdown.md +59 -0
- package/package.json +5 -6
- package/lib/custom-modifiers.d.ts +0 -12
- package/lib/custom-modifiers.js +0 -91
package/lib/dropdown.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { c } from 'react-compiler-runtime';
|
|
3
|
-
import React, { useState, useRef, useImperativeHandle, useContext, useEffect } from 'react';
|
|
3
|
+
import React, { useState, useRef, useImperativeHandle, useContext, useEffect, isValidElement, cloneElement } from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import cn from 'classnames';
|
|
6
|
-
import {
|
|
7
|
-
import maxSizeModifier from 'popper-max-size-modifier';
|
|
6
|
+
import { useFloating, offset, autoPlacement, flip, shift, limitShift } from '@floating-ui/react-dom';
|
|
8
7
|
import { useLayeringContext, ThemeContext, getInverseTheme, LayeringProvider, ThemeProvider } from '@rescui/ui-contexts';
|
|
9
8
|
import FocusLock from 'react-focus-lock';
|
|
10
9
|
import ReactDOM from 'react-dom';
|
|
10
|
+
import { autoUpdateDropdown } from './auto-update.js';
|
|
11
|
+
import { getInitialFocusElement, getFirstTabbableElement } from './focus-utils.js';
|
|
12
|
+
import { useDropdownAria } from './use-dropdown-aria.js';
|
|
11
13
|
import { useDropdownState, DROPDOWN_STATES } from './use-dropdown-state.js';
|
|
14
|
+
import { useHideOthers } from './use-hide-others.js';
|
|
12
15
|
import { useScrollableContainer } from './use-scrollable-container.js';
|
|
13
16
|
import styles from './dropdown.p.module.css.js';
|
|
14
|
-
import {
|
|
17
|
+
import { isAutoPlacement, sameWidth, AUTO_PLACEMENTS, applyMaxSize } from './custom-middleware.js';
|
|
15
18
|
import { useExtractCssValues } from './use-extract-css-values.js';
|
|
16
19
|
|
|
17
|
-
function
|
|
20
|
+
function getMiddleware(_ref) {
|
|
18
21
|
let {
|
|
19
22
|
placement,
|
|
20
23
|
maxHeight,
|
|
@@ -23,34 +26,21 @@ function getPopperOptions(_ref) {
|
|
|
23
26
|
minWidth,
|
|
24
27
|
disableFlip = false
|
|
25
28
|
} = _ref;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
...applyMaxSize,
|
|
42
|
-
options: {
|
|
43
|
-
maxHeight,
|
|
44
|
-
leastMaxHeight
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
...sameWidthModifier,
|
|
48
|
-
options: {
|
|
49
|
-
maxWidth,
|
|
50
|
-
minWidth
|
|
51
|
-
}
|
|
52
|
-
}]
|
|
53
|
-
};
|
|
29
|
+
const isAuto = isAutoPlacement(placement);
|
|
30
|
+
return [sameWidth({
|
|
31
|
+
maxWidth,
|
|
32
|
+
minWidth
|
|
33
|
+
}), offset(8), isAuto ? autoPlacement({
|
|
34
|
+
allowedPlacements: AUTO_PLACEMENTS[placement]
|
|
35
|
+
}) : !disableFlip && flip({
|
|
36
|
+
fallbackStrategy: 'initialPlacement'
|
|
37
|
+
}), shift({
|
|
38
|
+
limiter: limitShift()
|
|
39
|
+
}), applyMaxSize({
|
|
40
|
+
maxHeight,
|
|
41
|
+
leastMaxHeight,
|
|
42
|
+
flip: !isAuto && !disableFlip
|
|
43
|
+
})];
|
|
54
44
|
}
|
|
55
45
|
const Portal = _ref2 => {
|
|
56
46
|
let {
|
|
@@ -163,6 +153,31 @@ function useKeyPress(t0) {
|
|
|
163
153
|
}
|
|
164
154
|
useEffect(t1, t2);
|
|
165
155
|
}
|
|
156
|
+
function isFragment(trigger) {
|
|
157
|
+
return typeof trigger !== 'function' && /*#__PURE__*/isValidElement(trigger) && trigger.type === React.Fragment;
|
|
158
|
+
}
|
|
159
|
+
function renderTrigger(_ref3) {
|
|
160
|
+
let {
|
|
161
|
+
trigger,
|
|
162
|
+
triggerProps,
|
|
163
|
+
setTriggerRef,
|
|
164
|
+
hasRole
|
|
165
|
+
} = _ref3;
|
|
166
|
+
if (typeof trigger === 'function') {
|
|
167
|
+
return trigger({
|
|
168
|
+
...triggerProps,
|
|
169
|
+
ref: setTriggerRef
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
173
|
+
"data-test": "dropdown-trigger",
|
|
174
|
+
className: styles.triggerWrapper,
|
|
175
|
+
ref: setTriggerRef
|
|
176
|
+
}, hasRole && /*#__PURE__*/isValidElement(trigger) && !isFragment(trigger) ? /*#__PURE__*/cloneElement(trigger, triggerProps) : trigger);
|
|
177
|
+
}
|
|
178
|
+
const RETURN_FOCUS_OPTIONS = {
|
|
179
|
+
preventScroll: true
|
|
180
|
+
};
|
|
166
181
|
const THEME_STYLES = {
|
|
167
182
|
light: styles.themeLight,
|
|
168
183
|
dark: styles.themeDark
|
|
@@ -172,7 +187,7 @@ const MODE_STYLES = {
|
|
|
172
187
|
rock: styles.modeRock
|
|
173
188
|
};
|
|
174
189
|
const DropdownRender = (t0, externalRef) => {
|
|
175
|
-
const $ = c(
|
|
190
|
+
const $ = c(57);
|
|
176
191
|
const {
|
|
177
192
|
children,
|
|
178
193
|
trigger,
|
|
@@ -190,8 +205,15 @@ const DropdownRender = (t0, externalRef) => {
|
|
|
190
205
|
closeOnEsc: t6,
|
|
191
206
|
closeOnTab: t7,
|
|
192
207
|
disableFocusLock: t8,
|
|
193
|
-
|
|
194
|
-
|
|
208
|
+
modal: t9,
|
|
209
|
+
initialFocus: t10,
|
|
210
|
+
returnFocus: t11,
|
|
211
|
+
role,
|
|
212
|
+
visuallyHiddenDismiss: t12,
|
|
213
|
+
renderInTrigger: t13,
|
|
214
|
+
disableFlip: t14,
|
|
215
|
+
style: styleFromProps,
|
|
216
|
+
...restProps
|
|
195
217
|
} = t0;
|
|
196
218
|
const isOpenFromProps = t1 === undefined ? false : t1;
|
|
197
219
|
const placement = t2 === undefined ? "bottom-start" : t2;
|
|
@@ -201,8 +223,12 @@ const DropdownRender = (t0, externalRef) => {
|
|
|
201
223
|
const closeOnEsc = t6 === undefined ? true : t6;
|
|
202
224
|
const closeOnTab = t7 === undefined ? false : t7;
|
|
203
225
|
const disableFocusLock = t8 === undefined ? false : t8;
|
|
204
|
-
const
|
|
205
|
-
const
|
|
226
|
+
const modal = t9 === undefined ? false : t9;
|
|
227
|
+
const initialFocus = t10 === undefined ? 0 : t10;
|
|
228
|
+
const returnFocus = t11 === undefined ? true : t11;
|
|
229
|
+
const visuallyHiddenDismiss = t12 === undefined ? false : t12;
|
|
230
|
+
const renderInTrigger = t13 === undefined ? false : t13;
|
|
231
|
+
const disableFlip = t14 === undefined ? false : t14;
|
|
206
232
|
const [popperRef, setPopperRef] = useState(null);
|
|
207
233
|
const [triggerRef, setTriggerRef] = useState(undefined);
|
|
208
234
|
const {
|
|
@@ -212,19 +238,19 @@ const DropdownRender = (t0, externalRef) => {
|
|
|
212
238
|
const scrollableRef = useRef(null);
|
|
213
239
|
const isOpen = typeof triggerRef !== "undefined" || renderInTrigger ? isOpenFromProps : false;
|
|
214
240
|
const ownerDocument = triggerRef?.ownerDocument;
|
|
215
|
-
let
|
|
241
|
+
let t15;
|
|
216
242
|
if ($[0] !== popperRef || $[1] !== triggerRef) {
|
|
217
|
-
|
|
243
|
+
t15 = [popperRef, triggerRef];
|
|
218
244
|
$[0] = popperRef;
|
|
219
245
|
$[1] = triggerRef;
|
|
220
|
-
$[2] =
|
|
246
|
+
$[2] = t15;
|
|
221
247
|
} else {
|
|
222
|
-
|
|
248
|
+
t15 = $[2];
|
|
223
249
|
}
|
|
224
|
-
const outsideClickIgnoreElements =
|
|
225
|
-
let
|
|
250
|
+
const outsideClickIgnoreElements = t15;
|
|
251
|
+
let t16;
|
|
226
252
|
if ($[3] !== isOpen || $[4] !== onRequestClose || $[5] !== outsideClickIgnoreElements || $[6] !== ownerDocument) {
|
|
227
|
-
|
|
253
|
+
t16 = {
|
|
228
254
|
isEnabled: isOpen,
|
|
229
255
|
onOutsideClick: onRequestClose,
|
|
230
256
|
ignoreElements: outsideClickIgnoreElements,
|
|
@@ -234,48 +260,61 @@ const DropdownRender = (t0, externalRef) => {
|
|
|
234
260
|
$[4] = onRequestClose;
|
|
235
261
|
$[5] = outsideClickIgnoreElements;
|
|
236
262
|
$[6] = ownerDocument;
|
|
237
|
-
$[7] =
|
|
263
|
+
$[7] = t16;
|
|
238
264
|
} else {
|
|
239
|
-
|
|
265
|
+
t16 = $[7];
|
|
240
266
|
}
|
|
241
|
-
useOnOutsideClick(
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
if ($[8] !== onRequestClose || $[9] !== ownerDocument || $[10] !==
|
|
245
|
-
|
|
267
|
+
useOnOutsideClick(t16);
|
|
268
|
+
const t17 = isOpen && closeOnEsc;
|
|
269
|
+
let t18;
|
|
270
|
+
if ($[8] !== onRequestClose || $[9] !== ownerDocument || $[10] !== t17) {
|
|
271
|
+
t18 = {
|
|
246
272
|
key: "Escape",
|
|
247
|
-
isEnabled:
|
|
273
|
+
isEnabled: t17,
|
|
248
274
|
onKeyPress: onRequestClose,
|
|
249
275
|
ownerDocument
|
|
250
276
|
};
|
|
251
277
|
$[8] = onRequestClose;
|
|
252
278
|
$[9] = ownerDocument;
|
|
253
|
-
$[10] =
|
|
254
|
-
$[11] =
|
|
279
|
+
$[10] = t17;
|
|
280
|
+
$[11] = t18;
|
|
255
281
|
} else {
|
|
256
|
-
|
|
282
|
+
t18 = $[11];
|
|
257
283
|
}
|
|
258
|
-
useKeyPress(
|
|
259
|
-
const
|
|
260
|
-
let
|
|
261
|
-
if ($[12] !== onRequestClose || $[13] !== ownerDocument || $[14] !==
|
|
262
|
-
|
|
284
|
+
useKeyPress(t18);
|
|
285
|
+
const t19 = isOpen && closeOnTab;
|
|
286
|
+
let t20;
|
|
287
|
+
if ($[12] !== onRequestClose || $[13] !== ownerDocument || $[14] !== t19) {
|
|
288
|
+
t20 = {
|
|
263
289
|
key: "Tab",
|
|
264
|
-
isEnabled:
|
|
290
|
+
isEnabled: t19,
|
|
265
291
|
onKeyPress: onRequestClose,
|
|
266
292
|
ownerDocument
|
|
267
293
|
};
|
|
268
294
|
$[12] = onRequestClose;
|
|
269
295
|
$[13] = ownerDocument;
|
|
270
|
-
$[14] =
|
|
271
|
-
$[15] =
|
|
296
|
+
$[14] = t19;
|
|
297
|
+
$[15] = t20;
|
|
272
298
|
} else {
|
|
273
|
-
|
|
299
|
+
t20 = $[15];
|
|
274
300
|
}
|
|
275
|
-
useKeyPress(
|
|
276
|
-
let
|
|
277
|
-
if ($[16] !==
|
|
278
|
-
|
|
301
|
+
useKeyPress(t20);
|
|
302
|
+
let t21;
|
|
303
|
+
if ($[16] !== popperRef || $[17] !== triggerRef) {
|
|
304
|
+
t21 = {
|
|
305
|
+
reference: triggerRef,
|
|
306
|
+
floating: popperRef
|
|
307
|
+
};
|
|
308
|
+
$[16] = popperRef;
|
|
309
|
+
$[17] = triggerRef;
|
|
310
|
+
$[18] = t21;
|
|
311
|
+
} else {
|
|
312
|
+
t21 = $[18];
|
|
313
|
+
}
|
|
314
|
+
const t22 = isAutoPlacement(placement) ? undefined : placement;
|
|
315
|
+
let t23;
|
|
316
|
+
if ($[19] !== disableFlip || $[20] !== leastMaxHeight || $[21] !== maxHeight || $[22] !== maxWidth || $[23] !== minWidth || $[24] !== placement) {
|
|
317
|
+
t23 = getMiddleware({
|
|
279
318
|
placement,
|
|
280
319
|
maxHeight,
|
|
281
320
|
leastMaxHeight,
|
|
@@ -283,71 +322,157 @@ const DropdownRender = (t0, externalRef) => {
|
|
|
283
322
|
maxWidth,
|
|
284
323
|
disableFlip
|
|
285
324
|
});
|
|
286
|
-
$[
|
|
287
|
-
$[
|
|
288
|
-
$[
|
|
289
|
-
$[
|
|
290
|
-
$[
|
|
291
|
-
$[
|
|
292
|
-
$[
|
|
325
|
+
$[19] = disableFlip;
|
|
326
|
+
$[20] = leastMaxHeight;
|
|
327
|
+
$[21] = maxHeight;
|
|
328
|
+
$[22] = maxWidth;
|
|
329
|
+
$[23] = minWidth;
|
|
330
|
+
$[24] = placement;
|
|
331
|
+
$[25] = t23;
|
|
332
|
+
} else {
|
|
333
|
+
t23 = $[25];
|
|
334
|
+
}
|
|
335
|
+
const t24 = popperRef !== null;
|
|
336
|
+
let t25;
|
|
337
|
+
if ($[26] !== t21 || $[27] !== t22 || $[28] !== t23 || $[29] !== t24) {
|
|
338
|
+
t25 = {
|
|
339
|
+
elements: t21,
|
|
340
|
+
placement: t22,
|
|
341
|
+
middleware: t23,
|
|
342
|
+
whileElementsMounted: autoUpdateDropdown,
|
|
343
|
+
open: t24
|
|
344
|
+
};
|
|
345
|
+
$[26] = t21;
|
|
346
|
+
$[27] = t22;
|
|
347
|
+
$[28] = t23;
|
|
348
|
+
$[29] = t24;
|
|
349
|
+
$[30] = t25;
|
|
293
350
|
} else {
|
|
294
|
-
|
|
351
|
+
t25 = $[30];
|
|
295
352
|
}
|
|
296
353
|
const {
|
|
297
|
-
|
|
298
|
-
|
|
354
|
+
floatingStyles,
|
|
355
|
+
middlewareData,
|
|
356
|
+
placement: floatingPlacement,
|
|
357
|
+
isPositioned,
|
|
299
358
|
update
|
|
300
|
-
} =
|
|
301
|
-
const resolvedPlacement =
|
|
302
|
-
let
|
|
303
|
-
if ($[
|
|
304
|
-
|
|
359
|
+
} = useFloating(t25);
|
|
360
|
+
const resolvedPlacement = isPositioned ? floatingPlacement : null;
|
|
361
|
+
let t26;
|
|
362
|
+
if ($[31] !== cancelCloseAnimation || $[32] !== isOpen || $[33] !== popperRef || $[34] !== resolvedPlacement) {
|
|
363
|
+
t26 = {
|
|
305
364
|
isOpen,
|
|
306
365
|
cancelCloseAnimation,
|
|
307
366
|
contentRef: scrollableRef,
|
|
308
367
|
popperElement: popperRef,
|
|
309
368
|
resolvedPlacement
|
|
310
369
|
};
|
|
311
|
-
$[
|
|
312
|
-
$[
|
|
313
|
-
$[
|
|
314
|
-
$[
|
|
315
|
-
$[
|
|
370
|
+
$[31] = cancelCloseAnimation;
|
|
371
|
+
$[32] = isOpen;
|
|
372
|
+
$[33] = popperRef;
|
|
373
|
+
$[34] = resolvedPlacement;
|
|
374
|
+
$[35] = t26;
|
|
316
375
|
} else {
|
|
317
|
-
|
|
376
|
+
t26 = $[35];
|
|
318
377
|
}
|
|
319
|
-
const dropdownState = useDropdownState(
|
|
320
|
-
let
|
|
321
|
-
if ($[
|
|
322
|
-
|
|
378
|
+
const dropdownState = useDropdownState(t26);
|
|
379
|
+
let t27;
|
|
380
|
+
if ($[36] !== popperRef || $[37] !== update) {
|
|
381
|
+
t27 = () => ({
|
|
323
382
|
scheduleUpdate: () => {
|
|
324
|
-
|
|
383
|
+
if (popperRef) {
|
|
384
|
+
update();
|
|
385
|
+
}
|
|
325
386
|
}
|
|
326
387
|
});
|
|
327
|
-
$[
|
|
328
|
-
$[
|
|
388
|
+
$[36] = popperRef;
|
|
389
|
+
$[37] = update;
|
|
390
|
+
$[38] = t27;
|
|
329
391
|
} else {
|
|
330
|
-
|
|
392
|
+
t27 = $[38];
|
|
331
393
|
}
|
|
332
|
-
useImperativeHandle(externalRef,
|
|
394
|
+
useImperativeHandle(externalRef, t27);
|
|
333
395
|
const {
|
|
334
396
|
dropdownZIndex
|
|
335
397
|
} = useLayeringContext();
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
398
|
+
const isFocusLockActive = !disableFocusLock && (dropdownState === DROPDOWN_STATES.OPENING_PREPARE || dropdownState === DROPDOWN_STATES.OPENING || dropdownState === DROPDOWN_STATES.OPEN);
|
|
399
|
+
const isModal = (role === "alertdialog" || modal) && !disableFocusLock;
|
|
400
|
+
const {
|
|
401
|
+
triggerProps,
|
|
402
|
+
getPopupProps
|
|
403
|
+
} = useDropdownAria({
|
|
404
|
+
role,
|
|
405
|
+
isOpen,
|
|
406
|
+
isModal,
|
|
407
|
+
trigger,
|
|
408
|
+
id: restProps.id
|
|
409
|
+
});
|
|
410
|
+
useHideOthers(isModal && isFocusLockActive, popperRef);
|
|
411
|
+
const t28 = role !== undefined;
|
|
412
|
+
let t29;
|
|
413
|
+
if ($[39] !== t28 || $[40] !== trigger || $[41] !== triggerProps) {
|
|
414
|
+
t29 = renderTrigger({
|
|
415
|
+
trigger,
|
|
416
|
+
triggerProps,
|
|
417
|
+
setTriggerRef,
|
|
418
|
+
hasRole: t28
|
|
419
|
+
});
|
|
420
|
+
$[39] = t28;
|
|
421
|
+
$[40] = trigger;
|
|
422
|
+
$[41] = triggerProps;
|
|
423
|
+
$[42] = t29;
|
|
347
424
|
} else {
|
|
348
|
-
|
|
425
|
+
t29 = $[42];
|
|
349
426
|
}
|
|
350
|
-
const triggerRenderer =
|
|
427
|
+
const triggerRenderer = t29;
|
|
428
|
+
let t30;
|
|
429
|
+
if ($[43] !== initialFocus) {
|
|
430
|
+
t30 = lockElement => {
|
|
431
|
+
if (lockElement.contains(lockElement.ownerDocument.activeElement)) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
getInitialFocusElement(lockElement, initialFocus)?.focus({
|
|
435
|
+
preventScroll: true
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
$[43] = initialFocus;
|
|
439
|
+
$[44] = t30;
|
|
440
|
+
} else {
|
|
441
|
+
t30 = $[44];
|
|
442
|
+
}
|
|
443
|
+
const handleFocusLockActivation = t30;
|
|
444
|
+
let t31;
|
|
445
|
+
if ($[45] !== triggerRef) {
|
|
446
|
+
t31 = returnTo => {
|
|
447
|
+
const triggerElement = returnTo === returnTo.ownerDocument.body ? getFirstTabbableElement(triggerRef) : null;
|
|
448
|
+
if (!triggerElement) {
|
|
449
|
+
return RETURN_FOCUS_OPTIONS;
|
|
450
|
+
}
|
|
451
|
+
Promise.resolve().then(() => triggerElement.focus(RETURN_FOCUS_OPTIONS));
|
|
452
|
+
return false;
|
|
453
|
+
};
|
|
454
|
+
$[45] = triggerRef;
|
|
455
|
+
$[46] = t31;
|
|
456
|
+
} else {
|
|
457
|
+
t31 = $[46];
|
|
458
|
+
}
|
|
459
|
+
const handleReturnFocus = t31;
|
|
460
|
+
let t32;
|
|
461
|
+
if ($[47] !== isModal || $[48] !== onRequestClose || $[49] !== visuallyHiddenDismiss) {
|
|
462
|
+
t32 = isModal && visuallyHiddenDismiss ? /*#__PURE__*/React.createElement("button", {
|
|
463
|
+
type: "button",
|
|
464
|
+
tabIndex: -1,
|
|
465
|
+
className: styles.visuallyHidden,
|
|
466
|
+
onClick: onRequestClose
|
|
467
|
+
}, typeof visuallyHiddenDismiss === "string" ? visuallyHiddenDismiss : "Dismiss") : null;
|
|
468
|
+
$[47] = isModal;
|
|
469
|
+
$[48] = onRequestClose;
|
|
470
|
+
$[49] = visuallyHiddenDismiss;
|
|
471
|
+
$[50] = t32;
|
|
472
|
+
} else {
|
|
473
|
+
t32 = $[50];
|
|
474
|
+
}
|
|
475
|
+
const dismissButton = t32;
|
|
351
476
|
const dropdownShouldBeRendered = dropdownState !== DROPDOWN_STATES.CLOSE;
|
|
352
477
|
const wrapperIsInitial = dropdownState === DROPDOWN_STATES.OPENING_PREPARE;
|
|
353
478
|
const wrapperShouldBeHidden = wrapperIsInitial || dropdownState === DROPDOWN_STATES.CLOSING;
|
|
@@ -360,86 +485,66 @@ const DropdownRender = (t0, externalRef) => {
|
|
|
360
485
|
noProvider
|
|
361
486
|
} = useContext(ThemeContext);
|
|
362
487
|
const theme = themeFromProps || (noProvider ? themeFromCss : themeFromContext);
|
|
363
|
-
let
|
|
364
|
-
if ($[
|
|
365
|
-
|
|
366
|
-
$[
|
|
367
|
-
$[33] = theme;
|
|
368
|
-
$[34] = t21;
|
|
369
|
-
} else {
|
|
370
|
-
t21 = $[34];
|
|
371
|
-
}
|
|
372
|
-
const childrenTheme = t21;
|
|
373
|
-
let t22;
|
|
374
|
-
if ($[35] !== attributes.popper || $[36] !== children || $[37] !== childrenTheme || $[38] !== className || $[39] !== disableFocusLock || $[40] !== dropdownShouldBeRendered || $[41] !== dropdownState || $[42] !== dropdownZIndex || $[43] !== maxHeight || $[44] !== mode || $[45] !== noProvider || $[46] !== ownerDocument?.body || $[47] !== popperStyles || $[48] !== primaryColors || $[49] !== renderInTrigger || $[50] !== scrollableStyles || $[51] !== setContentEl || $[52] !== theme || $[53] !== triggerRef || $[54] !== wrapperIsInitial || $[55] !== wrapperShouldBeHidden) {
|
|
375
|
-
t22 = dropdownShouldBeRendered && /*#__PURE__*/React.createElement(Portal, {
|
|
376
|
-
target: renderInTrigger ? triggerRef : ownerDocument?.body
|
|
377
|
-
}, /*#__PURE__*/React.createElement("div", Object.assign({
|
|
378
|
-
ref: setPopperRef,
|
|
379
|
-
style: {
|
|
380
|
-
maxHeight,
|
|
381
|
-
...popperStyles.popper,
|
|
382
|
-
zIndex: dropdownZIndex,
|
|
383
|
-
...primaryColors
|
|
384
|
-
},
|
|
385
|
-
className: cn(styles.dropdown, className, MODE_STYLES[mode], THEME_STYLES[theme]),
|
|
386
|
-
"data-test": "dropdown"
|
|
387
|
-
}, attributes.popper), /*#__PURE__*/React.createElement(LayeringProvider, {
|
|
388
|
-
baseLayer: "dropdown"
|
|
389
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
390
|
-
ref: scrollableRef,
|
|
391
|
-
style: scrollableStyles,
|
|
392
|
-
className: cn(styles.contentWrapper, wrapperIsInitial && styles.wrapperInitial, wrapperShouldBeHidden && styles.wrapperHidden),
|
|
393
|
-
"data-test": "dropdown-content"
|
|
394
|
-
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
395
|
-
ignoreThemeValueForCSSApi: noProvider,
|
|
396
|
-
theme: childrenTheme
|
|
397
|
-
}, /*#__PURE__*/React.createElement(FocusLock, {
|
|
398
|
-
className: THEME_STYLES[childrenTheme],
|
|
399
|
-
ref: setContentEl,
|
|
400
|
-
disabled: dropdownState === DROPDOWN_STATES.CLOSING || disableFocusLock,
|
|
401
|
-
returnFocus: {
|
|
402
|
-
preventScroll: true
|
|
403
|
-
},
|
|
404
|
-
focusOptions: {
|
|
405
|
-
preventScroll: true
|
|
406
|
-
}
|
|
407
|
-
}, children))))));
|
|
408
|
-
$[35] = attributes.popper;
|
|
409
|
-
$[36] = children;
|
|
410
|
-
$[37] = childrenTheme;
|
|
411
|
-
$[38] = className;
|
|
412
|
-
$[39] = disableFocusLock;
|
|
413
|
-
$[40] = dropdownShouldBeRendered;
|
|
414
|
-
$[41] = dropdownState;
|
|
415
|
-
$[42] = dropdownZIndex;
|
|
416
|
-
$[43] = maxHeight;
|
|
417
|
-
$[44] = mode;
|
|
418
|
-
$[45] = noProvider;
|
|
419
|
-
$[46] = ownerDocument?.body;
|
|
420
|
-
$[47] = popperStyles;
|
|
421
|
-
$[48] = primaryColors;
|
|
422
|
-
$[49] = renderInTrigger;
|
|
423
|
-
$[50] = scrollableStyles;
|
|
424
|
-
$[51] = setContentEl;
|
|
488
|
+
let t33;
|
|
489
|
+
if ($[51] !== mode || $[52] !== theme) {
|
|
490
|
+
t33 = mode === "rock" ? getInverseTheme(theme) : theme;
|
|
491
|
+
$[51] = mode;
|
|
425
492
|
$[52] = theme;
|
|
426
|
-
$[53] =
|
|
427
|
-
$[54] = wrapperIsInitial;
|
|
428
|
-
$[55] = wrapperShouldBeHidden;
|
|
429
|
-
$[56] = t22;
|
|
493
|
+
$[53] = t33;
|
|
430
494
|
} else {
|
|
431
|
-
|
|
495
|
+
t33 = $[53];
|
|
432
496
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
497
|
+
const childrenTheme = t33;
|
|
498
|
+
const t34 = dropdownShouldBeRendered && /*#__PURE__*/React.createElement(Portal, {
|
|
499
|
+
target: renderInTrigger ? triggerRef : ownerDocument?.body
|
|
500
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
501
|
+
ref: setPopperRef,
|
|
502
|
+
style: {
|
|
503
|
+
...styleFromProps,
|
|
504
|
+
maxHeight: middlewareData.applyMaxSize?.maxHeight ?? maxHeight,
|
|
505
|
+
...floatingStyles,
|
|
506
|
+
zIndex: dropdownZIndex,
|
|
507
|
+
...primaryColors
|
|
508
|
+
},
|
|
509
|
+
className: cn(styles.dropdown, className, MODE_STYLES[mode], THEME_STYLES[theme]),
|
|
510
|
+
"data-test": "dropdown",
|
|
511
|
+
"data-popper-placement": resolvedPlacement ?? undefined
|
|
512
|
+
}, /*#__PURE__*/React.createElement(LayeringProvider, {
|
|
513
|
+
baseLayer: "dropdown"
|
|
514
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
515
|
+
ref: scrollableRef,
|
|
516
|
+
style: scrollableStyles,
|
|
517
|
+
className: cn(styles.contentWrapper, wrapperIsInitial && styles.wrapperInitial, wrapperShouldBeHidden && styles.wrapperHidden),
|
|
518
|
+
"data-test": "dropdown-content"
|
|
519
|
+
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
520
|
+
ignoreThemeValueForCSSApi: noProvider,
|
|
521
|
+
theme: childrenTheme
|
|
522
|
+
}, /*#__PURE__*/React.createElement(FocusLock, {
|
|
523
|
+
className: THEME_STYLES[childrenTheme],
|
|
524
|
+
ref: setContentEl,
|
|
525
|
+
disabled: !isFocusLockActive,
|
|
526
|
+
returnFocus: returnFocus && handleReturnFocus,
|
|
527
|
+
focusOptions: {
|
|
528
|
+
preventScroll: true
|
|
529
|
+
},
|
|
530
|
+
onActivation: handleFocusLockActivation,
|
|
531
|
+
lockProps: {
|
|
532
|
+
...getPopupProps(restProps),
|
|
533
|
+
...(initialFocus === "container" && {
|
|
534
|
+
tabIndex: -1
|
|
535
|
+
})
|
|
536
|
+
}
|
|
537
|
+
}, dismissButton, children, dismissButton))))));
|
|
538
|
+
let t35;
|
|
539
|
+
if ($[54] !== t34 || $[55] !== triggerRenderer) {
|
|
540
|
+
t35 = /*#__PURE__*/React.createElement(React.Fragment, null, triggerRenderer, t34);
|
|
541
|
+
$[54] = t34;
|
|
542
|
+
$[55] = triggerRenderer;
|
|
543
|
+
$[56] = t35;
|
|
439
544
|
} else {
|
|
440
|
-
|
|
545
|
+
t35 = $[56];
|
|
441
546
|
}
|
|
442
|
-
return
|
|
547
|
+
return t35;
|
|
443
548
|
};
|
|
444
549
|
/* eslint-enable react/prop-types */
|
|
445
550
|
const Dropdown = /*#__PURE__*/React.forwardRef(DropdownRender);
|
|
@@ -454,6 +559,13 @@ Dropdown.propTypes = {
|
|
|
454
559
|
maxWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
455
560
|
maxHeight: PropTypes.number,
|
|
456
561
|
leastMaxHeight: PropTypes.number,
|
|
562
|
+
modal: PropTypes.bool,
|
|
563
|
+
initialFocus: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['container']), PropTypes.shape({
|
|
564
|
+
current: PropTypes.any
|
|
565
|
+
})]),
|
|
566
|
+
returnFocus: PropTypes.bool,
|
|
567
|
+
role: PropTypes.oneOf(['dialog', 'alertdialog', 'menu', 'listbox', 'grid', 'tree']),
|
|
568
|
+
visuallyHiddenDismiss: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
457
569
|
renderInTrigger: PropTypes.bool,
|
|
458
570
|
disableFlip: PropTypes.bool
|
|
459
571
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var styles = {"themeLight":"
|
|
1
|
+
var styles = {"themeLight":"_themeLight_17wpuuu_7","themeDark":"_themeDark_17wpuuu_10","dropdown":"_dropdown_17wpuuu_14","triggerWrapper":"_triggerWrapper_17wpuuu_21","visuallyHidden":"_visuallyHidden_17wpuuu_25","contentWrapper":"_contentWrapper_17wpuuu_41","wrapperInitial":"_wrapperInitial_17wpuuu_57","wrapperHidden":"_wrapperHidden_17wpuuu_61","modeClassic":"_modeClassic_17wpuuu_81","modeRock":"_modeRock_17wpuuu_85"};
|
|
2
2
|
|
|
3
3
|
export { styles as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DropdownInitialFocus } from './types';
|
|
2
|
+
/** The element itself, if it's tabbable, or its first tabbable descendant */
|
|
3
|
+
export declare function getFirstTabbableElement(element: Element | null | undefined): HTMLElement | null;
|
|
4
|
+
/**
|
|
5
|
+
* The element to focus when the focus lock activates.
|
|
6
|
+
* `null` leaves the default behavior of the lock: it focuses the first tabbable element
|
|
7
|
+
* or the one with `data-autofocus`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getInitialFocusElement(lockElement: HTMLElement, initialFocus: DropdownInitialFocus): HTMLElement | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const TABBABLE_SELECTOR = ['a[href]', 'area[href]', 'button:not([disabled])', 'input:not([disabled]):not([type="hidden"])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'summary', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])', '[tabindex]'].join(', ');
|
|
2
|
+
function isTabbable(element) {
|
|
3
|
+
return element.matches(TABBABLE_SELECTOR) && element.tabIndex >= 0 && element.getClientRects().length > 0 && !element.closest('[inert], fieldset[disabled]');
|
|
4
|
+
}
|
|
5
|
+
function getTabbableElements(container) {
|
|
6
|
+
return Array.from(container.querySelectorAll(TABBABLE_SELECTOR)).filter(isTabbable);
|
|
7
|
+
}
|
|
8
|
+
/** The element itself, if it's tabbable, or its first tabbable descendant */
|
|
9
|
+
function getFirstTabbableElement(element) {
|
|
10
|
+
if (!element) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return isTabbable(element) ? element : getTabbableElements(element)[0] ?? null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The element to focus when the focus lock activates.
|
|
17
|
+
* `null` leaves the default behavior of the lock: it focuses the first tabbable element
|
|
18
|
+
* or the one with `data-autofocus`.
|
|
19
|
+
*/
|
|
20
|
+
function getInitialFocusElement(lockElement, initialFocus) {
|
|
21
|
+
if (initialFocus === 'container') {
|
|
22
|
+
return lockElement;
|
|
23
|
+
}
|
|
24
|
+
if (typeof initialFocus === 'number') {
|
|
25
|
+
return initialFocus === 0 ? null : getTabbableElements(lockElement)[initialFocus] ?? null;
|
|
26
|
+
}
|
|
27
|
+
return initialFocus.current;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { getFirstTabbableElement, getInitialFocusElement };
|