@lumx/react 4.24.1-alpha.1 → 4.24.1-next.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/index.d.ts +2 -7
- package/index.js +63 -140
- package/index.js.map +1 -1
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -2487,18 +2487,13 @@ interface DialogProps extends GenericProps$1, HasCloseMode$1, BaseDialogProps {
|
|
|
2487
2487
|
size?: DialogSizes;
|
|
2488
2488
|
/** Z-axis position. */
|
|
2489
2489
|
zIndex?: number;
|
|
2490
|
-
/**
|
|
2491
|
-
* Additional props for the dialog container element.
|
|
2492
|
-
* Set `'aria-modal': false` to make the dialog non-modal: the page stays usable (no focus trap, no overlay,
|
|
2493
|
-
* no close on click away, rendered in place instead of in a portal) and escape only closes the dialog when the
|
|
2494
|
-
* focus is inside.
|
|
2495
|
-
*/
|
|
2490
|
+
/** Z-axis position. */
|
|
2496
2491
|
dialogProps?: GenericProps$1;
|
|
2497
2492
|
/** On close callback. */
|
|
2498
2493
|
onClose?(): void;
|
|
2499
2494
|
/** Callback called when the open animation starts and the close animation finishes. */
|
|
2500
2495
|
onVisibilityChange?(isVisible: boolean): void;
|
|
2501
|
-
/**
|
|
2496
|
+
/** whether to disable the scroll on the body or not */
|
|
2502
2497
|
disableBodyScroll?: boolean;
|
|
2503
2498
|
/** Children */
|
|
2504
2499
|
children?: React__default.ReactNode;
|
package/index.js
CHANGED
|
@@ -6765,16 +6765,13 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
|
|
|
6765
6765
|
flag = true;
|
|
6766
6766
|
break;
|
|
6767
6767
|
case 'Escape':
|
|
6768
|
-
// 2-tier: close if open, otherwise clear
|
|
6769
|
-
// When there is nothing to close or clear, let Escape propagate
|
|
6770
|
-
// (ex: so a surrounding dialog can close).
|
|
6768
|
+
// 2-tier: close if open, otherwise clear value.
|
|
6771
6769
|
if (handle.isOpen) {
|
|
6772
6770
|
handle.setIsOpen(false);
|
|
6773
|
-
|
|
6774
|
-
} else if (triggerEl.tagName === 'INPUT' && triggerEl.value) {
|
|
6771
|
+
} else {
|
|
6775
6772
|
handle.select(null);
|
|
6776
|
-
flag = true;
|
|
6777
6773
|
}
|
|
6774
|
+
flag = true;
|
|
6778
6775
|
break;
|
|
6779
6776
|
case 'PageUp':
|
|
6780
6777
|
if (handle.isOpen && nav?.selectors.activeItem) {
|
|
@@ -7272,11 +7269,8 @@ function setupComboboxButton(button, callbacks) {
|
|
|
7272
7269
|
// Close if open; never clear selection (button-mode has no text input).
|
|
7273
7270
|
if (combobox.isOpen) {
|
|
7274
7271
|
combobox.setIsOpen(false);
|
|
7275
|
-
return true;
|
|
7276
7272
|
}
|
|
7277
|
-
|
|
7278
|
-
// The base handler does not clear the selection on a button trigger.
|
|
7279
|
-
return false;
|
|
7273
|
+
return true;
|
|
7280
7274
|
default:
|
|
7281
7275
|
// Printable characters → typeahead.
|
|
7282
7276
|
if (isPrintableKey(event)) {
|
|
@@ -9266,64 +9260,6 @@ function getFirstAndLastFocusable(parentElement) {
|
|
|
9266
9260
|
return {};
|
|
9267
9261
|
}
|
|
9268
9262
|
|
|
9269
|
-
/**
|
|
9270
|
-
* Focus the zone element itself (last-resort fallback, e.g. an empty dialog).
|
|
9271
|
-
*
|
|
9272
|
-
* Adds a `tabindex="-1"` if needed to make the zone programmatically focusable, removed when the signal aborts.
|
|
9273
|
-
*
|
|
9274
|
-
* @param focusZoneElement The zone element.
|
|
9275
|
-
* @param signal AbortSignal used to remove the added `tabindex`.
|
|
9276
|
-
*/
|
|
9277
|
-
function focusZoneFallback(focusZoneElement, signal) {
|
|
9278
|
-
if (!focusZoneElement.hasAttribute('tabindex')) {
|
|
9279
|
-
focusZoneElement.setAttribute('tabindex', '-1');
|
|
9280
|
-
signal.addEventListener('abort', () => focusZoneElement.removeAttribute('tabindex'), {
|
|
9281
|
-
once: true
|
|
9282
|
-
});
|
|
9283
|
-
}
|
|
9284
|
-
focusZoneElement.focus({
|
|
9285
|
-
preventScroll: true
|
|
9286
|
-
});
|
|
9287
|
-
}
|
|
9288
|
-
|
|
9289
|
-
/**
|
|
9290
|
-
* Move the focus into the `focusZoneElement`:
|
|
9291
|
-
* 1. Focus `focusElement` if provided and contained in the zone.
|
|
9292
|
-
* 2. Otherwise focus the first focusable descendant.
|
|
9293
|
-
* 3. Otherwise focus the zone element itself (falling back to setting `tabindex="-1"` if needed) so that
|
|
9294
|
-
* keyboard users (especially screen reader users) land inside the zone (e.g. an empty dialog).
|
|
9295
|
-
*
|
|
9296
|
-
* @param options Initial focus configuration.
|
|
9297
|
-
* @param signal AbortSignal used to tear down (removes the fallback `tabindex` if it was added).
|
|
9298
|
-
*/
|
|
9299
|
-
function setupInitialFocus(options, signal) {
|
|
9300
|
-
const {
|
|
9301
|
-
focusZoneElement,
|
|
9302
|
-
focusElement
|
|
9303
|
-
} = options;
|
|
9304
|
-
if (!focusZoneElement || signal.aborted) {
|
|
9305
|
-
return;
|
|
9306
|
-
}
|
|
9307
|
-
if (focusElement && focusZoneElement.contains(focusElement)) {
|
|
9308
|
-
// Focus the given element.
|
|
9309
|
-
focusElement.focus({
|
|
9310
|
-
preventScroll: true
|
|
9311
|
-
});
|
|
9312
|
-
return;
|
|
9313
|
-
}
|
|
9314
|
-
const firstFocusable = getFirstAndLastFocusable(focusZoneElement).first;
|
|
9315
|
-
if (firstFocusable) {
|
|
9316
|
-
// Focus the first focusable descendant.
|
|
9317
|
-
firstFocusable.focus({
|
|
9318
|
-
preventScroll: true
|
|
9319
|
-
});
|
|
9320
|
-
return;
|
|
9321
|
-
}
|
|
9322
|
-
|
|
9323
|
-
// No focusable descendant — fall back to the zone itself.
|
|
9324
|
-
focusZoneFallback(focusZoneElement, signal);
|
|
9325
|
-
}
|
|
9326
|
-
|
|
9327
9263
|
/**
|
|
9328
9264
|
* Shared listener tower for focus traps.
|
|
9329
9265
|
*
|
|
@@ -9331,13 +9267,14 @@ function setupInitialFocus(options, signal) {
|
|
|
9331
9267
|
* registered trap is re-enabled.
|
|
9332
9268
|
*/
|
|
9333
9269
|
const FOCUS_TRAPS = makeListenerTowerContext();
|
|
9334
|
-
|
|
9335
|
-
/** Focus trap options: the zone in which to trap the focus, and the element to focus on activation. */
|
|
9336
|
-
|
|
9337
9270
|
/**
|
|
9338
9271
|
* Trap 'Tab' focus switch inside the `focusZoneElement`.
|
|
9339
9272
|
*
|
|
9340
|
-
* Setup behavior:
|
|
9273
|
+
* Setup behavior:
|
|
9274
|
+
* 1. Focus `focusElement` if provided and contained in the zone.
|
|
9275
|
+
* 2. Otherwise focus the first focusable descendant.
|
|
9276
|
+
* 3. Otherwise focus the zone element itself (falling back to setting `tabindex="-1"` if needed) so that
|
|
9277
|
+
* keyboard users (especially screen reader users) land inside the trapped region (e.g. an empty dialog).
|
|
9341
9278
|
*
|
|
9342
9279
|
* Tab key behavior:
|
|
9343
9280
|
* - With at least one focusable descendant: focus cycles between the first and last focusable in the zone.
|
|
@@ -9350,7 +9287,8 @@ const FOCUS_TRAPS = makeListenerTowerContext();
|
|
|
9350
9287
|
*/
|
|
9351
9288
|
function setupFocusTrap(options, signal) {
|
|
9352
9289
|
const {
|
|
9353
|
-
focusZoneElement
|
|
9290
|
+
focusZoneElement,
|
|
9291
|
+
focusElement
|
|
9354
9292
|
} = options;
|
|
9355
9293
|
if (!focusZoneElement || signal.aborted) {
|
|
9356
9294
|
return;
|
|
@@ -9359,6 +9297,25 @@ function setupFocusTrap(options, signal) {
|
|
|
9359
9297
|
// The root node is either the Document (regular DOM) or a ShadowRoot (shadow DOM portal).
|
|
9360
9298
|
const rootNode = focusZoneElement.getRootNode();
|
|
9361
9299
|
|
|
9300
|
+
// Track whether we added a `tabindex="-1"` so we can restore the original state on teardown.
|
|
9301
|
+
let addedTabIndex = false;
|
|
9302
|
+
|
|
9303
|
+
/** Make the zone element programmatically focusable (so we can fall back to it). */
|
|
9304
|
+
const ensureZoneIsFocusable = () => {
|
|
9305
|
+
if (!focusZoneElement.hasAttribute('tabindex')) {
|
|
9306
|
+
focusZoneElement.setAttribute('tabindex', '-1');
|
|
9307
|
+
addedTabIndex = true;
|
|
9308
|
+
}
|
|
9309
|
+
};
|
|
9310
|
+
|
|
9311
|
+
/** Focus the zone element itself as a last-resort fallback. */
|
|
9312
|
+
const focusZoneFallback = () => {
|
|
9313
|
+
ensureZoneIsFocusable();
|
|
9314
|
+
focusZoneElement.focus({
|
|
9315
|
+
preventScroll: true
|
|
9316
|
+
});
|
|
9317
|
+
};
|
|
9318
|
+
|
|
9362
9319
|
// Trap 'Tab' key down focus switch into the focus zone.
|
|
9363
9320
|
const trapTabFocusInFocusZone = evt => {
|
|
9364
9321
|
if (evt.key !== 'Tab') {
|
|
@@ -9369,7 +9326,7 @@ function setupFocusTrap(options, signal) {
|
|
|
9369
9326
|
// Prevent focus switch if no focusable available — pin focus on the zone itself.
|
|
9370
9327
|
if (!focusable.first) {
|
|
9371
9328
|
evt.preventDefault();
|
|
9372
|
-
focusZoneFallback(
|
|
9329
|
+
focusZoneFallback();
|
|
9373
9330
|
return;
|
|
9374
9331
|
}
|
|
9375
9332
|
const {
|
|
@@ -9402,11 +9359,32 @@ function setupFocusTrap(options, signal) {
|
|
|
9402
9359
|
};
|
|
9403
9360
|
|
|
9404
9361
|
// SETUP: focus initial element.
|
|
9405
|
-
|
|
9362
|
+
if (focusElement && focusZoneElement.contains(focusElement)) {
|
|
9363
|
+
// Focus the given element.
|
|
9364
|
+
focusElement.focus({
|
|
9365
|
+
preventScroll: true
|
|
9366
|
+
});
|
|
9367
|
+
} else {
|
|
9368
|
+
const firstFocusable = getFirstAndLastFocusable(focusZoneElement).first;
|
|
9369
|
+
if (firstFocusable) {
|
|
9370
|
+
// Focus the first focusable descendant.
|
|
9371
|
+
firstFocusable.focus({
|
|
9372
|
+
preventScroll: true
|
|
9373
|
+
});
|
|
9374
|
+
} else {
|
|
9375
|
+
// No focusable descendant — fall back to the zone itself (e.g. an empty dialog).
|
|
9376
|
+
focusZoneFallback();
|
|
9377
|
+
}
|
|
9378
|
+
}
|
|
9406
9379
|
FOCUS_TRAPS.register(focusTrap);
|
|
9407
9380
|
|
|
9408
9381
|
// TEARDOWN.
|
|
9409
|
-
signal.addEventListener('abort', () =>
|
|
9382
|
+
signal.addEventListener('abort', () => {
|
|
9383
|
+
FOCUS_TRAPS.unregister(focusTrap);
|
|
9384
|
+
if (addedTabIndex) {
|
|
9385
|
+
focusZoneElement.removeAttribute('tabindex');
|
|
9386
|
+
}
|
|
9387
|
+
}, {
|
|
9410
9388
|
once: true
|
|
9411
9389
|
});
|
|
9412
9390
|
}
|
|
@@ -12178,23 +12156,6 @@ const useTransitionVisibility = (ref, isComponentVisible, timeout, onVisibilityC
|
|
|
12178
12156
|
return isVisible || isComponentVisible;
|
|
12179
12157
|
};
|
|
12180
12158
|
|
|
12181
|
-
/**
|
|
12182
|
-
* Check if the focus is on the given element or inside it.
|
|
12183
|
-
*
|
|
12184
|
-
* Reads the active element of the element's own root node (Document or ShadowRoot), so it also works when the
|
|
12185
|
-
* element lives in a shadow DOM.
|
|
12186
|
-
*
|
|
12187
|
-
* @param element The element to check.
|
|
12188
|
-
* @return whether the active element is the element itself or one of its descendants.
|
|
12189
|
-
*/
|
|
12190
|
-
function isFocusWithin(element) {
|
|
12191
|
-
if (!element) return false;
|
|
12192
|
-
const {
|
|
12193
|
-
activeElement
|
|
12194
|
-
} = element.getRootNode();
|
|
12195
|
-
return Boolean(activeElement && element.contains(activeElement));
|
|
12196
|
-
}
|
|
12197
|
-
|
|
12198
12159
|
/**
|
|
12199
12160
|
* Dialog label id key in IdsRegistry
|
|
12200
12161
|
*/
|
|
@@ -12241,7 +12202,6 @@ const DialogShell = props => {
|
|
|
12241
12202
|
isVisible,
|
|
12242
12203
|
size = DEFAULT_PROPS$U.size,
|
|
12243
12204
|
zIndex,
|
|
12244
|
-
isModal = true,
|
|
12245
12205
|
children,
|
|
12246
12206
|
Portal,
|
|
12247
12207
|
HeadingLevelProvider,
|
|
@@ -12250,21 +12210,19 @@ const DialogShell = props => {
|
|
|
12250
12210
|
...forwardedProps
|
|
12251
12211
|
} = props;
|
|
12252
12212
|
return /*#__PURE__*/jsx(Portal, {
|
|
12253
|
-
enabled: isModal,
|
|
12254
12213
|
children: /*#__PURE__*/jsxs("div", {
|
|
12255
12214
|
ref: ref,
|
|
12256
12215
|
...forwardedProps,
|
|
12257
12216
|
className: classnames(className, block$N({
|
|
12258
12217
|
'is-hidden': !isOpen,
|
|
12259
12218
|
'is-loading': isLoading,
|
|
12260
|
-
'is-non-modal': !isModal,
|
|
12261
12219
|
'is-shown': isOpen || isVisible,
|
|
12262
12220
|
[`size-${size}`]: Boolean(size)
|
|
12263
12221
|
})),
|
|
12264
12222
|
style: {
|
|
12265
12223
|
zIndex
|
|
12266
12224
|
},
|
|
12267
|
-
children: [
|
|
12225
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
12268
12226
|
className: element$C('overlay')
|
|
12269
12227
|
}), /*#__PURE__*/jsx(HeadingLevelProvider, {
|
|
12270
12228
|
level: 2,
|
|
@@ -12302,14 +12260,6 @@ function resolveAccessibleNameProps(ariaLabel, ariaLabelledBy) {
|
|
|
12302
12260
|
* that has resolved `labelId` from the ids registry.
|
|
12303
12261
|
*/
|
|
12304
12262
|
|
|
12305
|
-
/**
|
|
12306
|
-
* Whether the dialog is modal: it is, unless `dialogProps['aria-modal']` is `false` (or `'false'`).
|
|
12307
|
-
*
|
|
12308
|
-
* @param dialogProps Props of the dialog container element.
|
|
12309
|
-
* @return whether the dialog is modal.
|
|
12310
|
-
*/
|
|
12311
|
-
const isDialogModal = dialogProps => dialogProps?.['aria-modal'] !== false && dialogProps?.['aria-modal'] !== 'false';
|
|
12312
|
-
|
|
12313
12263
|
/**
|
|
12314
12264
|
* Dialog content: the `role="dialog"` element + header/body/footer.
|
|
12315
12265
|
*
|
|
@@ -12351,17 +12301,14 @@ const DialogContent$1 = props => {
|
|
|
12351
12301
|
'aria-labelledby': dialogAriaLabelledBy,
|
|
12352
12302
|
...restDialogProps
|
|
12353
12303
|
} = dialogProps ?? {};
|
|
12354
|
-
const isModal = isDialogModal(restDialogProps);
|
|
12355
12304
|
return /*#__PURE__*/jsx("div", {
|
|
12356
12305
|
className: element$C('container'),
|
|
12357
12306
|
role: "dialog",
|
|
12358
12307
|
"aria-modal": "true",
|
|
12359
12308
|
...restDialogProps,
|
|
12360
12309
|
...resolveAccessibleNameProps(dialogAriaLabel, dialogAriaLabelledBy || labelId),
|
|
12361
|
-
children: /*#__PURE__*/jsx(ClickAwayProvider
|
|
12362
|
-
|
|
12363
|
-
, {
|
|
12364
|
-
callback: isModal && !shouldPreventCloseOnClickAway && handleClose,
|
|
12310
|
+
children: /*#__PURE__*/jsx(ClickAwayProvider, {
|
|
12311
|
+
callback: !shouldPreventCloseOnClickAway && handleClose,
|
|
12365
12312
|
childrenRefs: clickAwayRefs,
|
|
12366
12313
|
parentRef: rootRef,
|
|
12367
12314
|
children: /*#__PURE__*/jsxs("section", {
|
|
@@ -12587,51 +12534,28 @@ const DialogBody = forwardRef((props, ref) => {
|
|
|
12587
12534
|
preventCloseOnEscape,
|
|
12588
12535
|
...forwardedProps
|
|
12589
12536
|
} = props;
|
|
12590
|
-
const isModal = isDialogModal(dialogProps);
|
|
12591
|
-
const wrapperRef = useRef(null);
|
|
12592
12537
|
const previousOpen = React__default.useRef(isOpen);
|
|
12593
12538
|
React__default.useEffect(() => {
|
|
12594
12539
|
if (isOpen !== previousOpen.current) {
|
|
12595
12540
|
previousOpen.current = isOpen;
|
|
12596
12541
|
|
|
12597
12542
|
// Focus the parent element on close.
|
|
12598
|
-
|
|
12599
|
-
if (!isOpen && parentElement?.current && (isModal || isFocusWithin(wrapperRef.current))) {
|
|
12543
|
+
if (!isOpen && parentElement && parentElement.current) {
|
|
12600
12544
|
parentElement.current.focus();
|
|
12601
12545
|
}
|
|
12602
12546
|
}
|
|
12603
|
-
}, [isOpen,
|
|
12547
|
+
}, [isOpen, parentElement]);
|
|
12604
12548
|
const shouldPreventCloseOnEscape = preventAutoClose || preventCloseOnEscape;
|
|
12605
|
-
|
|
12549
|
+
useCallbackOnEscape(onClose, isOpen && !shouldPreventCloseOnEscape);
|
|
12550
|
+
const wrapperRef = useRef(null);
|
|
12606
12551
|
/**
|
|
12607
12552
|
* Since the `contentRef` comes from the parent and is optional,
|
|
12608
12553
|
* we need to create a stable contentRef that will always be available.
|
|
12609
12554
|
*/
|
|
12610
12555
|
const localContentRef = useRef(null);
|
|
12611
|
-
|
|
12612
|
-
// Close on escape (a tooltip or popover opened inside registers after the dialog and so gets the escape first).
|
|
12613
|
-
// Non-modal: the page stays usable, so only close when the focus is inside the dialog.
|
|
12614
|
-
const onEscape = React__default.useCallback(() => {
|
|
12615
|
-
if (isModal || isFocusWithin(wrapperRef.current)) onClose?.();
|
|
12616
|
-
}, [isModal, onClose]);
|
|
12617
|
-
useCallbackOnEscape(onClose && onEscape, isOpen && !shouldPreventCloseOnEscape);
|
|
12618
|
-
|
|
12619
12556
|
// Handle focus trap.
|
|
12620
|
-
useFocusTrap(
|
|
12621
|
-
|
|
12622
|
-
// Non-modal: without the focus trap, move the focus into the dialog on open ourselves.
|
|
12623
|
-
useEffect(() => {
|
|
12624
|
-
const wrapper = wrapperRef.current;
|
|
12625
|
-
if (isModal || !isOpen || !wrapper) return undefined;
|
|
12626
|
-
const controller = new AbortController();
|
|
12627
|
-
setupInitialFocus({
|
|
12628
|
-
focusZoneElement: wrapper,
|
|
12629
|
-
focusElement: focusElement?.current
|
|
12630
|
-
}, controller.signal);
|
|
12631
|
-
return () => controller.abort();
|
|
12632
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12633
|
-
}, [isModal, isOpen]);
|
|
12634
|
-
useDisableBodyScroll(isModal && disableBodyScroll && isOpen && localContentRef.current);
|
|
12557
|
+
useFocusTrap(isOpen && wrapperRef.current, focusElement?.current);
|
|
12558
|
+
useDisableBodyScroll(disableBodyScroll && isOpen && localContentRef.current);
|
|
12635
12559
|
const [sentinelTop, setSentinelTop] = useState(null);
|
|
12636
12560
|
const [sentinelBottom, setSentinelBottom] = useState(null);
|
|
12637
12561
|
const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {
|
|
@@ -12663,7 +12587,6 @@ const DialogBody = forwardRef((props, ref) => {
|
|
|
12663
12587
|
isVisible,
|
|
12664
12588
|
size,
|
|
12665
12589
|
zIndex,
|
|
12666
|
-
isModal,
|
|
12667
12590
|
ref: mergeRefs(rootRef, ref),
|
|
12668
12591
|
...forwardedProps,
|
|
12669
12592
|
children: /*#__PURE__*/jsx(DialogContent, {
|