@lumx/react 4.29.0 → 4.29.1-alpha.1

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.js CHANGED
@@ -1,15 +1,15 @@
1
- import { ColorVariant as ColorVariant$1, Size as Size$1, VISUALLY_HIDDEN, Theme as Theme$1, AspectRatio as AspectRatio$1, DOCUMENT, IS_BROWSER as IS_BROWSER$1, Emphasis as Emphasis$1, WINDOW, DIALOG_TRANSITION_DURATION, Typography as Typography$1, Orientation as Orientation$1, NOTIFICATION_TRANSITION_DURATION, Kind as Kind$1, Alignment as Alignment$1, ColorPalette as ColorPalette$1 } from '@lumx/core/js/constants';
1
+ import { ColorVariant as ColorVariant$1, Size as Size$1, Theme as Theme$1, AspectRatio as AspectRatio$1, DOCUMENT, IS_BROWSER as IS_BROWSER$1, Emphasis as Emphasis$1, WINDOW, DIALOG_TRANSITION_DURATION, Typography as Typography$1, Orientation as Orientation$1, NOTIFICATION_TRANSITION_DURATION, Kind as Kind$1, Alignment as Alignment$1, ColorPalette as ColorPalette$1 } from '@lumx/core/js/constants';
2
2
  export * from '@lumx/core/js/constants';
3
3
  export * from '@lumx/core/js/types';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
6
  import React__default, { useState, useEffect, useMemo, useRef, useCallback, Children, useLayoutEffect, cloneElement, createContext, useContext, useReducer } from 'react';
7
+ import { u as useDisabledStateContext, a as useTooltipContext, g as getOverflowingText, v as visuallyHidden, T as TooltipContextProvider, P as Portal, C as ClickAwayProvider, b as useOverflowTooltipLabel, I as InfiniteScroll } from './_internal/Dx4QtHFB.js';
7
8
  import * as ReactDOM from 'react-dom';
8
9
  import ReactDOM__default from 'react-dom';
9
10
  import { classNames, onEscapePressed, onEnterPressed as onEnterPressed$1, detectHorizontalSwipe } from '@lumx/core/js/utils';
10
11
  import last from 'lodash/last.js';
11
12
  import pull from 'lodash/pull.js';
12
- import { u as useDisabledStateContext, P as Portal, C as ClickAwayProvider, I as InfiniteScroll } from './_internal/CcLi-Wuu.js';
13
13
  import { getDisabledState as getDisabledState$1 } from '@lumx/core/js/utils/disabledState';
14
14
  import { mdiInformationOutline } from '@lumx/icons/esm/information-outline.js';
15
15
  import { mdiAlertCircle } from '@lumx/icons/esm/alert-circle.js';
@@ -448,12 +448,6 @@ function padding(directionOrSize, size) {
448
448
  return spacing('padding', directionOrSize, size);
449
449
  }
450
450
 
451
- /**
452
- * Visually hidden class name.
453
- * Used to hide elements from view but keep them readable from screen readers
454
- */
455
- const visuallyHidden = () => VISUALLY_HIDDEN;
456
-
457
451
  /**
458
452
  * Creates a BEM element class generator function for the given base class.
459
453
  * Returns a function that generates BEM element class names with optional modifiers.
@@ -2715,45 +2709,20 @@ Icon.displayName = Icon$1.displayName;
2715
2709
  Icon.className = Icon$1.className;
2716
2710
  Icon.defaultProps = Icon$1.defaultProps;
2717
2711
 
2718
- const DEFAULT_VALUE = {};
2719
-
2720
- /**
2721
- * Tooltip react context simply used as a marker to know when parent react node have a tooltip
2722
- */
2723
- const TooltipContext = /*#__PURE__*/React__default.createContext(undefined);
2724
- const TooltipContextProvider = ({
2725
- children
2726
- }) => /*#__PURE__*/jsx(TooltipContext.Provider, {
2727
- value: DEFAULT_VALUE,
2728
- children: children
2729
- });
2730
- const useTooltipContext = () => React__default.useContext(TooltipContext);
2731
-
2732
2712
  /**
2733
- * Compute a tooltip label based on a label element `innerText` if the text overflows.
2713
+ * Compute a native `title` from the `innerText` of a label element when its text overflows.
2734
2714
  * Updates dynamically on content changes (but not on resize!)
2735
2715
  */
