@lumx/react 4.27.1-alpha.1 → 4.28.0-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
@@ -1543,6 +1543,28 @@ interface ComboboxPopoverComponentProps extends ComboboxPopoverProps {
1543
1543
  children: ReactNode;
1544
1544
  }
1545
1545
 
1546
+ /**
1547
+ * State of a composite for its live region (see `CompositeStatus`): the item count, the loading state and the
1548
+ * open state, as one snapshot (see {@link CompositeEventMap.stateChange}).
1549
+ */
1550
+ interface CompositeState {
1551
+ /** The number of visible items. */
1552
+ optionsLength: number;
1553
+ /** The current input value (combobox only, empty string otherwise). */
1554
+ inputValue: string;
1555
+ /** Whether the item count must not be announced (set by the composite specialization). */
1556
+ isCountHidden: boolean;
1557
+ /** Whether root skeletons are registered (loading), at once. */
1558
+ isLoading: boolean;
1559
+ /** Whether the loading lasted long enough to be announced (500ms after skeletons mount while open). */
1560
+ isLoadingAnnounced: boolean;
1561
+ /**
1562
+ * Whether the items are open for the live region: set 100ms after the composite opens (the popover must
1563
+ * be in the accessibility tree before the live region content changes), cleared at once when it closes.
1564
+ * A standalone composite is always open.
1565
+ */
1566
+ isOpenForAnnouncement: boolean;
1567
+ }
1546
1568
  /** Map of composite event names to their payload types. */
