@lumx/react 4.25.0 → 4.25.1-alpha.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
@@ -1898,6 +1898,12 @@ interface ComboboxEventMap {
1898
1898
  * Used to control the loading message text in the live region (ComboboxState).
1899
1899
  */
1900
1900
  loadingAnnouncement: boolean;
1901
+ /**
1902
+ * Fired only when this option becomes the active descendant (true)
1903
+ * or stops being the active descendant (false).
1904
+ * Build the key with optionActiveEvent(optionId).
1905
+ */
1906
+ [event: OptionActiveEvent]: boolean;
1901
1907
  }
1902
1908
  /** Callbacks provided by the consumer (React/Vue) to react to combobox state changes. */
1903
1909
  interface ComboboxCallbacks {
@@ -4308,6 +4314,12 @@ interface RenderOptionContext {
4308
4314
  isSelected: boolean;
4309
4315
  /** Resolved description string (from `getOptionDescription`), if any. Should be forwarded as `description`. */
4310
4316
  description?: string | null;
4317
+ /**
4318
+ * Selection state icon to render after the option label
4319
+ * (single selection: check circle when selected, blank radio otherwise; multiple selection: checkbox).
4320
+ * Should be forwarded as `after` (appended after any custom `after` content).
4321
+ */
4322
+ after?: JSXElement;
4311
4323
  }
4312
4324
  interface BaseSelectProps<O> {
4313
4325
  /** List of option objects. */
package/index.js CHANGED
@@ -26,6 +26,9 @@ import dropRight from 'lodash/dropRight.js';
26
26
  import partition from 'lodash/partition.js';
27
27
  import reduce from 'lodash/reduce.js';
28
28
  import { mdiMenuDown } from '@lumx/icons/esm/menu-down.js';
29
+ import { mdiCheckboxBlankOutline } from '@lumx/icons/esm/checkbox-blank-outline.js';
30
+ import { mdiCheckboxMarked } from '@lumx/icons/esm/checkbox-marked.js';
31
+ import { mdiRadioboxBlank } from '@lumx/icons/esm/radiobox-blank.js';
29
32
  import { mdiClose } from '@lumx/icons/esm/close.js';
30
33
  import isFunction from 'lodash/isFunction.js';
31
34
  import { mdiAlert } from '@lumx/icons/esm/alert.js';
@@ -48,7 +51,6 @@ import { mdiPauseCircleOutline } from '@lumx/icons/esm/pause-circle-outline.js';
48
51
  import chunk from 'lodash/chunk.js';
49
52
  import { mdiDotsVertical } from '@lumx/icons/esm/dots-vertical.js';
50
53
  import take from 'lodash/take.js';
51
- import { mdiRadioboxBlank } from '@lumx/icons/esm/radiobox-blank.js';
52
54
  import { mdiRadioboxMarked } from '@lumx/icons/esm/radiobox-marked.js';
53
55
  import { mdiArrowDown } from '@lumx/icons/esm/arrow-down.js';
54
56
  import { mdiArrowUp } from '@lumx/icons/esm/arrow-up.js';
@@ -6514,6 +6516,11 @@ function setupListbox(handle, signal, notify, options) {
6514
6516
  return focusNav;
6515
6517
  }
6516
6518
 
6519
+ const DEFAULT_COMBOBOX_POPOVER_MAX_HEIGHT = '80vh';
6520
+ const OPTION_ACTIVE_EVENT_PREFIX = 'optionActive:';
6521
+ const optionActiveEvent = optionId => `${OPTION_ACTIVE_EVENT_PREFIX}${optionId}`;
6522
+ const isOptionActiveEvent = event => event.startsWith(OPTION_ACTIVE_EVENT_PREFIX);
6523
+
6517
6524
  /** Options for configuring the shared combobox behavior. */
6518
6525
 
6519
6526
  /**
@@ -6574,6 +6581,9 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
6574
6581
  loadingAnnouncement: new Set()
6575
6582
  };
6576
6583
 
6584
+ /** Per-option subscribers, keyed by optionActive:<id>. Sets are created on demand. */
6585
+ const optionActiveSubscribers = new Map();
6586
+
6577
6587
  /**
6578
6588
  * Last value dispatched for each event. Kept in sync so pull-based subscribers — React's
6579
6589
  * `useSyncExternalStore` via {@link ComboboxHandle.getSnapshot} — can read the current value
@@ -6585,8 +6595,15 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
6585
6595
 
6586
6596
  /** Notify all subscribers for a given event. */
6587
6597
  function notify(event, value) {
6598
+ const previous = latestValues.activeDescendantChange ?? null;
6588
6599
  latestValues[event] = value;
6589
6600
  subscribers[event].forEach(cb => cb(value));
6601
+
6602
+ // Fan out to the 2 affected options only: first the previous one, then the new one.
6603
+ if (event === 'activeDescendantChange' && previous !== value) {
6604
+ if (previous) optionActiveSubscribers.get(optionActiveEvent(previous))?.forEach(cb => cb(false));
6605
+ if (value) optionActiveSubscribers.get(optionActiveEvent(value))?.forEach(cb => cb(true));
6606
+ }
6590
6607
  }
6591
6608
 
6592
6609
  /** Count visible (non-filtered) options. */
@@ -7003,7 +7020,20 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
7003
7020
  };
7004
7021
  },