2736
- const useOverflowTooltipLabel = content => {
2716
+ const useOverflowTitle = content => {
2737
2717
  const parentTooltip = useTooltipContext();
2738
- const [tooltipLabel, setTooltipLabel] = React__default.useState(undefined);
2718
+ const [title, setTitle] = React__default.useState(undefined);
2739
2719
  const [labelElement, setLabelElement] = React__default.useState(null);
2740
2720
  React__default.useLayoutEffect(() => {
2741
- if (
2742
- // Not inside a tooltip
2743
- !parentTooltip && labelElement &&
2744
- // Not inside a visually hidden
2745
- !labelElement?.closest(`.${classNames.visuallyHidden()}`) &&
2746
- // Text overflows
2747
- labelElement.offsetWidth < labelElement.scrollWidth) {
2748
- // Set tooltip label
2749
- setTooltipLabel(labelElement.innerText);
2750
- } else {
2751
- setTooltipLabel(undefined);
2752
- }
2721
+ setTitle(parentTooltip ? undefined : getOverflowingText(labelElement));
2753
2722
  }, [labelElement, parentTooltip, content]);
2754
2723
  return {
2755
2724
  labelRef: setLabelElement,
2756
- tooltipLabel
2725
+ title
2757
2726
  };
2758
2727
  };
2759
2728
 
@@ -2892,16 +2861,16 @@ const Text = forwardRef((props, ref) => {
2892
2861
  ...forwardedProps
2893
2862
  } = props;
2894
2863
  const {
2895
- tooltipLabel,
2864
+ title,
2896
2865
  labelRef
2897
- } = useOverflowTooltipLabel(children);
2866
+ } = useOverflowTitle(children);
2898
2867
  const {
2899
2868
  className,
2900
2869
  style
2901
2870
  } = React__default.useMemo(() => getTextProps(props), [props]);
2902
2871
  return /*#__PURE__*/jsx(Component, {
2903
2872
  ref: useMergeRefs(ref, labelRef),
2904
- title: tooltipLabel,
2873
+ title: title,
2905
2874
  ...forwardedProps,
2906
2875
  className: className,
2907
2876
  style: style,
@@ -4978,6 +4947,60 @@ const offset = (options, deps) => ({
4978
4947
  options: [options, deps]
4979
4948
  });
4980
4949
 
4950
+ /**
4951
+ * Keep track of listeners, only the last registered listener gets activated at any point (previously registered
4952
+ * listener are disabled).
4953
+ * When a listener gets unregistered, the previously registered listener gets enabled again.
4954
+ */
4955
+ function makeListenerTowerContext() {
4956
+ const LISTENERS = [];
4957
+ return {
4958
+ register(listener) {
4959
+ // Disable previous listener.
4960
+ last(LISTENERS)?.disable();
4961
+ // Keep track of current listener.
4962
+ LISTENERS.push(listener);
4963
+ // Enable current listener.
4964
+ listener.enable();
4965
+ },
4966
+ unregister(listener) {
4967
+ // Disable current listener.
4968
+ listener.disable();
4969
+ // Remove current listener.
4970
+ pull(LISTENERS, listener);
4971
+ // Enable previous listener.
4972
+ last(LISTENERS)?.enable();
4973
+ }
4974
+ };
4975
+ }
4976
+
4977
+ const LISTENERS = makeListenerTowerContext();
4978
+
4979
+ /**
4980
+ * Register a global listener on 'Escape' key pressed.
4981
+ *
4982
+ * If multiple listener are registered, only the last one is maintained. When a listener is unregistered, the previous
4983
+ * one gets activated again.
4984
+ *
4985
+ * @param callback Callback
4986
+ * @param closeOnEscape Disables the hook when false
4987
+ */
4988
+ function useCallbackOnEscape(callback, closeOnEscape = true) {
4989
+ useEffect(() => {
4990
+ const rootElement = DOCUMENT?.body;
4991
+ if (!closeOnEscape || !callback || !rootElement) {
4992
+ return undefined;
4993
+ }
4994
+ const onKeyDown = onEscapePressed(callback);
4995
+ const listener = {
4996
+ enable: () => rootElement.addEventListener('keydown', onKeyDown),
4997
+ disable: () => rootElement.removeEventListener('keydown', onKeyDown)
4998
+ };
4999
+ LISTENERS.register(listener);
5000
+ return () => LISTENERS.unregister(listener);
5001
+ }, [callback, closeOnEscape]);
5002
+ }
5003
+
4981
5004
  /**
4982
5005
  * Arrow size (in pixel).
4983
5006
  */
@@ -5075,12 +5098,13 @@ const useInjectTooltipRef = options => {
5075
5098
  isMounted,
5076
5099
  id,
5077
5100
  label,
5101
+ hasLabel,
5078
5102
  ariaLinkMode
5079
5103
  } = options;
5080
5104
  // Only add link when mounted
5081
5105
  const linkId = isMounted ? id : undefined;
5082
5106
  return useMemo(() => {
5083
- if (!label) return children;
5107
+ if (!hasLabel) return children;
5084
5108
 
5085
5109
  // Non-disabled element
5086
5110
  if (/*#__PURE__*/React__default.isValidElement(children) && children.props.disabled !== true && children.props.isDisabled !== true) {
@@ -5106,63 +5130,9 @@ const useInjectTooltipRef = options => {
5106
5130
  ...aria,
5107
5131
  children: children
5108
5132
  });
5109
- }, [label, children, setAnchorElement, linkId, ariaLinkMode]);
5133
+ }, [hasLabel, label, children, setAnchorElement, linkId, ariaLinkMode]);
5110
5134
  };