1547
1569
  interface CompositeEventMap {
1548
1570
  /** Fired when the active descendant changes (visual focus). Payload: the active item id or null. */
@@ -1559,20 +1581,22 @@ interface CompositeEventMap {
1559
1581
  } | undefined;
1560
1582
  /**
1561
1583
  * Fired immediately when the aggregate loading state changes (root skeleton count transitions
1562
- * between 0 and >0). Used for empty suppression in the status and for `aria-busy` on the list.
1584
+ * between 0 and >0). Used for `aria-busy` on the list. The live region reads the loading state and
1585
+ * the loading announcement from {@link stateChange}.
1563
1586
  */
1564
1587
  loadingChange: boolean;
1565
- /**
1566
- * Fired after a 500ms debounce when loading persists while the items are visible,
1567
- * or immediately when loading ends. Used to control the loading message text in the live region.
1568
- */
1569
- loadingAnnouncement: boolean;
1570
1588
  /**
1571
1589
  * Fired when the items become visible or hidden (see {@link CompositeHandle.setOpen}).
1572
1590
  * Inside a combobox, this is the combobox open state. A standalone composite is open from
1573
1591
  * creation and never closes.
1574
1592
  */
1575
1593
  open: boolean;
1594
+ /**
1595
+ * Fired when any field of the live region state changes (see {@link CompositeState}): the visible count,
1596
+ * the loading state, the loading announcement, and the delayed open state. Has a value from creation
1597
+ * (`undefined` only as the initial value of the framework hooks, without a handle).
1598
+ */
1599
+ stateChange: CompositeState | undefined;
1576
1600
  /**
1577
1601
  * Fired only when this item becomes the active descendant (true)
1578
1602
  * or stops being the active descendant (false).
@@ -2207,7 +2231,7 @@ interface ListboxSectionProps extends GenericProps$1, ReactToJSX<ListboxSectionP
2207
2231
  /**
2208
2232
  * Defines the props for the core CompositeStatus template.
2209
2233
  */
2210
- interface CompositeStatusProps$1 {
2234
+ interface CompositeStatusProps$1 extends HasClassName {
2211
2235
  /**
2212
2236
  * Message to display when the composite has no visible items.
2213
2237
  * Can be a plain string or a function receiving the current input value (for dynamic messages).
@@ -2239,40 +2263,16 @@ interface CompositeStatusProps$1 {
2239
2263
  */
2240
2264
  loadingMessage?: string;
2241
2265
  /**
2242
- * Composite state
2243
- */
2244
- state?: {
2245
- /**
2246
- * The number of currently visible items.
2247
- * Driven by the framework wrapper via the composite handle's `optionsChange` event.
2248
- */
2249
- optionsLength?: number;
2250
- /**
2251
- * The current value of the combobox input.
2252
- * Passed to `emptyMessage` when it is a function.
2253
- */
2254
- inputValue?: string;
2255
- /**
2256
- * Whether loading is active (immediate, from `loadingChange` event).
2257
- * Used to suppress false "empty" state while data is loading.
2258
- */
2259
- isLoading?: boolean;
2260
- /**
2261
- * Whether the combobox popover is open.
2262
- * Used to gate live region content so screen readers announce messages
2263
- * when the popover opens (content insertion triggers `aria-live` announcement).
2264
- */
2265
- isOpen?: boolean;
2266
- };
2266
+ * The live region state of the composite (the `stateChange` snapshot, see `CompositeState`).
2267
+ * Without it (no composite handle yet), nothing renders.
2268
+ */
2269
+ state?: CompositeState;
2267
2270
  }
2268
2271
 
2269
2272
  /**
2270
2273
  * Props of the composite status (`Combobox.State`, `Listbox.State`).
2271
2274
  */
2272
- interface CompositeStatusProps extends ReactToJSX<CompositeStatusProps$1, 'state'> {
2273
- /** Additional content rendered after the state message. */
2274
- children?: ReactNode;
2275
- }
2275
+ type CompositeStatusProps = ReactToJSX<CompositeStatusProps$1, 'state'>;
2276
2276
 
2277
2277
  /**
2278
2278
  * Combobox compound component namespace.
package/index.js CHANGED
@@ -8665,6 +8665,9 @@ const ListboxSection = forwardRef((props, ref) => {
8665
8665
  ListboxSection.displayName = COMPONENT_NAME$1e;
8666
8666
  ListboxSection.className = CLASSNAME$1b;
8667
8667
 
8668
+ /**
8669
+ * Component display name.
8670
+ */
8668
8671
  const COMPONENT_NAME$1c = 'CompositeStatus';
8669
8672
 
8670
8673
  /**
@@ -8710,19 +8713,19 @@ const CompositeStatus$1 = (props, {
8710
8713
  nbOptionMessage,
8711
8714
  errorMessage,
8712
8715
  errorTryReloadMessage,
8713
- loadingMessage,
8714
- state
8716
+ state,
8717
+ className
8715
8718
  } = props;
8716
- const isOpen = state?.isOpen ?? true;
8719
+ const isOpen = state?.isOpenForAnnouncement ?? false;
8717
8720
  const optionsLength = state?.optionsLength ?? 0;
8718
8721
  const isEmpty = optionsLength === 0;
8719
8722
  const showError = !!errorMessage;
8720
8723
  const resolvedEmptyMessage = typeof emptyMessage === 'function' ? emptyMessage(state?.inputValue || '') : emptyMessage;
8721
8724
  // Suppress empty while loading (immediate flag prevents false "no results" before data arrives)
8722
8725
  const showEmpty = isEmpty && !showError && !state?.isLoading && !!resolvedEmptyMessage;
8723
- // Show loading message when provided and not in error state.
8724
- // The framework wrapper gates `loadingMessage` via the debounced `loadingAnnouncement` event,
8725
- // passing `undefined` until the 500ms threshold is reached.
8726
+ // Show the loading message when provided, not in error state, and once the loading lasted long enough
8727
+ // to be announced (`isLoadingAnnounced`: 500ms after the skeletons mount).
8728
+ const loadingMessage = state?.isLoadingAnnounced ? props.loadingMessage : undefined;
8726
8729
  const showLoading = !showError && !!loadingMessage;
8727
8730
  // Show the item count message when the composite is open, not empty, not loading, and not in error.
8728
8731
  const resolvedNbOptionMessage = !isEmpty && !showError && !state?.isLoading && nbOptionMessage ? nbOptionMessage(optionsLength) : undefined;
@@ -8738,7 +8741,7 @@ const CompositeStatus$1 = (props, {
8738
8741
  // the popover's closeMode="hide") and revealing it doesn't trigger announcements.
8739
8742
  const renderContent = isOpen;
8740
8743
  return /*#__PURE__*/jsxs(GenericBlock, {
8741
- className: classnames(!show && visuallyHidden(), block$W(), LEGACY_CLASSNAME, padding('regular')),
8744
+ className: classnames(className, !show && visuallyHidden(), block$W(), LEGACY_CLASSNAME, padding('regular')),
8742
8745
  orientation: "vertical",
8743
8746
  ...alignProps,
8744
8747
  role: "status",
@@ -8774,72 +8777,6 @@ const CompositeStatus$1 = (props, {
8774
8777
  });
8775
8778
  };
8776
8779
 
8777
- /**
8778
- * Delay before inserting content into the aria-live region after the popover opens (ms).
8779
- *
8780
- * The popover uses `closeMode="hide"` (`display:none` when closed), so the live region
8781
- * container is not in the accessibility tree until the popover becomes visible.
8782
- * Screen readers only detect content *changes* in live regions that are already visible.
8783
- * This delay ensures the popover's `display:none` is removed and the accessibility tree
8784
- * is updated before content is inserted, so screen readers reliably announce it.
8785
- */
8786
- const OPEN_ANNOUNCEMENT_DELAY = 100;
8787
-
8788
- /** Setters invoked by `subscribeListboxState` when handle events fire. */
8789
-
8790
- /**
8791
- * Subscribe to the listbox handle events needed by `CompositeStatus`.
8792
- *
8793
- * Manages three subscriptions:
8794
- * - `loadingChange` → `setIsLoading` (+ synchronous initial read of the `loadingChange` snapshot)
8795
- * - `loadingAnnouncement` → `setShouldAnnounce`
8796
- * - `open` → `setIsOpen` (deferred by {@link OPEN_ANNOUNCEMENT_DELAY}ms when shown, immediate when hidden)
8797
- * (a standalone listbox is always visible: `setIsOpen(true)` once, no subscription)
8798
- *
8799
- * @param list The listbox handle to subscribe to (`ComboboxHandle.list` inside a combobox).
8800
- * @param setters Framework-specific state setters.
8801
- * @returns A cleanup function that unsubscribes all events and clears timers.
8802
- */
8803
- function subscribeListboxState(list, setters) {
8804
- const {
8805
- setIsLoading,
8806
- setShouldAnnounce,
8807
- setIsOpen
8808
- } = setters;
8809
-
8810
- // Read current loading state synchronously
8811
- setIsLoading(list.getSnapshot('loadingChange') ?? false);
8812
- const unsubLoadingChange = list.subscribe('loadingChange', setIsLoading);
8813
- const unsubLoadingAnnouncement = list.subscribe('loadingAnnouncement', setShouldAnnounce);
8814
-
8815
- // Standalone listbox: the options are always visible.
8816
- if (list.isStandalone) {
8817
- setIsOpen(true);
8818
- return () => {
8819
- unsubLoadingChange();
8820
- unsubLoadingAnnouncement();
8821
- };
8822
- }
8823
- let openTimer;
8824
- const unsubVisible = list.subscribe('open', visible => {
8825
- clearTimeout(openTimer);
8826
- if (visible) {
8827
- // Delay content insertion so the popover is visible in the
8828
- // accessibility tree before the live region content changes.
8829
- openTimer = setTimeout(() => setIsOpen(true), OPEN_ANNOUNCEMENT_DELAY);
8830
- } else {
8831
- // Reset immediately on close
8832
- setIsOpen(false);
8833
- }
8834
- });
8835
- return () => {
8836
- unsubLoadingChange();
8837
- unsubLoadingAnnouncement();
8838
- unsubVisible();
8839
- clearTimeout(openTimer);
8840
- };
8841
- }
8842
-
8843
8780
  /**
8844
8781
  * Similar to lodash `partition` function but working with multiple predicates.
8845
8782
  *
@@ -9063,29 +9000,9 @@ const CompositeStatus = props => {
9063
9000
  const {
9064
9001
  handle: list
9065
9002
  } = useCompositeContext();
9066
- const optionsState = useCompositeEvent(list, 'optionsChange', undefined);
9067
- const [isLoading, setIsLoading] = useState(false);
9068
- const [shouldAnnounce, setShouldAnnounce] = useState(false);
9069
- const [isOpen, setIsOpen] = useState(false);
9070
- useEffect(() => {
9071
- if (!list) return undefined;
9072
- return subscribeListboxState(list, {
9073
- setIsLoading,
9074
- setShouldAnnounce,
9075
- setIsOpen
9076
- });
9077
- }, [list]);
9078
- const state = {
9079
- ...optionsState,
9080
- isLoading,
9081
- isOpen
9082
- };
9083
-
9084
- // Only pass loadingMessage to core after the 500ms debounce threshold
9085
- const loadingMessage = shouldAnnounce ? props.loadingMessage : undefined;
9003
+ const state = useCompositeEvent(list, 'stateChange', undefined);
9086
9004
  return CompositeStatus$1({
9087
9005
  ...props,
9088
- loadingMessage,
9089
9006
  state
9090
9007
  }, {
9091
9008
  GenericBlock,
@@ -9264,6 +9181,16 @@ const isSelected = el => el.getAttribute('aria-selected') === 'true';
9264
9181
  /** Delay before announcing loading in the live region (ms). */
9265
9182
  const LOADING_ANNOUNCEMENT_DELAY = 500;
9266
9183
 
9184
+ /**
9185
+ * Delay before the live region content shows after the composite opens (ms).
9186
+ *
9187
+ * The combobox popover uses `closeMode="hide"` (`display:none` when closed), so the live region container is
9188
+ * not in the accessibility tree until the popover becomes visible. Screen readers only detect content
9189
+ * *changes* in live regions that are already visible. This delay ensures the popover's `display:none` is
9190
+ * removed and the accessibility tree is updated before content is inserted, so screen readers announce it.
9191
+ */
9192
+ const OPEN_ANNOUNCEMENT_DELAY = 100;
9193
+
9267
9194
  /** The `optionsChange` payload before any item registers. */
9268
9195
  const INITIAL_OPTIONS = {
9269
9196
  optionsLength: 0,
@@ -9310,7 +9237,7 @@ function setupComposite(options, specialization) {
9310
9237
 
9311
9238
  /** The current filter (see {@link CompositeHandle.setFilter}). */
9312
9239
  let filter = NO_FILTER;
9313
- /** The last `optionsChange` payload. */
9240
+ /** The last `optionsChange` payload (the visible items part of the live region state). */
9314
9241
  let lastOptions = INITIAL_OPTIONS;
9315
9242
  /**
9316
9243
  * Registered skeletons, one token per registration: a stale cleanup (e.g. after a destroy) finds no
@@ -9326,15 +9253,28 @@ function setupComposite(options, specialization) {
9326
9253
  let loadingTimer;
9327
9254
  /** Whether a loading announcement has been sent since the items became visible. */
9328
9255
  let announcementSent = false;
9256
+ /** Whether the items are open for the live region (see {@link CompositeState.isOpenForAnnouncement}). */
9257
+ let isOpenForAnnouncement = isStandalone;
9258
+ /** Timer for the delayed open state of the live region. */
9259
+ let openTimer;
9329
9260
  const isLoading = () => rootSkeletons.size > 0;
9330
9261
 
9262
+ /** The live region state (see {@link CompositeState}). */
9263
+ const getState = () => ({
9264
+ ...lastOptions,
9265
+ isLoading: isLoading(),
9266
+ isLoadingAnnounced: announcementSent,
9267
+ isOpenForAnnouncement
9268
+ });
9269
+
9331
9270
  /** Subscribers, per event (also the per-item `optionActive:<id>` events). Sets are created on demand. */
9332
9271
  const subscribers = new Map();
9333
9272
  /** The last dispatched value of the static events (the per-item events are derived, see `getSnapshot`). */
9334
9273
 
9335
- // `open` has a value from creation so pull-based subscribers read it before any change.
9274
+ // `open` and `stateChange` have a value from creation so pull-based subscribers read it before any change.
9336
9275
  const initialValues = () => ({
9337
- open: isOpen
9276
+ open: isOpen,
9277
+ stateChange: getState()
9338
9278
  });
9339
9279
  let latestValues = initialValues();
9340
9280
  function emit(event, value) {
@@ -9354,6 +9294,16 @@ function setupComposite(options, specialization) {
9354
9294
  if (id) emit(optionActiveEvent(id), true);
9355
9295
  }
9356
9296
 
9297
+ /** Fire `stateChange` when a field of the live region state changed. */
9298
+ function notifyStateChange() {
9299
+ const next = getState();
9300
+ const last = latestValues.stateChange;
9301
+ if (last && Object.keys(next).every(key => last[key] === next[key])) {
9302
+ return;
9303
+ }
9304
+ notify('stateChange', next);
9305
+ }
9306
+
9357
9307
  // Forward-declared so the DOM listeners can reference `handle` (via closure) before it is constructed.
9358
9308
  let handle;
9359
9309
 
@@ -9396,6 +9346,7 @@ function setupComposite(options, specialization) {
9396
9346
  if (next.optionsLength !== lastOptions.optionsLength || next.isCountHidden !== lastOptions.isCountHidden || isEmpty && next.inputValue !== lastOptions.inputValue) {
9397
9347
  lastOptions = next;
9398
9348
  notify('optionsChange', next);
9349
+ notifyStateChange();
9399
9350
  }
9400
9351
  }
9401
9352
 
@@ -9413,7 +9364,7 @@ function setupComposite(options, specialization) {
9413
9364
  if (!hasSkeleton() || !isOpen) return;
9414
9365
  loadingTimer = setTimeout(() => {
9415
9366
  announcementSent = true;
9416
- notify('loadingAnnouncement', true);
9367
+ notifyStateChange();
9417
9368
  }, LOADING_ANNOUNCEMENT_DELAY);
9418
9369
  }
9419
9370
 
@@ -9422,7 +9373,7 @@ function setupComposite(options, specialization) {
9422
9373
  clearTimeout(loadingTimer);
9423
9374
  if (announcementSent) {
9424
9375
  announcementSent = false;
9425
- notify('loadingAnnouncement', false);
9376
+ notifyStateChange();
9426
9377
  }
9427
9378
  }
9428
9379
 
@@ -9434,11 +9385,26 @@ function setupComposite(options, specialization) {
9434
9385
  syncHidden();
9435
9386
  if (isLoading() !== wasLoading) {
9436
9387
  notify('loadingChange', isLoading());
9388
+ notifyStateChange();
9437
9389
  }
9438
9390
  if (hasSkeleton() === hadSkeleton) return;
9439
9391
  if (hadSkeleton) resetLoadingAnnouncement();else startLoadingAnnouncementTimer();
9440
9392
  }
9441
9393
 
9394
+ /** Set the open state of the live region: delayed on open, at once on close. */
9395
+ function setOpenForAnnouncement(open) {
9396
+ clearTimeout(openTimer);
9397
+ if (open) {
9398
+ openTimer = setTimeout(() => {
9399
+ isOpenForAnnouncement = true;
9400
+ notifyStateChange();
9401
+ }, OPEN_ANNOUNCEMENT_DELAY);
9402
+ } else {
9403
+ isOpenForAnnouncement = false;
9404
+ notifyStateChange();
9405
+ }
9406
+ }
9407
+
9442
9408
  // ── Mount (DOM) ───────────────────────────────────────────
9443
9409
 
9444
9410
  function unmount() {
@@ -9593,6 +9559,7 @@ function setupComposite(options, specialization) {
9593
9559
  isOpen = open;
9594
9560
  if (open) startLoadingAnnouncementTimer();else resetLoadingAnnouncement();
9595
9561
  notify('open', open);
9562
+ setOpenForAnnouncement(open);
9596
9563
  },
9597
9564
  select(option) {
9598
9565
  onSelect?.({
@@ -9714,10 +9681,12 @@ function setupComposite(options, specialization) {
9714
9681
  destroy() {
9715
9682
  unmount();
9716
9683
  clearTimeout(loadingTimer);
9684
+ clearTimeout(openTimer);
9717
9685
  announcementSent = false;
9718
9686
  filter = NO_FILTER;
9719
9687
  lastOptions = INITIAL_OPTIONS;
9720
9688
  isOpen = isStandalone;
9689
+ isOpenForAnnouncement = isStandalone;
9721
9690
  rootSkeletons.clear();
9722
9691
  nestedSkeletons.clear();
9723
9692
  // After the state reset: the initial values read it.