@tangible/ui 0.2.8 → 0.2.10

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.
Files changed (50) hide show
  1. package/components/Combobox/Combobox.d.ts +16 -11
  2. package/components/Combobox/Combobox.js +42 -196
  3. package/components/Combobox/types.d.ts +3 -7
  4. package/components/MultiCombobox/MultiCombobox.d.ts +16 -11
  5. package/components/MultiCombobox/MultiCombobox.js +42 -154
  6. package/components/MultiCombobox/types.d.ts +4 -7
  7. package/components/MultiSelect/MultiSelect.d.ts +16 -11
  8. package/components/MultiSelect/MultiSelect.js +70 -207
  9. package/components/MultiSelect/types.d.ts +5 -8
  10. package/components/SearchSelect/SearchSelect.d.ts +34 -0
  11. package/components/SearchSelect/SearchSelect.js +462 -0
  12. package/components/SearchSelect/SearchSelectContext.d.ts +7 -0
  13. package/components/SearchSelect/SearchSelectContext.js +21 -0
  14. package/components/SearchSelect/index.d.ts +2 -0
  15. package/components/SearchSelect/index.js +1 -0
  16. package/components/SearchSelect/types.d.ts +153 -0
  17. package/components/SearchSelect/types.js +5 -0
  18. package/components/Select/Select.d.ts +16 -11
  19. package/components/Select/Select.js +78 -237
  20. package/components/Select/types.d.ts +5 -8
  21. package/components/index.d.ts +2 -0
  22. package/components/index.js +1 -0
  23. package/package.json +5 -1
  24. package/styles/all.css +1 -1
  25. package/styles/all.expanded.css +180 -0
  26. package/styles/all.expanded.unlayered.css +180 -0
  27. package/styles/all.unlayered.css +1 -1
  28. package/styles/components/_bundle.scss +8 -4
  29. package/styles/components/search-select.scss +244 -0
  30. package/tui-manifest.json +74 -2
  31. package/utils/listbox/blur.d.ts +14 -0
  32. package/utils/listbox/blur.js +51 -0
  33. package/utils/listbox/filter-active-index.d.ts +16 -0
  34. package/utils/listbox/filter-active-index.js +72 -0
  35. package/utils/listbox/floating.d.ts +7 -0
  36. package/utils/listbox/floating.js +34 -0
  37. package/utils/listbox/group.d.ts +26 -0
  38. package/utils/listbox/group.js +40 -0
  39. package/utils/listbox/ids.d.ts +9 -0
  40. package/utils/listbox/ids.js +31 -0
  41. package/utils/listbox/index.d.ts +9 -0
  42. package/utils/listbox/index.js +11 -0
  43. package/utils/listbox/navigation.d.ts +27 -0
  44. package/utils/listbox/navigation.js +53 -0
  45. package/utils/listbox/registry.d.ts +61 -0
  46. package/utils/listbox/registry.js +121 -0
  47. package/utils/listbox/scroll.d.ts +7 -0
  48. package/utils/listbox/scroll.js +15 -0
  49. package/utils/listbox/trigger.d.ts +16 -0
  50. package/utils/listbox/trigger.js +35 -0
@@ -1,4 +1,4 @@
1
- import { type SelectProps, type SelectTriggerProps, type SelectContentProps, type SelectOptionProps, type SelectGroupProps, type SelectLabelProps } from './types';
1
+ import { type SelectProps, type SelectTriggerProps, type SelectContentProps, type SelectOptionProps } from './types';
2
2
  declare function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, side, align, sideOffset, clearable, clearLabel, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, children, }: SelectProps): import("react/jsx-runtime").JSX.Element;