5111
5135
 
5112
- /**
5113
- * Keep track of listeners, only the last registered listener gets activated at any point (previously registered
5114
- * listener are disabled).
5115
- * When a listener gets unregistered, the previously registered listener gets enabled again.
5116
- */
5117
- function makeListenerTowerContext() {
5118
- const LISTENERS = [];
5119
- return {
5120
- register(listener) {
5121
- // Disable previous listener.
5122
- last(LISTENERS)?.disable();
5123
- // Keep track of current listener.
5124
- LISTENERS.push(listener);
5125
- // Enable current listener.
5126
- listener.enable();
5127
- },
5128
- unregister(listener) {
5129
- // Disable current listener.
5130
- listener.disable();
5131
- // Remove current listener.
5132
- pull(LISTENERS, listener);
5133
- // Enable previous listener.
5134
- last(LISTENERS)?.enable();
5135
- }
5136
- };
5137
- }
5138
-
5139
- const LISTENERS = makeListenerTowerContext();
5140
-
5141
- /**
5142
- * Register a global listener on 'Escape' key pressed.
5143
- *
5144
- * If multiple listener are registered, only the last one is maintained. When a listener is unregistered, the previous
5145
- * one gets activated again.
5146
- *
5147
- * @param callback Callback
5148
- * @param closeOnEscape Disables the hook when false
5149
- */
5150
- function useCallbackOnEscape(callback, closeOnEscape = true) {
5151
- useEffect(() => {
5152
- const rootElement = DOCUMENT?.body;
5153
- if (!closeOnEscape || !callback || !rootElement) {
5154
- return undefined;
5155
- }
5156
- const onKeyDown = onEscapePressed(callback);
5157
- const listener = {
5158
- enable: () => rootElement.addEventListener('keydown', onKeyDown),
5159
- disable: () => rootElement.removeEventListener('keydown', onKeyDown)
5160
- };
5161
- LISTENERS.register(listener);
5162
- return () => LISTENERS.unregister(listener);
5163
- }, [callback, closeOnEscape]);
5164
- }
5165
-
5166
5136
  /** Check if the focus is visible on the given element */
