@lumx/react 4.24.1-next.0 → 4.25.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,13 +2487,18 @@ interface DialogProps extends GenericProps$1, HasCloseMode$1, BaseDialogProps {
2487
2487
  size?: DialogSizes;
2488
2488
  /** Z-axis position. */
2489
2489
  zIndex?: number;
2490
- /** Z-axis position. */
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
+ */
2491
2496
  dialogProps?: GenericProps$1;
2492
2497
  /** On close callback. */
2493
2498
  onClose?(): void;
2494
2499
  /** Callback called when the open animation starts and the close animation finishes. */
2495
2500
  onVisibilityChange?(isVisible: boolean): void;
2496
- /** whether to disable the scroll on the body or not */
2501
+ /** Whether to disable the scroll on the body or not (ignored on a non-modal dialog: the page stays usable). */
2497
2502
  disableBodyScroll?: boolean;
2498
2503
  /** Children */
2499
2504
  children?: React__default.ReactNode;
package/index.js CHANGED
@@ -6765,13 +6765,16 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
6765
6765
  flag = true;
6766
6766
  break;
6767
6767
  case 'Escape':
6768
- // 2-tier: close if open, otherwise clear value.
6768
+ // 2-tier: close if open, otherwise clear the input value.
6769
+ // When there is nothing to close or clear, let Escape propagate
6770
+ // (ex: so a surrounding dialog can close).
6769
6771
  if (handle.isOpen) {
6770
6772
  handle.setIsOpen(false);
6771
- } else {
6773
+ flag = true;
6774
+ } else if (triggerEl.tagName === 'INPUT' && triggerEl.value) {
6772
6775
  handle.select(null);
6776
+ flag = true;
6773
6777
  }
6774
- flag = true;
6775
6778
  break;
6776
6779
  case 'PageUp':
6777
6780
  if (handle.isOpen && nav?.selectors.activeItem) {
@@ -7269,8 +7272,11 @@ function setupComboboxButton(button, callbacks) {
7269
7272
  // Close if open; never clear selection (button-mode has no text input).
7270
7273
  if (combobox.isOpen) {
7271
7274
  combobox.setIsOpen(false);
7275
+ return true;
7272
7276
  }
7273
- return true;
7277
+ // Closed: let Escape propagate (ex: so a surrounding dialog can close).
7278
+ // The base handler does not clear the selection on a button trigger.
7279
+ return false;
7274
7280
  default:
7275
7281
  // Printable characters → typeahead.
7276
7282
  if (isPrintableKey(event)) {
@@ -9260,6 +9266,64 @@ function getFirstAndLastFocusable(parentElement) {
9260
9266
  return {};
9261
9267
  }
9262
9268
 
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
+
9263
9327
  /**
9264
9328
  * Shared listener tower for focus traps.
9265
9329
  *
@@ -9267,14 +9331,13 @@ function getFirstAndLastFocusable(parentElement) {
9267
9331
  * registered trap is re-enabled.
9268
9332
  */
9269
9333
  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
+
9270
9337
  /**
9271
9338
  * Trap 'Tab' focus switch inside the `focusZoneElement`.
9272
9339
  *
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).
9340
+ * Setup behavior: move the focus into the zone (see `setupInitialFocus`).
9278
9341
  *
9279
9342
  * Tab key behavior:
9280
9343
  * - With at least one focusable descendant: focus cycles between the first and last focusable in the zone.
@@ -9287,8 +9350,7 @@ const FOCUS_TRAPS = makeListenerTowerContext();
9287
9350
  */
9288
9351
  function setupFocusTrap(options, signal) {
9289
9352
  const {
9290
- focusZoneElement,
9291
- focusElement
9353
+ focusZoneElement
9292
9354
  } = options;
9293
9355
  if (!focusZoneElement || signal.aborted) {
9294
9356
  return;
@@ -9297,25 +9359,6 @@ function setupFocusTrap(options, signal) {
9297
9359
  // The root node is either the Document (regular DOM) or a ShadowRoot (shadow DOM portal).
9298
9360
  const rootNode = focusZoneElement.getRootNode();
9299
9361
 
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
-
9319
9362
  // Trap 'Tab' key down focus switch into the focus zone.
9320
9363
  const trapTabFocusInFocusZone = evt => {
9321
9364
  if (evt.key !== 'Tab') {
@@ -9326,7 +9369,7 @@ function setupFocusTrap(options, signal) {
9326
9369
  // Prevent focus switch if no focusable available — pin focus on the zone itself.
9327
9370
  if (!focusable.first) {
9328
9371
  evt.preventDefault();
9329
- focusZoneFallback();
9372
+ focusZoneFallback(focusZoneElement, signal);
9330
9373
  return;
9331
9374
  }
9332
9375
  const {
@@ -9359,32 +9402,11 @@ function setupFocusTrap(options, signal) {
9359
9402
  };
9360
9403
 
9361
9404
  // SETUP: focus initial element.
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
- }
9405
+ setupInitialFocus(options, signal);
9379
9406
  FOCUS_TRAPS.register(focusTrap);
9380
9407
 
9381
9408
  // TEARDOWN.
9382
- signal.addEventListener('abort', () => {
9383
- FOCUS_TRAPS.unregister(focusTrap);
9384
- if (addedTabIndex) {
9385
- focusZoneElement.removeAttribute('tabindex');
9386
- }
9387
- }, {
9409
+ signal.addEventListener('abort', () => FOCUS_TRAPS.unregister(focusTrap), {
9388
9410
  once: true
9389
9411
  });
9390
9412
  }
@@ -12156,6 +12178,23 @@ const useTransitionVisibility = (ref, isComponentVisible, timeout, onVisibilityC
12156
12178
  return isVisible || isComponentVisible;
12157
12179
  };
12158
12180
 
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
+
12159
12198
  /**
12160
12199
  * Dialog label id key in IdsRegistry
12161
12200
  */
@@ -12202,6 +12241,7 @@ const DialogShell = props => {
12202
12241
  isVisible,
12203
12242
  size = DEFAULT_PROPS$U.size,
12204
12243
  zIndex,
12244
+ isModal = true,
12205
12245
  children,
12206
12246
  Portal,
12207
12247
  HeadingLevelProvider,
@@ -12210,19 +12250,21 @@ const DialogShell = props => {
12210
12250
  ...forwardedProps
12211
12251
  } = props;
12212
12252
  return /*#__PURE__*/jsx(Portal, {
12253
+ enabled: isModal,
12213
12254
  children: /*#__PURE__*/jsxs("div", {
12214
12255
  ref: ref,
12215
12256
  ...forwardedProps,
12216
12257
  className: classnames(className, block$N({
12217
12258
  'is-hidden': !isOpen,
12218
12259
  'is-loading': isLoading,
12260
+ 'is-non-modal': !isModal,
12219
12261
  'is-shown': isOpen || isVisible,
12220
12262
  [`size-${size}`]: Boolean(size)
12221
12263
  })),
12222
12264
  style: {
12223
12265
  zIndex
12224
12266
  },
12225
- children: [/*#__PURE__*/jsx("div", {
12267
+ children: [isModal && /*#__PURE__*/jsx("div", {
12226
12268
  className: element$C('overlay')
12227
12269
  }), /*#__PURE__*/jsx(HeadingLevelProvider, {
12228
12270
  level: 2,
@@ -12260,6 +12302,14 @@ function resolveAccessibleNameProps(ariaLabel, ariaLabelledBy) {
12260
12302
  * that has resolved `labelId` from the ids registry.
12261
12303
  */
12262
12304
 
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
+
12263
12313
  /**
12264
12314
  * Dialog content: the `role="dialog"` element + header/body/footer.
12265
12315
  *
@@ -12301,14 +12351,17 @@ const DialogContent$1 = props => {
12301
12351
  'aria-labelledby': dialogAriaLabelledBy,
12302
12352
  ...restDialogProps
12303
12353
  } = dialogProps ?? {};
12354
+ const isModal = isDialogModal(restDialogProps);
12304
12355
  return /*#__PURE__*/jsx("div", {
12305
12356
  className: element$C('container'),
12306
12357
  role: "dialog",
12307
12358
  "aria-modal": "true",
12308
12359
  ...restDialogProps,
12309
12360
  ...resolveAccessibleNameProps(dialogAriaLabel, dialogAriaLabelledBy || labelId),
12310
- children: /*#__PURE__*/jsx(ClickAwayProvider, {
12311
- callback: !shouldPreventCloseOnClickAway && handleClose,
12361
+ children: /*#__PURE__*/jsx(ClickAwayProvider
12362
+ // A non-modal dialog leaves the page usable: clicking it must not close the dialog.
12363
+ , {
12364
+ callback: isModal && !shouldPreventCloseOnClickAway && handleClose,
12312
12365
  childrenRefs: clickAwayRefs,
12313
12366
  parentRef: rootRef,
12314
12367
  children: /*#__PURE__*/jsxs("section", {
@@ -12534,28 +12587,51 @@ const DialogBody = forwardRef((props, ref) => {
12534
12587
  preventCloseOnEscape,
12535
12588
  ...forwardedProps
12536
12589
  } = props;
12590
+ const isModal = isDialogModal(dialogProps);
12591
+ const wrapperRef = useRef(null);
12537
12592
  const previousOpen = React__default.useRef(isOpen);
12538
12593
  React__default.useEffect(() => {
12539
12594
  if (isOpen !== previousOpen.current) {
12540
12595
  previousOpen.current = isOpen;
12541
12596
 
12542
12597
  // Focus the parent element on close.
12543
- if (!isOpen && parentElement && parentElement.current) {
12598
+ // Non-modal: only when the focus is inside the dialog (do not steal the focus from the page).
12599
+ if (!isOpen && parentElement?.current && (isModal || isFocusWithin(wrapperRef.current))) {
12544
12600
  parentElement.current.focus();
12545
12601
  }
12546
12602
  }
12547
- }, [isOpen, parentElement]);
12603
+ }, [isOpen, isModal, parentElement]);
12548
12604
  const shouldPreventCloseOnEscape = preventAutoClose || preventCloseOnEscape;
12549
- useCallbackOnEscape(onClose, isOpen && !shouldPreventCloseOnEscape);
12550
- const wrapperRef = useRef(null);
12605
+
12551
12606
  /**
12552
12607
  * Since the `contentRef` comes from the parent and is optional,
12553
12608
  * we need to create a stable contentRef that will always be available.
12554
12609
  */
12555
12610
  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
+
12556
12619
  // Handle focus trap.
12557
- useFocusTrap(isOpen && wrapperRef.current, focusElement?.current);
12558
- useDisableBodyScroll(disableBodyScroll && isOpen && localContentRef.current);
12620
+ useFocusTrap(isModal && isOpen && wrapperRef.current, focusElement?.current);
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);
12559
12635
  const [sentinelTop, setSentinelTop] = useState(null);
12560
12636
  const [sentinelBottom, setSentinelBottom] = useState(null);
12561
12637
  const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {
@@ -12587,6 +12663,7 @@ const DialogBody = forwardRef((props, ref) => {
12587
12663
  isVisible,
12588
12664
  size,
12589
12665
  zIndex,
12666
+ isModal,
12590
12667
  ref: mergeRefs(rootRef, ref),
12591
12668
  ...forwardedProps,
12592
12669
  children: /*#__PURE__*/jsx(DialogContent, {