@lumx/react 4.24.1-alpha.0 → 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 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
- /** Whether to disable the scroll on the body or not (ignored on a non-modal dialog: the page stays usable). */
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
@@ -9260,64 +9260,6 @@ function getFirstAndLastFocusable(parentElement) {
9260
9260
  return {};
9261
9261
  }
9262
9262
 
9263
- /**
9264
- * Focus the zone element itself (last-resort fallback, e.g. an empty dialog).
9265
- *
9266
- * Adds a `tabindex="-1"` if needed to make the zone programmatically focusable, removed when the signal aborts.
9267
- *
9268
- * @param focusZoneElement The zone element.
9269
- * @param signal AbortSignal used to remove the added `tabindex`.
9270
- */
9271
- function focusZoneFallback(focusZoneElement, signal) {
9272
- if (!focusZoneElement.hasAttribute('tabindex')) {
9273
- focusZoneElement.setAttribute('tabindex', '-1');
9274
- signal.addEventListener('abort', () => focusZoneElement.removeAttribute('tabindex'), {
9275
- once: true
9276
- });
9277
- }
9278
- focusZoneElement.focus({
9279
- preventScroll: true
9280
- });
9281
- }
9282
-
9283
- /**
9284
- * Move the focus into the `focusZoneElement`:
9285
- * 1. Focus `focusElement` if provided and contained in the zone.
9286
- * 2. Otherwise focus the first focusable descendant.
9287
- * 3. Otherwise focus the zone element itself (falling back to setting `tabindex="-1"` if needed) so that
9288
- * keyboard users (especially screen reader users) land inside the zone (e.g. an empty dialog).
9289
- *
9290
- * @param options Initial focus configuration.
9291
- * @param signal AbortSignal used to tear down (removes the fallback `tabindex` if it was added).
9292
- */
9293
- function setupInitialFocus(options, signal) {
9294
- const {
9295
- focusZoneElement,
9296
- focusElement
9297
- } = options;
9298
- if (!focusZoneElement || signal.aborted) {
9299
- return;
9300
- }
9301
- if (focusElement && focusZoneElement.contains(focusElement)) {
9302
- // Focus the given element.
9303
- focusElement.focus({
9304
- preventScroll: true
9305
- });
9306
- return;
9307
- }
9308
- const firstFocusable = getFirstAndLastFocusable(focusZoneElement).first;
9309
- if (firstFocusable) {
9310
- // Focus the first focusable descendant.
9311
- firstFocusable.focus({
9312
- preventScroll: true
9313
- });
9314
- return;
9315
- }
9316
-
9317
- // No focusable descendant — fall back to the zone itself.
9318
- focusZoneFallback(focusZoneElement, signal);
9319
- }
9320
-
9321
9263
  /**
9322
9264
  * Shared listener tower for focus traps.
9323
9265
  *
@@ -9325,13 +9267,14 @@ function setupInitialFocus(options, signal) {
9325
9267
  * registered trap is re-enabled.
9326
9268
  */
9327
9269
  const FOCUS_TRAPS = makeListenerTowerContext();
9328
-
9329
- /** Focus trap options: the zone in which to trap the focus, and the element to focus on activation. */
9330
-
9331
9270
  /**
9332
9271
  * Trap 'Tab' focus switch inside the `focusZoneElement`.
9333
9272
  *
9334
- * Setup behavior: move the focus into the zone (see `setupInitialFocus`).
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).
9335
9278
  *
9336
9279
  * Tab key behavior:
9337
9280
  * - With at least one focusable descendant: focus cycles between the first and last focusable in the zone.
@@ -9344,7 +9287,8 @@ const FOCUS_TRAPS = makeListenerTowerContext();
9344
9287
  */