5167
5137
  const isFocusVisible = element => {
5168
5138
  try {
@@ -5307,38 +5277,68 @@ function createTooltipOpenManager(options) {
5307
5277
  };
5308
5278
  }
5309
5279
 
5280
+ /**
5281
+ * SSR-safe version of `useLayoutEffect`.
5282
+ * Uses `useLayoutEffect` on the client and `useEffect` on the server to avoid React SSR warnings.
5283
+ */
5284
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
5285
+
5286
+ /**
5287
+ * Returns a stable callback that always calls the latest version of `fn`.
5288
+ * Useful to avoid re-running effects when a callback prop changes reference.
5289
+ *
5290
+ * https://github.com/facebook/react/issues/14099#issuecomment-440013892
5291
+ *
5292
+ * @param fn A function to stabilize.
5293
+ * @return A stable function with the same signature.
5294
+ */
5295
+ function useEventCallback(fn) {
5296
+ const ref = React__default.useRef(fn);
5297
+ useIsomorphicLayoutEffect(() => {
5298
+ ref.current = fn;
5299
+ });
5300
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5301
+ return React__default.useCallback((...args) => ref.current?.(...args), []);
5302
+ }
5303
+
5310
5304
  /**
5311
5305
  * Hook controlling tooltip visibility using mouse hover the anchor and delay.
5312
5306
  *
5313
5307
  * @param delay Delay in millisecond to display the tooltip.
5314
5308
  * @param anchorElement Tooltip anchor element.
5315
- * @return whether or not to show the tooltip.
5309
+ * @param onOpen Called each time the open delay ends, before the state changes.
5310
+ * @return whether the anchor activates the tooltip, the popper mount callback and a close callback.
5316
5311
  */
5317
- function useTooltipOpen(delay, anchorElement) {
5312
+ function useTooltipOpen(delay, anchorElement, onOpen) {
5318
5313
  const [isOpen, setIsOpen] = useState(false);
5319
5314
  const onPopperMount = useRef(null);
5320
5315
  const managerRef = useRef(null);
5321
-
5322
- // Global close on escape
5323
- useCallbackOnEscape(isOpen ? () => managerRef.current?.close() : undefined);
5316
+ const handleOpen = useEventCallback(onOpen);
5317
+ const close = useCallback(() => managerRef.current?.close(), []);
5324
5318
  useEffect(() => {
5325
5319
  if (!anchorElement) {
5326
5320
  return undefined;
5327
5321
  }
5328
5322
  const manager = createTooltipOpenManager({
5329
5323
  delay,
5330
- onStateChange: setIsOpen
5324
+ onStateChange: value => {
5325
+ if (value) handleOpen();
5326
+ setIsOpen(value);
5327
+ }
5331
5328
  });
5332
5329
  managerRef.current = manager;
5333
5330
  onPopperMount.current = el => manager.attachPopper(el);
5334
5331
  manager.attachAnchor(anchorElement);
5335
5332
  return () => {
5336
5333
  manager.destroy();
5334
+ // The manager dies with the anchor, so the open state must die with it.
5335
+ setIsOpen(false);
5337
5336
  };
5338
- }, [anchorElement, delay]);
5337
+ }, [anchorElement, delay, handleOpen]);
5339
5338
  return {
5340
5339
  isOpen,
5341
- onPopperMount: onPopperMount.current
5340
+ onPopperMount: onPopperMount.current,
5341
+ close
5342
5342
  };
5343
5343
  }
5344
5344
 
@@ -5388,20 +5388,36 @@ const Tooltip = forwardRef((props, ref) => {
5388
5388
  } : {}),
5389
5389
  middleware: [offset(ARROW_SIZE$1)]
5390
5390
  });
5391
+ const [resolvedFunctionLabel, setResolvedFunctionLabel] = useState(undefined);
5392
+ const resolveLabel = () => {
5393
+ if (typeof label === 'function') setResolvedFunctionLabel(label());
5394
+ };
5391
5395
  const position = resolvedPlacement ?? placement;