3
3
  declare namespace SelectRoot {
4
4
  var displayName: string;
@@ -15,14 +15,13 @@ declare function SelectOptionComponent({ value: optionValue, disabled, textValue
15
15
  declare namespace SelectOptionComponent {
16
16
  var displayName: string;
17
17
  }
18
- declare function SelectGroupComponent({ className, children }: SelectGroupProps): import("react/jsx-runtime").JSX.Element;
19
- declare namespace SelectGroupComponent {
20
- var displayName: string;
21
- }
22
- declare function SelectLabelComponent({ className, children }: SelectLabelProps): import("react/jsx-runtime").JSX.Element;
23
- declare namespace SelectLabelComponent {
24
- var displayName: string;
25
- }
18
+ declare const SelectGroupComponent: {
19
+ ({ className, children }: import("..").SearchSelectGroupProps): import("react/jsx-runtime").JSX.Element;
20
+ displayName: string;
21
+ }, SelectLabelComponent: {
22
+ ({ className, children }: import("..").SearchSelectLabelProps): import("react/jsx-runtime").JSX.Element;
23
+ displayName: string;
24
+ };
26
25
  type SelectCompound = typeof SelectRoot & {
27
26
  Trigger: typeof SelectTriggerComponent;
28
27
  Content: typeof SelectContentComponent;
@@ -34,7 +33,13 @@ export declare const Select: SelectCompound;
34
33
  export declare const SelectTrigger: typeof SelectTriggerComponent;
35
34
  export declare const SelectContent: typeof SelectContentComponent;
36
35
  export declare const SelectOption: typeof SelectOptionComponent;
37
- export declare const SelectGroup: typeof SelectGroupComponent;
38
- export declare const SelectLabel: typeof SelectLabelComponent;
36
+ export declare const SelectGroup: {
37
+ ({ className, children }: import("..").SearchSelectGroupProps): import("react/jsx-runtime").JSX.Element;
38
+ displayName: string;
39
+ };
40
+ export declare const SelectLabel: {
41
+ ({ className, children }: import("..").SearchSelectLabelProps): import("react/jsx-runtime").JSX.Element;
42
+ displayName: string;
43
+ };
39
44
  export { useSelectContext as useSelect } from './SelectContext';
40
45
  export type { SelectContextValue } from './types';
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import React, { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, cloneElement, isValidElement, } from 'react';
3
- import { isDev } from '../../utils/is-dev.js';
4
- import { useFloating, offset, flip, shift, size as sizeMiddleware, autoUpdate, FloatingPortal, useDismiss, useInteractions, useListNavigation, useTypeahead, useRole, useClick, } from '@floating-ui/react';
2
+ import React, { useCallback, useEffect, useMemo, useRef, useState, cloneElement, isValidElement, } from 'react';
3
+ import { FloatingPortal } from '@floating-ui/react';
5
4
  import { cx } from '../../utils/cx.js';
6
5
  import { toKey } from '../../utils/value-key.js';
7
6
  import { getPortalRootFor } from '../../utils/portal.js';
7
+ import { useOptionRegistry, useOptionRegistration, useListboxIds, useListboxFloating, useListboxNavigation, useListboxBlurGuard, useTriggerPointerDownFix, useFocusTriggerOnOpen, useActiveOptionScroll, optionIdForIndex, createListboxGroupComponents, } from '../../utils/listbox/index.js';
8
8
  import { Icon } from '../Icon/index.js';
9
9
  import { SelectContext, SelectContentContext, useSelectContext, useSelectContentContext, } from './SelectContext.js';
10
10
  import { toPlacement, } from './types.js';
@@ -19,11 +19,6 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
19
19
  const value = isValueControlled ? controlledValue : uncontrolledValue;
20
20
  // Store display text separately so it persists when dropdown is closed
21
21
  const [displayText, setDisplayText] = useState(undefined);
22
- // Option registration
23
- const optionsRef = useRef(new Map());
24
- const [registryVersion, setRegistryVersion] = useState(0);
25
- // Track open state via ref so unregisterOption can check synchronously
26
- const openRef = useRef(false);
27
22
  const setValue = useCallback((newValue, textValue) => {
28
23
  if (!isValueControlled) {
29
24
  setUncontrolledValue(newValue);
@@ -31,33 +26,10 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
31
26
  }
32
27
  onValueChange?.(newValue);
33
28
  }, [isValueControlled, onValueChange]);
34
- // Sync displayText when controlled value changes externally (parent prop update)
35
- useEffect(() => {
36
- if (value === undefined) {
37
- setDisplayText(undefined);
38
- }
39
- else {
40
- const option = optionsRef.current.get(toKey(value));
41
- if (option) {
42
- setDisplayText(option.textValue);
43
- }
44
- }
45
- }, [value]);
46
- // Initialize displayText when options register (handles defaultValue case)
47
- // This runs when registryVersion changes, catching newly registered options
48
- useEffect(() => {
49
- if (value !== undefined && !displayText) {
50
- const option = optionsRef.current.get(toKey(value));
51
- if (option) {
52
- setDisplayText(option.textValue);
53
- }
54
- }
55
- }, [registryVersion, value, displayText]);
56
29
  // Controlled/uncontrolled open
57
30
  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen ?? false);
58
31
  const isOpenControlled = controlledOpen !== undefined;
59
32
  const open = isOpenControlled ? controlledOpen : uncontrolledOpen;
60
- openRef.current = open;
61
33
  // Guard flag: when Backspace/Delete clears a closed Select, Floating UI's
62
34
  // composed handlers (useTypeahead/useListNavigation) also fire and call
63
35
  // setOpen(true). This ref rejects that open request within the same microtask.
@@ -73,9 +45,7 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
73
45
  onOpenChange?.(nextOpen);
74
46
  }, [disabled, isOpenControlled, onOpenChange]);
75
47
  // IDs
76
- const baseId = useId();
77
- const triggerId = triggerIdProp ?? `${baseId}-trigger`;
78
- const listboxId = `${baseId}-listbox`;
48
+ const { controlId: triggerId, listboxId } = useListboxIds(triggerIdProp, 'trigger');
79
49
  // Refs for list navigation
80
50
  const listRef = useRef([]);
81
51
  const listContentRef = useRef([]);
@@ -83,58 +53,39 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
83
53
  const [activeIndex, setActiveIndex] = useState(null);
84
54
  // Compute placement from props
85
55
  const placement = toPlacement(side, align);
86
- // Get ordered options
87
- const getOrderedOptions = useCallback(() => {
88
- const options = Array.from(optionsRef.current.values());
89
- return options.sort((a, b) => {
90
- if (!a.ref.current || !b.ref.current)
91
- return 0;
92
- const position = a.ref.current.compareDocumentPosition(b.ref.current);
93
- if (position & Node.DOCUMENT_POSITION_FOLLOWING)
94
- return -1;
95
- if (position & Node.DOCUMENT_POSITION_PRECEDING)
96
- return 1;
97
- return 0;
98
- });
99
- }, []);
100
- // Memoized ordered options - recompute when registry changes
101
- // Also update listContentRef synchronously for typeahead
102
- const orderedOptions = useMemo(() => {
103
- const options = getOrderedOptions();
104
- // Update typeahead ref synchronously (during render is safe for refs)
105
- listContentRef.current = options.map((opt) => opt.textValue);
106
- return options;
56
+ // Shared option registry (listbox engine)
57
+ const { optionsRef, registryVersion, registerOption, unregisterOption, orderedOptions, orderedOptionsRef, optionIndexMap, } = useOptionRegistry({ open, listContentRef });
58
+ // Sync displayText when controlled value changes externally (parent prop update)
59
+ useEffect(() => {
60
+ if (value === undefined) {
61
+ setDisplayText(undefined);
62
+ }
63
+ else {
64
+ const option = optionsRef.current.get(toKey(value));
65
+ if (option) {
66
+ setDisplayText(option.textValue);
67
+ }
68
+ }
69
+ // optionsRef is a stable ref from the registry hook
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, [value]);
72
+ // Initialize displayText when options register (handles defaultValue case)
73
+ // This runs when registryVersion changes, catching newly registered options
74
+ useEffect(() => {
75
+ if (value !== undefined && !displayText) {
76
+ const option = optionsRef.current.get(toKey(value));
77
+ if (option) {
78
+ setDisplayText(option.textValue);
79
+ }
80
+ }
107
81
  // eslint-disable-next-line react-hooks/exhaustive-deps
108
- }, [registryVersion]);
109
- // O(1) index lookup map — rebuilt when orderedOptions changes
110
- const optionIndexMap = useMemo(() => {
111
- const map = new Map();
112
- orderedOptions.forEach((opt, i) => map.set(toKey(opt.value), i));
113
- return map;
114
- }, [orderedOptions]);
115
- // Ref for stable handleSelect — avoids recreating on registry changes
116
- const orderedOptionsRef = useRef(orderedOptions);
117
- orderedOptionsRef.current = orderedOptions;
82
+ }, [registryVersion, value, displayText]);
118
83
  // Floating UI setup - in Root so Trigger and Content can share
119
- const { refs, floatingStyles, context } = useFloating({
120
- placement,
84
+ const { refs, floatingStyles, context } = useListboxFloating({
121
85
  open,
122
86
  onOpenChange: setOpen,
123
- middleware: [
124
- offset(sideOffset),
125
- flip({ padding: 8 }),
126
- shift({ padding: 8 }),
127
- sizeMiddleware({
128
- apply({ availableHeight, rects, elements }) {
129
- Object.assign(elements.floating.style, {
130
- maxHeight: `${Math.min(availableHeight - 16, 300)}px`,
131
- minWidth: `${rects.reference.width}px`,
132
- });
133
- },
134
- padding: 8,
135
- }),
136
- ],
137
- whileElementsMounted: autoUpdate,
87
+ placement,
88
+ offset: sideOffset,
138
89
  });
139
90
  // Handle selection — reads orderedOptionsRef to avoid recreating on registry changes
140
91
  const handleSelect = useCallback((index) => {
@@ -145,73 +96,33 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
145
96
  setValue(option.value, option.textValue);
146
97
  setOpen(false);
147
98
  }
148
- }, [setValue, setOpen]);
149
- // Floating UI interactions
150
- // Use 'click' (not 'mousedown') so button has focus when dropdown opens
151
- // This ensures keyboard navigation works immediately
152
- const click = useClick(context);
153
- const dismiss = useDismiss(context);
154
- const role = useRole(context, { role: 'listbox' });
99
+ },
100
+ // orderedOptionsRef is a stable ref from the registry hook
101
+ [setValue, setOpen, orderedOptionsRef]);
155
102
  // Compute disabled indices for keyboard navigation to skip
156
103
  const disabledIndices = useMemo(() => orderedOptions.reduce((acc, opt, i) => {
157
104
  if (opt.disabled)
158
105
  acc.push(i);
159
106
  return acc;
160
107
  }, []), [orderedOptions]);
161
- const listNavigation = useListNavigation(context, {
108
+ // Shared interaction stack (listbox engine)
109
+ const { getReferenceProps, getFloatingProps, getItemProps } = useListboxNavigation(context, {
162
110
  listRef,
163
111
  activeIndex,
164
112
  onNavigate: setActiveIndex,
165
- loop: true,
166
- virtual: true,
113
+ disabledIndices,
114
+ withClick: true,
167
115
  focusItemOnOpen: true,
168
116
  selectedIndex: value !== undefined ? (optionIndexMap.get(toKey(value)) ?? -1) : -1,
169
- disabledIndices,
170
- });
171
- const typeahead = useTypeahead(context, {
172
- listRef: listContentRef,
173
- activeIndex,
174
- onMatch: (index) => {
175
- if (open) {
176
- setActiveIndex(index);
177
- }
117
+ typeahead: {
118
+ listContentRef,
119
+ onMatch: (index) => {
120
+ if (open) {
121
+ setActiveIndex(index);
122
+ }
123
+ },
178
124
  },
179
- resetMs: 500,
180
125
  });
181
- const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([
182
- click,
183
- dismiss,
184
- role,
185
- listNavigation,
186
- typeahead,
187
- ]);
188
- // Flag: when the dropdown opens, the first registerOption call clears the
189
- // registry before adding. This ensures stale entries from options that changed
190
- // while closed don't persist — and avoids a useLayoutEffect ordering issue
191
- // where a parent clear would run after children register.
192
- const prevOpenForFlush = useRef(open);
193
- const needsFlushRef = useRef(false);
194
- if (open && !prevOpenForFlush.current)
195
- needsFlushRef.current = true;
196
- prevOpenForFlush.current = open;
197
- // Register option (stable callback - no value/displayText deps)
198
- const registerOption = useCallback((option) => {
199
- if (needsFlushRef.current) {
200
- optionsRef.current.clear();
201
- needsFlushRef.current = false;
202
- }
203
- optionsRef.current.set(toKey(option.value), option);
204
- setRegistryVersion((v) => v + 1);
205
- }, []);
206
- const unregisterOption = useCallback((optionValue) => {
207
- // When the dropdown closes, options unmount and call unregister in cleanup.
208
- // Skip the delete to preserve the registry — displayText and typeahead
209
- // depend on it while closed. Options re-register on next open (same keys).
210
- if (!openRef.current)
211
- return;
212
- optionsRef.current.delete(toKey(optionValue));
213
- setRegistryVersion((v) => v + 1);
214
- }, []);
215
126
  // Highlighted value for keyboard navigation
216
127
  const highlightedValue = activeIndex !== null ? orderedOptions[activeIndex]?.value ?? null : null;
217
128
  // Reset active index when closing
@@ -232,11 +143,7 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
232
143
  }
233
144
  }, [open, orderedOptions, optionIndexMap, value]);
234
145
  // Scroll active option into view
235
- useEffect(() => {
236
- if (open && activeIndex !== null && listRef.current[activeIndex]) {
237
- listRef.current[activeIndex]?.scrollIntoView({ block: 'nearest' });
238
- }
239
- }, [open, activeIndex]);
146
+ useActiveOptionScroll(open, activeIndex, listRef);
240
147
  // ==========================================================================
241
148
  // Context Value
242
149
  // ==========================================================================
@@ -317,11 +224,7 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
317
224
  const sizeClass = size !== 'md' ? `is-size-${size}` : undefined;
318
225
  const hasValue = displayText !== undefined;
319
226
  // Ensure trigger has focus when dropdown opens (Safari doesn't focus buttons on click)
320
- useEffect(() => {
321
- if (open && refs.reference.current) {
322
- refs.reference.current.focus();
323
- }
324
- }, [open, refs.reference]);
227
+ useFocusTriggerOnOpen(open, refs.reference);
325
228
  // Handle Enter/Space for selection when open, Delete/Backspace to clear when closed
326
229
  const handleKeyDown = useCallback((e) => {
327
230
  if (open && (e.key === 'Enter' || e.key === ' ')) {
@@ -337,23 +240,12 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
337
240
  }, [open, activeIndex, handleSelect, clearable, hasValue, setValue, justClearedRef]);
338
241
  // Close dropdown when focus leaves trigger
339
242
  // Uses blur guard pattern: only close if focus moved outside controlled elements
340
- const handleBlur = useCallback((e) => {
341
- if (!open)
342
- return;
343
- const relatedTarget = e.relatedTarget;
344
- // Focus left the document entirely (e.g., clicked outside window)
345
- if (relatedTarget === null) {
346
- setOpen(false);
347
- return;
348
- }
349
- // Check if focus moved to the floating content (clicking an option)
350
- const floating = refs.floating.current;
351
- if (floating && relatedTarget && floating.contains(relatedTarget)) {
352
- return;
353
- }
354
- // Focus moved somewhere outside our control — close
355
- setOpen(false);
356
- }, [open, setOpen, refs.floating]);
243
+ // Shared three-branch focus-loss guard (listbox engine)
244
+ const handleBlur = useListboxBlurGuard({
245
+ open,
246
+ setOpen,
247
+ floatingRef: refs.floating,
248
+ });
357
249
  // Handle clear button - clears value, keeps focus on trigger
358
250
  const handleClear = useCallback((e) => {
359
251
  e.preventDefault(); // Keep focus in trigger
@@ -364,19 +256,8 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
364
256
  // Return focus to trigger after clearing
365
257
  refs.reference.current?.focus();
366
258
  }, [disabled, setValue, refs.reference]);
367
- // Safari doesn't focus buttons on mousedown — focus jumps to <body>, firing
368
- // a blur that handleBlur reads as focus-loss and closes the menu, so a click
369
- // on the open trigger closes-then-reopens and never visibly toggles. Focus
370
- // the trigger ourselves and cancel the browser's focus juggling. Mouse/pen
371
- // only: cancelling pointerdown on touch swallows the compatibility click.
372
- const handleTriggerPointerDown = useCallback((e) => {
373
- if (e.pointerType !== 'mouse' && e.pointerType !== 'pen')
374
- return;
375
- if (e.button !== 0)
376
- return;
377
- e.preventDefault();
378
- e.currentTarget.focus();
379
- }, []);
259
+ // Safari focus-on-mousedown fix (listbox engine — see hook doc)
260
+ const handleTriggerPointerDown = useTriggerPointerDownFix();
380
261
  // Get Floating UI's reference props - pass our handlers so they get composed
381
262
  const floatingProps = getReferenceProps({
382
263
  'aria-activedescendant': activeIndex !== null ? `${listboxId}-option-${activeIndex}` : undefined,
@@ -480,21 +361,17 @@ function SelectOptionComponent({ value: optionValue, disabled = false, textValue
480
361
  const { value: selectedValue, setValue, setOpen, listboxId, registerOption, unregisterOption, highlightedValue, getItemProps, } = useSelectContext();
481
362
  const { listRef, optionIndexMap } = useSelectContentContext();
482
363
  const ref = useRef(null);
483
- // Derive textValue from children if not explicitly provided
484
- const textValue = explicitTextValue ?? (typeof children === 'string' ? children : '');
485
- // Warn in dev if textValue couldn't be derived (once per mount)
486
- const warnedTextValueRef = useRef(false);
487
- useEffect(() => {
488
- if (isDev() && !textValue && !warnedTextValueRef.current) {
489
- warnedTextValueRef.current = true;
490
- console.warn(`Select.Option with value="${optionValue}" has no textValue. Provide textValue prop when children is not a string.`);
491
- }
492
- }, [textValue, optionValue]);
493
- // Register option
494
- useLayoutEffect(() => {
495
- registerOption({ value: optionValue, ref, disabled, textValue });
496
- return () => unregisterOption(optionValue);
497
- }, [optionValue, disabled, textValue, registerOption, unregisterOption]);
364
+ // Shared registration: textValue derivation, dev warn, layout-effect register
365
+ const textValue = useOptionRegistration({
366
+ value: optionValue,
367
+ disabled,
368
+ textValue: explicitTextValue,
369
+ children,
370
+ componentName: 'Select.Option',
371
+ elementRef: ref,
372
+ registerOption,
373
+ unregisterOption,
374
+ });
498
375
  // O(1) index lookup via Map
499
376
  const index = optionIndexMap.get(toKey(optionValue)) ?? -1;
500
377
  // Assign ref to listRef for navigation
@@ -511,7 +388,7 @@ function SelectOptionComponent({ value: optionValue, disabled = false, textValue
511
388
  setValue(optionValue, textValue);
512
389
  setOpen(false);
513
390
  }, [disabled, optionValue, textValue, setValue, setOpen]);
514
- return (_jsxs("div", { ref: ref, id: index >= 0 ? `${listboxId}-option-${index}` : undefined, role: "option", className: cx('tui-select__option', className), "aria-selected": isSelected, "aria-disabled": disabled || undefined, "data-highlighted": isHighlighted || undefined, "data-disabled": disabled || undefined, ...getItemProps({
391
+ return (_jsxs("div", { ref: ref, id: optionIdForIndex(listboxId, index), role: "option", className: cx('tui-select__option', className), "aria-selected": isSelected, "aria-disabled": disabled || undefined, "data-highlighted": isHighlighted || undefined, "data-disabled": disabled || undefined, ...getItemProps({
515
392
  onClick: handleClick,
516
393
  }), children: [_jsx("span", { className: "tui-select__option-content", children: children }), isSelected && (_jsx(Icon, { name: "system/check", className: "tui-select__option-check", "aria-hidden": "true" }))] }));
517
394
  }
@@ -519,51 +396,15 @@ SelectOptionComponent.displayName = 'Select.Option';
519
396
  // =============================================================================
520
397
  // Select.Group
521
398
  // =============================================================================
522
- function SelectGroupComponent({ className, children }) {
523
- const groupId = useId();
524
- const groupRef = useRef(null);
525
- // Guard aria-labelledby: only set when a Label child actually exists in the DOM.
526
- // Without this, aria-labelledby points to a non-existent ID, which per AccName 1.2
527
- // step 2B overrides all other name sources and resolves to empty string.
528
- // useLayoutEffect runs before paint, so AT never sees the dangling reference.
529
- // groupId is stable (from useId) and label presence is stable after mount —
530
- // only run once to avoid a DOM query on every render.
531
- useLayoutEffect(() => {
532
- const groupEl = groupRef.current;
533
- if (!groupEl)
534
- return;
535
- const labelId = `${groupId}-label`;
536
- const labelEl = groupEl.querySelector(`#${CSS.escape(labelId)}`);
537
- if (labelEl) {
538
- groupEl.setAttribute('aria-labelledby', labelId);
539
- }
540
- else {
541
- groupEl.removeAttribute('aria-labelledby');
542
- }
543
- }, [groupId]);
544
- return (_jsx("div", { ref: groupRef, role: "group", className: cx('tui-select__group', className), children: _jsx(SelectGroupContext.Provider, { value: { groupId }, children: children }) }));
545
- }
546
- SelectGroupComponent.displayName = 'Select.Group';
547
- const SelectGroupContext = React.createContext(null);
548
- // =============================================================================
549
- // Select.Label
550
- // =============================================================================
551
- function SelectLabelComponent({ className, children }) {
552
- const groupContext = React.useContext(SelectGroupContext);
553
- // DEV: warn if Label is used outside a Group — it has no semantic effect there
554
- const warnedRef = useRef(false);
555
- useEffect(() => {
556
- if (isDev() && !groupContext && !warnedRef.current) {
557
- warnedRef.current = true;
558
- console.warn('Select.Label rendered outside Select.Group has no effect. ' +
559
- 'Wrap in Select.Group so aria-labelledby is wired correctly.');
560
- }
561
- }, [groupContext]);
562
- // No aria-hidden — aria-labelledby on Group references this element,
563
- // so screen readers need access to read the label text.
564
- return (_jsx("div", { id: groupContext ? `${groupContext.groupId}-label` : undefined, className: cx('tui-select__label', className), children: children }));
565
- }
566
- SelectLabelComponent.displayName = 'Select.Label';
399
+ // Shared Group/Label pair from the listbox engine. NOTE: this migrated
400
+ // Select's Group from a mount-once label query to the re-evaluating hasLabel
401
+ // model the other three listboxes use — a Label appearing after mount (async
402
+ // content) is now picked up. Deliberate, strictly-more-correct change.
403
+ const { Group: SelectGroupComponent, Label: SelectLabelComponent } = createListboxGroupComponents({
404
+ componentName: 'Select',
405
+ groupClass: 'tui-select__group',
406
+ labelClass: 'tui-select__label',
407
+ });
567
408
  export const Select = SelectRoot;
568
409
  Select.Trigger = SelectTriggerComponent;
569
410
  Select.Content = SelectContentComponent;
@@ -1,5 +1,5 @@
1
1
  import type { Placement, ReferenceType } from '@floating-ui/react';
2
- import type { RefObject, CSSProperties, MutableRefObject } from 'react';
2
+ import type { CSSProperties, MutableRefObject } from 'react';
3
3
  import type { SizeStandard } from '../../types/sizes';
4
4
  import type { OptionValue } from '../../utils/value-key';
5
5
  /**
@@ -157,14 +157,11 @@ export type SelectLabelProps = {
157
157
  children: React.ReactNode;
158
158
  };
159
159
  /**
160
- * Registration record for an option.
160
+ * Registration record for an option — now defined by the shared listbox
161
+ * engine; re-exported here for back-compat.
161
162
  */
162
- export type RegisteredOption = {
163
- value: OptionValue;
164
- ref: RefObject<HTMLElement | null>;
165
- disabled: boolean;
166
- textValue: string;
167
- };
163
+ import type { RegisteredOption } from '../../utils/listbox';
164
+ export type { RegisteredOption };
168
165
  /**
169
166
  * Select context: config, IDs, refs, callbacks, and reactive state.
170
167
  * All sub-components subscribe to one context.
@@ -37,6 +37,7 @@ export { StepIndicator } from './StepIndicator';
37
37
  export { StepList } from './StepList';
38
38
  export { DataTable } from './Table';
39
39
  export { SearchInput } from './SearchInput';
40
+ export { SearchSelect, SearchSelectTrigger, SearchSelectContent, SearchSelectOption, SearchSelectGroup, SearchSelectLabel, useSearchSelect, } from './SearchSelect';
40
41
  export { Switch } from './Switch';
41
42
  export { Tabs } from './Tabs';
42
43
  export { Textarea } from './Textarea';
@@ -79,6 +80,7 @@ export type { StepListProps, StepListItemProps } from './StepList';
79
80
  export type { DataTableProps } from './Table';
80
81
  export type { TabsProps, TabsListProps, TabProps, TabPanelProps, TabsVariant, TabsActivationMode, TabsOrientation, } from './Tabs';
81
82
  export type { SearchInputProps } from './SearchInput';
83
+ export type { SearchSelectProps, SearchSelectTriggerProps, SearchSelectContentProps, SearchSelectOptionProps, SearchSelectGroupProps, SearchSelectLabelProps, SearchSelectLabels, } from './SearchSelect';
82
84
  export type { SwitchProps } from './Switch';
83
85
  export type { TextareaProps, TextareaResize } from './Textarea';
84
86
  export type { TextInputProps, TextInputType } from './TextInput';
@@ -35,6 +35,7 @@ export { StepIndicator } from './StepIndicator/index.js';
35
35
  export { StepList } from './StepList/index.js';
36
36
  export { DataTable } from './Table/index.js';
37
37
  export { SearchInput } from './SearchInput/index.js';
38
+ export { SearchSelect, SearchSelectTrigger, SearchSelectContent, SearchSelectOption, SearchSelectGroup, SearchSelectLabel, useSearchSelect, } from './SearchSelect/index.js';
38
39
  export { Switch } from './Switch/index.js';
39
40
  export { Tabs } from './Tabs/index.js';
40
41
  export { Textarea } from './Textarea/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -164,6 +164,10 @@
164
164
  "import": "./components/SearchInput/index.js",
165
165
  "types": "./components/SearchInput/index.d.ts"
166
166
  },
167
+ "./components/SearchSelect": {
168
+ "import": "./components/SearchSelect/index.js",
169
+ "types": "./components/SearchSelect/index.d.ts"
170
+ },
167
171
  "./components/SegmentedControl": {
168
172
  "import": "./components/SegmentedControl/index.js",
169
173
  "types": "./components/SegmentedControl/index.d.ts"