7005
7022
  subscribe(event, callback) {
7006
- subscribers[event].add(callback);
7023
+ if (isOptionActiveEvent(event)) {
7024
+ const optionCallback = callback;
7025
+ const set = optionActiveSubscribers.get(event) ?? new Set();
7026
+ optionActiveSubscribers.set(event, set);
7027
+ set.add(optionCallback);
7028
+ // Replay (same as open): Vue subscribes after mount and can miss the activation.
7029
+ if (latestValues.activeDescendantChange === event.slice(OPTION_ACTIVE_EVENT_PREFIX.length)) optionCallback(true);
7030
+ return () => {
7031
+ set.delete(optionCallback);
7032
+ if (!set.size) optionActiveSubscribers.delete(event);
7033
+ };
7034
+ }
7035
+ const subs = subscribers[event];
7036
+ subs.add(callback);
7007
7037
  // Replay current loading state to late subscribers so that framework wrappers
7008
7038
  // that subscribe after initial mount (e.g. async Vue watchers) don't miss the
7009
7039
  // initial events fired during mount.
@@ -7016,10 +7046,14 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
7016
7046
 
7017
7047
  // Cleanup function
7018
7048
  return () => {
7019
- subscribers[event].delete(callback);
7049
+ subs.delete(callback);
7020
7050
  };
7021
7051
  },
7022
7052
  getSnapshot(event) {
7053
+ if (isOptionActiveEvent(event)) {
7054
+ // Derived value. No per-id value is stored.
7055
+ return latestValues.activeDescendantChange === event.slice(OPTION_ACTIVE_EVENT_PREFIX.length);
7056
+ }
7023
7057
  return latestValues[event];
7024
7058
  },