5392
5396
  const {
5393
5397
  isOpen: isActivated,
5394
- onPopperMount
5395
- } = useTooltipOpen(delay, anchorElement);
5396
- const isOpen = (isActivated || forceOpen) && !!label;
5397
- const isMounted = !!label && (isOpen || closeMode === 'hide');
5398
+ onPopperMount,
5399
+ close
5400
+ } = useTooltipOpen(delay, anchorElement, resolveLabel);
5401
+ const resolvedLabel = typeof label === 'function' ? resolvedFunctionLabel : label;
5402
+ const hasLabel = typeof label === 'function' || !!label;
5403
+ const isOpen = (isActivated || forceOpen) && !!resolvedLabel;
5404
+ const isMounted = !!resolvedLabel && (isOpen || closeMode === 'hide');
5398
5405
  const isHidden = !isOpen && closeMode === 'hide';
5406
+
5407
+ // No dependency list: the text of a function label can change on any render (ex: a toggle by keyboard).
5408
+ useLayoutEffect(() => {
5409
+ if (isActivated || forceOpen) resolveLabel();
5410
+ });
5411
+
5412
+ // A forced-open tooltip does not take Escape from its container (ex: the highlighted option of a combobox).
5413
+ useCallbackOnEscape(isActivated && resolvedLabel ? close : undefined);
5399
5414
  const wrappedChildren = useInjectTooltipRef({
5400
5415
  children,
5401
5416
  setAnchorElement,
5402
5417
  isMounted,
5403
5418
  id,
5404
- label,
5419
+ label: resolvedLabel,
5420
+ hasLabel,
5405
5421
  ariaLinkMode: ariaLinkMode
5406
5422
  });
5407
5423
  const tooltipRef = useMergeRefs(ref, setPopperElement, onPopperMount);