9345
9288
  function setupFocusTrap(options, signal) {
9346
9289
  const {
9347
- focusZoneElement
9290
+ focusZoneElement,
9291
+ focusElement
9348
9292
  } = options;
9349
9293
  if (!focusZoneElement || signal.aborted) {
9350
9294
  return;
@@ -9353,6 +9297,25 @@ function setupFocusTrap(options, signal) {
9353
9297
  // The root node is either the Document (regular DOM) or a ShadowRoot (shadow DOM portal).
9354
9298
  const rootNode = focusZoneElement.getRootNode();
9355
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
+
9356
9319
  // Trap 'Tab' key down focus switch into the focus zone.
9357
9320
  const trapTabFocusInFocusZone = evt => {
9358
9321
  if (evt.key !== 'Tab') {
@@ -9363,7 +9326,7 @@ function setupFocusTrap(options, signal) {
9363
9326
  // Prevent focus switch if no focusable available — pin focus on the zone itself.
9364
9327
  if (!focusable.first) {
9365
9328
  evt.preventDefault();
9366
- focusZoneFallback(focusZoneElement, signal);
9329
+ focusZoneFallback();
9367
9330
  return;
9368
9331
  }
9369
9332
  const {
@@ -9396,11 +9359,32 @@ function setupFocusTrap(options, signal) {
9396
9359
  };
9397
9360
 
9398
9361
  // SETUP: focus initial element.
9399
- setupInitialFocus(options, signal);
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
+ }
9400
9379
  FOCUS_TRAPS.register(focusTrap);
9401
9380
 
9402
9381
  // TEARDOWN.
9403
- signal.addEventListener('abort', () => FOCUS_TRAPS.unregister(focusTrap), {
9382
+ signal.addEventListener('abort', () => {
9383
+ FOCUS_TRAPS.unregister(focusTrap);
9384
+ if (addedTabIndex) {
9385
+ focusZoneElement.removeAttribute('tabindex');
9386
+ }
9387
+ }, {
9404
9388
  once: true
9405
9389
  });
9406
9390
  }
@@ -12172,23 +12156,6 @@ const useTransitionVisibility = (ref, isComponentVisible, timeout, onVisibilityC
12172
12156
  return isVisible || isComponentVisible;
12173
12157
  };
12174
12158
 
12175
- /**
12176
- * Check if the focus is on the given element or inside it.
12177
- *
12178
- * Reads the active element of the element's own root node (Document or ShadowRoot), so it also works when the
12179
- * element lives in a shadow DOM.
12180
- *
12181
- * @param element The element to check.
12182
- * @return whether the active element is the element itself or one of its descendants.
12183
- */
12184
- function isFocusWithin(element) {
12185
- if (!element) return false;
12186
- const {
12187
- activeElement
12188
- } = element.getRootNode();
12189
- return Boolean(activeElement && element.contains(activeElement));
12190
- }
12191
-
12192
12159
  /**
12193
12160
  * Dialog label id key in IdsRegistry
12194
12161
  */
@@ -12235,7 +12202,6 @@ const DialogShell = props => {
12235
12202
  isVisible,
12236
12203
  size = DEFAULT_PROPS$U.size,
12237
12204
  zIndex,
12238
- isModal = true,
12239
12205
  children,
12240
12206
  Portal,
12241
12207
  HeadingLevelProvider,
@@ -12244,21 +12210,19 @@ const DialogShell = props => {
12244
12210
  ...forwardedProps
12245
12211
  } = props;
12246
12212
  return /*#__PURE__*/jsx(Portal, {
12247
- enabled: isModal,
12248
12213
  children: /*#__PURE__*/jsxs("div", {
12249
12214
  ref: ref,
12250
12215
  ...forwardedProps,
12251
12216
  className: classnames(className, block$N({
12252
12217
  'is-hidden': !isOpen,
12253
12218
  'is-loading': isLoading,
12254
- 'is-non-modal': !isModal,
12255
12219
  'is-shown': isOpen || isVisible,
12256
12220
  [`size-${size}`]: Boolean(size)
12257
12221
  })),
12258
12222
  style: {
12259
12223
  zIndex
12260
12224
  },
12261
- children: [isModal && /*#__PURE__*/jsx("div", {
12225
+ children: [/*#__PURE__*/jsx("div", {
12262
12226
  className: element$C('overlay')
12263
12227
  }), /*#__PURE__*/jsx(HeadingLevelProvider, {
12264
12228
  level: 2,
@@ -12296,14 +12260,6 @@ function resolveAccessibleNameProps(ariaLabel, ariaLabelledBy) {
12296
12260
  * that has resolved `labelId` from the ids registry.
12297
12261
  */
12298
12262
 
12299
- /**
12300
- * Whether the dialog is modal: it is, unless `dialogProps['aria-modal']` is `false` (or `'false'`).
12301
- *
12302
- * @param dialogProps Props of the dialog container element.
12303
- * @return whether the dialog is modal.
12304
- */
12305
- const isDialogModal = dialogProps => dialogProps?.['aria-modal'] !== false && dialogProps?.['aria-modal'] !== 'false';
12306
-
12307
12263
  /**
12308
12264
  * Dialog content: the `role="dialog"` element + header/body/footer.
12309
12265
  *
@@ -12345,17 +12301,14 @@ const DialogContent$1 = props => {
12345
12301
  'aria-labelledby': dialogAriaLabelledBy,
12346
12302
  ...restDialogProps
12347
12303
  } = dialogProps ?? {};
12348
- const isModal = isDialogModal(restDialogProps);
12349
12304
  return /*#__PURE__*/jsx("div", {
12350
12305
  className: element$C('container'),
12351
12306
  role: "dialog",
12352
12307
  "aria-modal": "true",
12353
12308
  ...restDialogProps,
12354
12309
  ...resolveAccessibleNameProps(dialogAriaLabel, dialogAriaLabelledBy || labelId),
12355
- children: /*#__PURE__*/jsx(ClickAwayProvider
12356
- // A non-modal dialog leaves the page usable: clicking it must not close the dialog.
12357
- , {
12358
- callback: isModal && !shouldPreventCloseOnClickAway && handleClose,
12310
+ children: /*#__PURE__*/jsx(ClickAwayProvider, {
12311
+ callback: !shouldPreventCloseOnClickAway && handleClose,
12359
12312
  childrenRefs: clickAwayRefs,
12360
12313
  parentRef: rootRef,
12361
12314
  children: /*#__PURE__*/jsxs("section", {
@@ -12581,51 +12534,28 @@ const DialogBody = forwardRef((props, ref) => {
12581
12534
  preventCloseOnEscape,
12582
12535
  ...forwardedProps
12583
12536
  } = props;
12584
- const isModal = isDialogModal(dialogProps);
12585
- const wrapperRef = useRef(null);
12586
12537
  const previousOpen = React__default.useRef(isOpen);
12587
12538
  React__default.useEffect(() => {
12588
12539
  if (isOpen !== previousOpen.current) {
12589
12540
  previousOpen.current = isOpen;
12590
12541
 
12591
12542
  // Focus the parent element on close.
12592
- // Non-modal: only when the focus is inside the dialog (do not steal the focus from the page).
12593
- if (!isOpen && parentElement?.current && (isModal || isFocusWithin(wrapperRef.current))) {
12543
+ if (!isOpen && parentElement && parentElement.current) {
12594
12544
  parentElement.current.focus();
12595
12545
  }
12596
12546
  }
12597
- }, [isOpen, isModal, parentElement]);
12547
+ }, [isOpen, parentElement]);
12598
12548
  const shouldPreventCloseOnEscape = preventAutoClose || preventCloseOnEscape;
12599
-
12549
+ useCallbackOnEscape(onClose, isOpen && !shouldPreventCloseOnEscape);
12550
+ const wrapperRef = useRef(null);
12600
12551
  /**
12601
12552
  * Since the `contentRef` comes from the parent and is optional,
12602
12553
  * we need to create a stable contentRef that will always be available.
12603
12554
  */
12604
12555
  const localContentRef = useRef(null);
12605
-
12606
- // Close on escape (a tooltip or popover opened inside registers after the dialog and so gets the escape first).
12607
- // Non-modal: the page stays usable, so only close when the focus is inside the dialog.
12608
- const onEscape = React__default.useCallback(() => {
12609
- if (isModal || isFocusWithin(wrapperRef.current)) onClose?.();
12610
- }, [isModal, onClose]);
12611
- useCallbackOnEscape(onClose && onEscape, isOpen && !shouldPreventCloseOnEscape);
12612
-
12613
12556
  // Handle focus trap.
12614
- useFocusTrap(isModal && isOpen && wrapperRef.current, focusElement?.current);
12615
-
12616
- // Non-modal: without the focus trap, move the focus into the dialog on open ourselves.
12617
- useEffect(() => {
12618
- const wrapper = wrapperRef.current;
12619
- if (isModal || !isOpen || !wrapper) return undefined;
12620
- const controller = new AbortController();
12621
- setupInitialFocus({
12622
- focusZoneElement: wrapper,
12623
- focusElement: focusElement?.current
12624
- }, controller.signal);
12625
- return () => controller.abort();
12626
- // eslint-disable-next-line react-hooks/exhaustive-deps
12627
- }, [isModal, isOpen]);
12628
- useDisableBodyScroll(isModal && disableBodyScroll && isOpen && localContentRef.current);
12557
+ useFocusTrap(isOpen && wrapperRef.current, focusElement?.current);
12558
+ useDisableBodyScroll(disableBodyScroll && isOpen && localContentRef.current);
12629
12559
  const [sentinelTop, setSentinelTop] = useState(null);
12630
12560
  const [sentinelBottom, setSentinelBottom] = useState(null);
12631
12561
  const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {
@@ -12657,7 +12587,6 @@ const DialogBody = forwardRef((props, ref) => {
12657
12587
  isVisible,
12658
12588
  size,
12659
12589
  zIndex,
12660
- isModal,
12661
12590
  ref: mergeRefs(rootRef, ref),
12662
12591
  ...forwardedProps,
12663
12592
  children: /*#__PURE__*/jsx(DialogContent, {