7025
7059
  destroy() {
@@ -7039,6 +7073,7 @@ function setupCombobox(callbacks, options, onTriggerAttach) {
7039
7073
  skeletonCount = 0;
7040
7074
  clearTimeout(loadingTimer);
7041
7075
  announcementSent = false;
7076
+ optionActiveSubscribers.clear();
7042
7077
  // Clear all subscribers
7043
7078
  for (const set of Object.values(subscribers)) {
7044
7079
  set.clear();
@@ -9022,6 +9057,9 @@ const ComboboxOption = forwardRef((props, ref) => {
9022
9057
  const internalRef = useRef(null);
9023
9058
  const mergedRef = useMergeRefs(ref, internalRef);
9024
9059
  const [isFiltered, setIsFiltered] = useState(false);
9060
+
9061
+ // Force the tooltip open while the option is the active descendant (keyboard highlight).
9062
+ const isActive = useComboboxEvent(optionActiveEvent(optionId), false);
9025
9063
  useEffect(() => {
9026
9064
  const element = internalRef.current;
9027
9065
  if (!element || !handle) return undefined;
@@ -9060,7 +9098,10 @@ const ComboboxOption = forwardRef((props, ref) => {
9060
9098
  handleClick: onClick,
9061
9099
  id: optionId,
9062
9100
  descriptionId,
9063
- tooltipProps
9101
+ tooltipProps: tooltipProps && {
9102
+ ...tooltipProps,
9103
+ forceOpen: tooltipProps.forceOpen || isActive
9104
+ }
9064
9105
  }, {
9065
9106
  Tooltip
9066
9107
  });
@@ -10251,8 +10292,6 @@ const ComboboxOptionSkeleton = props => {
10251
10292
  ComboboxOptionSkeleton.displayName = COMPONENT_NAME$1c;
10252
10293
  ComboboxOptionSkeleton.className = CLASSNAME$19;
10253
10294
 
10254
- const DEFAULT_COMBOBOX_POPOVER_MAX_HEIGHT = '80vh';
10255
-
10256
10295
  const COMPONENT_NAME$1b = 'ComboboxPopover';
10257
10296
 
10258
10297
  /**
@@ -18563,6 +18602,28 @@ function getOptionDisplayName(value, getOptionName, getOptionId) {
18563
18602
  return '';
18564
18603
  }
18565
18604
 
18605
+ /**
18606
+ * Get the selection state icons of an option. The icon is always rendered after the label.
18607
+ *
18608
+ * - `single`: a check circle icon when selected, a blank radio icon otherwise.
18609
+ * - `multiple`: a checkbox icon, marked or blank.
18610
+ */
18611
+ function getSelectionIcons(selectionType, isSelected) {
18612
+ const color = isSelected ? 'primary' : undefined;
18613
+ if (selectionType === 'multiple') {
18614
+ return Icon$1({
18615
+ icon: isSelected ? mdiCheckboxMarked : mdiCheckboxBlankOutline,
18616
+ color
18617
+ });
18618
+ } else if (selectionType === 'single') {
18619
+ return Icon$1({
18620
+ icon: isSelected ? mdiCheckCircle : mdiRadioboxBlank,
18621
+ color
18622
+ });
18623
+ }
18624
+ return null;
18625
+ }
18626
+
18566
18627
  /**
18567
18628
  * Render options as ComboboxOption elements.
18568
18629
  * Framework-specific components are passed as a second argument.
@@ -18575,6 +18636,7 @@ function renderSelectOptions(props, components) {
18575
18636
  getOptionDescription,
18576
18637
  renderOption,
18577
18638
  selected,
18639
+ selectionType,
18578
18640
  getSectionId,
18579
18641
  renderSectionTitle
18580
18642
  } = props;
@@ -18596,7 +18658,8 @@ function renderSelectOptions(props, components) {
18596
18658
  getOptionName,
18597
18659
  getOptionDescription,
18598
18660
  renderOption,
18599
- selected
18661
+ selected,
18662
+ selectionType
18600
18663
  // getSectionId intentionally omitted to render flat options inside.
18601
18664
  }, components)
18602
18665
  }, sectionId);
@@ -18610,6 +18673,7 @@ function renderSelectOptions(props, components) {
18610
18673
  const name = getWithSelector(getOptionName || getOptionId, item) || id;
18611
18674
  const description = getOptionDescription && getWithSelector(getOptionDescription, item);
18612
18675
  const isSelected = selectedIds?.has(id) ?? false;
18676
+ const after = getSelectionIcons(selectionType, isSelected);
18613
18677
 
18614
18678
  // Delegate to the consumer's render function when provided.
18615
18679
  // The consumer receives core-computed context and is responsible for rendering
@@ -18620,13 +18684,15 @@ function renderSelectOptions(props, components) {
18620
18684
  value: id,
18621
18685
  name,
18622
18686
  isSelected,
18623
- description
18687
+ description,
18688
+ after
18624
18689
  });
18625
18690
  }
18626
18691
  return /*#__PURE__*/jsx(Combobox.Option, {
18627
18692
  value: id,
18628
18693
  description: description,
18629
18694
  isSelected: isSelected,
18695
+ after: after,
18630
18696
  children: name
18631
18697
  }, id);
18632
18698
  });
@@ -18725,7 +18791,8 @@ const SelectButton$2 = (props, {
18725
18791
  renderOption,
18726
18792
  getSectionId,
18727
18793
  renderSectionTitle,
18728
- selected: value
18794
+ selected: value,
18795
+ selectionType
18729
18796
  }, {
18730
18797
  Combobox
18731
18798
  }), onLoadMore && InfiniteScroll && /*#__PURE__*/jsx(InfiniteScroll, {
@@ -18758,6 +18825,7 @@ SelectButton$2.className = CLASSNAME$n;
18758
18825
  * - If the consumer returns a `<Combobox.Option>`, its props/children are merged with the
18759
18826
  * core-computed `value` / `isSelected` / `description` / `key`.
18760
18827
  * When the consumer's `<Combobox.Option>` has no children, falls back to the option `name`.
18828
+ * The core-computed selection icons are kept: `after` is appended to the custom `after`.
18761
18829
  * - If the consumer returns anything else, returns `null` (skips the option).
18762
18830
  *
18763
18831
  * @param renderOption Consumer-provided render function.
@@ -18770,7 +18838,8 @@ function wrapRenderOption(renderOption) {
18770
18838
  value: optionValue,
18771
18839
  isSelected,
18772
18840
  description,
18773
- name
18841
+ name,
18842
+ after
18774
18843
  }) => {
18775
18844
  const node = renderOption(option, index);
18776
18845
  if (!isComponentType(ComboboxOption)(node)) {
@@ -18778,6 +18847,7 @@ function wrapRenderOption(renderOption) {
18778
18847
  }
18779
18848
  const {
18780
18849
  children = name,
18850
+ after: customAfter,
18781
18851
  ...customProps
18782
18852
  } = node.props;
18783
18853
  return /*#__PURE__*/jsx(ComboboxOption, {
@@ -18785,6 +18855,9 @@ function wrapRenderOption(renderOption) {
18785
18855
  value: optionValue,
18786
18856
  isSelected: isSelected,
18787
18857
  description: description,
18858
+ after: /*#__PURE__*/jsxs(Fragment, {
18859
+ children: [cusomAfter, after]
18860
+ }),
18788
18861
  children: children
18789
18862
  }, optionValue);
18790
18863
  };
@@ -19021,7 +19094,8 @@ const SelectTextField$2 = (props, {
19021
19094
  renderOption,
19022
19095
  getSectionId,
19023
19096
  renderSectionTitle,
19024
- selected
19097
+ selected,
19098
+ selectionType: isMultiselectable ? 'multiple' : 'single'
19025
19099
  }, {
19026
19100
  Combobox
19027
19101
  }), afterOptions, onLoadMore && InfiniteScroll && /*#__PURE__*/jsx(InfiniteScroll, {