@@ -5413,7 +5429,7 @@ const Tooltip = forwardRef((props, ref) => {
5413
5429
  ref: tooltipRef,
5414
5430
  ...forwardedProps,
5415
5431
  id,
5416
- label: label,
5432
+ label: resolvedLabel,
5417
5433
  position: position,
5418
5434
  isHidden,
5419
5435
  style: isHidden ? undefined : floatingStyles,
@@ -6193,30 +6209,6 @@ function setupRovingTabIndex(options, signal) {
6193
6209
  return nav;
6194
6210
  }
6195
6211
 
6196
- /**
6197
- * SSR-safe version of `useLayoutEffect`.
6198
- * Uses `useLayoutEffect` on the client and `useEffect` on the server to avoid React SSR warnings.
6199
- */
6200
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
6201
-
6202
- /**
6203
- * Returns a stable callback that always calls the latest version of `fn`.
6204
- * Useful to avoid re-running effects when a callback prop changes reference.
6205
- *
6206
- * https://github.com/facebook/react/issues/14099#issuecomment-440013892
6207
- *
6208
- * @param fn A function to stabilize.
6209
- * @return A stable function with the same signature.
6210
- */
6211
- function useEventCallback(fn) {
6212
- const ref = React__default.useRef(fn);
6213
- useIsomorphicLayoutEffect(() => {
6214
- ref.current = fn;
6215
- });
6216
- // eslint-disable-next-line react-hooks/exhaustive-deps
6217
- return React__default.useCallback((...args) => ref.current?.(...args), []);
6218
- }
6219
-
6220
6212
  /** Unref a react ref or element */
6221
6213
  function unref(maybeElement) {
6222
6214
  if (maybeElement instanceof HTMLElement) return maybeElement;
@@ -11039,6 +11031,7 @@ const TextField$1 = props => {
11039
11031
  theme,
11040
11032
  value,
11041
11033
  afterElement,
11034
+ beforeElement,
11042
11035
  input,
11043
11036
  isFocus,
11044
11037
  IconButton,
@@ -11091,6 +11084,9 @@ const TextField$1 = props => {
11091
11084
  color: theme === Theme.dark ? 'light' : undefined,
11092
11085
  icon,
11093
11086
  size: Size.xs
11087
+ }), beforeElement && /*#__PURE__*/jsx("div", {
11088
+ className: element$I('before-element'),
11089
+ children: beforeElement
11094
11090
  }), chips ? /*#__PURE__*/jsxs("div", {
11095
11091
  className: element$I('chips'),
11096
11092
  children: [chips, input]
@@ -11397,6 +11393,7 @@ const TextField = forwardRef((props, ref) => {
11397
11393
  type = DEFAULT_PROPS$X.type,
11398
11394
  value,
11399
11395
  afterElement,
11396
+ beforeElement,
11400
11397
  ...forwardedProps
11401
11398
  } = otherProps;
11402
11399
  const generatedTextFieldId = useId();
@@ -11479,6 +11476,7 @@ const TextField = forwardRef((props, ref) => {
11479
11476
  input,
11480
11477
  id: textFieldId,
11481
11478
  afterElement,
11479
+ beforeElement,
11482
11480
  hasError,
11483
11481
  helperId,
11484
11482
  labelId,
@@ -17534,9 +17532,9 @@ const NavigationItem = Object.assign(forwardRefPolymorphic((props, ref) => {
17534
17532
  } = props;
17535
17533
  const theme = useTheme();
17536
17534
  const {
17537
- tooltipLabel,
17538
- labelRef
17539
- } = useOverflowTooltipLabel(label);
17535
+ labelRef,
17536
+ tooltipLabel
17537
+ } = useOverflowTooltipLabel();
17540
17538
  return /*#__PURE__*/jsx("li", {
17541
17539
  className: classNames.join(className, block$w({
17542
17540
  [`theme-${theme}`]: Boolean(theme)
@@ -19936,6 +19934,7 @@ const SelectTextField$1 = props => {
19936
19934
  // Load more
19937
19935
  onLoadMore,
19938
19936
  beforeOptions,
19937
+ beforeElement,
19939
19938
  // Popover
19940
19939
  popoverProps,
19941
19940
  // Theme
@@ -19980,7 +19979,9 @@ const SelectTextField$1 = props => {
19980
19979
  let displayValue;
19981
19980
  if (isMultiple || isSearching) {
19982
19981
  displayValue = searchText;
19983
- } else if (!isMultiple) {
19982
+ } else if (externalSearchValue === '') {
19983
+ displayValue = '';
19984
+ } else {
19984
19985
  displayValue = getOptionDisplayName(value, getOptionName, getOptionId);
19985
19986
  }
19986
19987
 
@@ -19989,13 +19990,15 @@ const SelectTextField$1 = props => {
19989
19990
  const next = toggleSelection(options, getOptionId, value, selectedOption.value, isMultiple);
19990
19991
  // In multi mode, `toggleSelection` skips when no option matches and returns the
19991
19992
  // unchanged current array — the onChange call is a no-op for the consumer.
19992
- onChange?.(next);
19993
+ // Escape on a closed combobox sends a clear request with an empty option id.
19994
+ const isBlockedClear = !isMultiple && !hasClearButton && selectedOption.value === '';
19995
+ if (!isBlockedClear) onChange?.(next);
19993
19996
 
19994
19997
  // Reset search state after selection.
19995
19998
  setIsSearching(false);
19996
19999
  setSearchText('');
19997
20000
  onSearch?.('');
19998
- }, [getOptionId, isMultiple, onChange, onSearch, options, value]);
20001
+ }, [getOptionId, hasClearButton, isMultiple, onChange, onSearch, options, value]);
19999
20002
 
20000
20003
  // Handle text input changes (search).
20001
20004
  const handleInputChange = useCallback(inputValue => {
@@ -20004,10 +20007,10 @@ const SelectTextField$1 = props => {
20004
20007
  onSearch?.(inputValue);
20005
20008
 
20006
20009
  // When the user clears the input (single mode only), clear the selection too.
20007
- if (!isMultiple && inputValue === '' && value !== undefined && value !== null) {
20010
+ if (!isMultiple && hasClearButton && inputValue === '' && value !== undefined && value !== null) {
20008
20011
  onChange?.(undefined);
20009
20012
  }
20010
- }, [isMultiple, onChange, onSearch, value]);
20013
+ }, [hasClearButton, isMultiple, onChange, onSearch, value]);
20011
20014
 
20012
20015
  // Handle clear button click (single mode only).
20013
20016
  const handleClear = useCallback(event => {
@@ -20071,6 +20074,7 @@ const SelectTextField$1 = props => {
20071
20074
  inputProps: {
20072
20075
  ...consumerInputProps,
20073
20076
  labelProps: labelProps ?? consumerInputProps?.labelProps,
20077
+ beforeElement: beforeElement ?? consumerInputProps?.beforeElement,
20074
20078
  placeholder,
20075
20079
  icon,
20076
20080
  value: displayValue,
@@ -24352,6 +24356,7 @@ function setupTreeList(options = {}) {
24352
24356
  function registerTreeItem(element, itemOptions) {
24353
24357
  const {
24354
24358
  isParent,
24359
+ defaultOpen,
24355
24360
  onOpenChange,
24356
24361
  onChange
24357
24362
  } = itemOptions;
@@ -24361,7 +24366,7 @@ function setupTreeList(options = {}) {
24361
24366
  const hasSelectedBelow = () => hasSelectedSubItem(element);
24362
24367
  let filterState = NO_FILTER_STATE;
24363
24368
  /** Open state set by the user (or the initial state) without a filter. */
24364
- let userOpen = hasSelectedBelow();
24369
+ let userOpen = defaultOpen || hasSelectedBelow();
24365
24370
  /** Open state set by the user during a filter (lasts until the next change of the filter text). */
24366
24371
  let filterOverride = null;
24367
24372
  /**
@@ -24820,8 +24825,8 @@ function isTreeListHandle(handle) {
24820
24825
  * tree `value` holds it. Without, it is not selectable: Enter or a click on a non-selectable parent item
24821
24826
  * opens or closes it, and on a non-selectable leaf item only calls `onClick` (e.g. an action such as
24822
24827
  * "Create a new list…").
24823
- * - The open state is internal: a parent item starts open when a sub-item at any depth is selected.
24824
- * In a combobox, it resets on each popup open.
24828
+ * - The open state is internal: a parent item starts open with `defaultOpen`, or when a sub-item at
24829
+ * any depth is selected. In a combobox, it resets on each popup open.
24825
24830
  * - Touch screen readers: TalkBack (Chrome) can open and close the parent items. On iOS, a user can
24826
24831
  * only reach the sub-items of a selectable parent item through the filter. To support it, use a
24827
24832
  * non-selectable parent item with an "All <name>" leaf item that carries the parent value.
@@ -24836,6 +24841,7 @@ const TreeListItem = forwardRef((props, ref) => {
24836
24841
  children,
24837
24842
  value,
24838
24843
  hasSubItems,
24844
+ defaultOpen,
24839
24845
  onOpenChange,
24840
24846
  onClick,
24841
24847
  before,
@@ -24875,10 +24881,12 @@ const TreeListItem = forwardRef((props, ref) => {
24875
24881
  // Latest props read by the controller.
24876
24882
  const latestProps = useRef({
24877
24883
  isParent,
24884
+ defaultOpen,
24878
24885
  onOpenChange
24879
24886
  });
24880
24887
  latestProps.current = {
24881
24888
  isParent,
24889
+ defaultOpen,
24882
24890
  onOpenChange
24883
24891
  };
24884
24892
  const [state, setState] = useState({
@@ -24892,6 +24900,7 @@ const TreeListItem = forwardRef((props, ref) => {
24892
24900
  if (!element || !tree) return undefined;
24893
24901
  const controller = tree.registerTreeItem(element, {
24894
24902
  isParent: () => latestProps.current.isParent,
24903
+ defaultOpen: latestProps.current.defaultOpen,
24895
24904
  onOpenChange: isOpen => latestProps.current.onOpenChange?.(isOpen),
24896
24905
  onChange: setState
24897
24906
  });