@tangible/ui 0.2.7 → 0.2.9

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 (62) hide show
  1. package/components/ColorPicker/ColorField.js +33 -10
  2. package/components/Combobox/Combobox.d.ts +16 -11
  3. package/components/Combobox/Combobox.js +42 -196
  4. package/components/Combobox/types.d.ts +3 -7
  5. package/components/MultiCombobox/MultiCombobox.d.ts +16 -11
  6. package/components/MultiCombobox/MultiCombobox.js +46 -157
  7. package/components/MultiCombobox/types.d.ts +4 -7
  8. package/components/MultiSelect/MultiSelect.d.ts +16 -11
  9. package/components/MultiSelect/MultiSelect.js +74 -210
  10. package/components/MultiSelect/types.d.ts +5 -8
  11. package/components/SearchSelect/SearchSelect.d.ts +34 -0
  12. package/components/SearchSelect/SearchSelect.js +444 -0
  13. package/components/SearchSelect/SearchSelectContext.d.ts +7 -0
  14. package/components/SearchSelect/SearchSelectContext.js +21 -0
  15. package/components/SearchSelect/index.d.ts +2 -0
  16. package/components/SearchSelect/index.js +1 -0
  17. package/components/SearchSelect/types.d.ts +134 -0
  18. package/components/SearchSelect/types.js +5 -0
  19. package/components/Select/Select.d.ts +16 -11
  20. package/components/Select/Select.js +78 -237
  21. package/components/Select/types.d.ts +5 -8
  22. package/components/Tabs/Tabs.js +16 -1
  23. package/components/index.d.ts +2 -0
  24. package/components/index.js +1 -0
  25. package/package.json +5 -1
  26. package/styles/all.css +1 -1
  27. package/styles/all.expanded.css +230 -34
  28. package/styles/all.expanded.unlayered.css +230 -34
  29. package/styles/all.unlayered.css +1 -1
  30. package/styles/components/_bundle.scss +8 -4
  31. package/styles/components/combobox.scss +29 -6
  32. package/styles/components/date-picker.scss +9 -3
  33. package/styles/components/multi-combobox.scss +18 -3
  34. package/styles/components/multi-select.scss +28 -9
  35. package/styles/components/notice.scss +7 -5
  36. package/styles/components/search-select.scss +244 -0
  37. package/styles/components/segmented-control.scss +10 -5
  38. package/styles/components/select.scss +16 -7
  39. package/styles/components/sidebar.scss +31 -22
  40. package/styles/components/tabs.scss +26 -15
  41. package/tui-manifest.json +75 -2
  42. package/utils/color/color.js +14 -2
  43. package/utils/listbox/blur.d.ts +14 -0
  44. package/utils/listbox/blur.js +51 -0
  45. package/utils/listbox/filter-active-index.d.ts +16 -0
  46. package/utils/listbox/filter-active-index.js +72 -0
  47. package/utils/listbox/floating.d.ts +7 -0
  48. package/utils/listbox/floating.js +34 -0
  49. package/utils/listbox/group.d.ts +26 -0
  50. package/utils/listbox/group.js +40 -0
  51. package/utils/listbox/ids.d.ts +9 -0
  52. package/utils/listbox/ids.js +31 -0
  53. package/utils/listbox/index.d.ts +9 -0
  54. package/utils/listbox/index.js +11 -0
  55. package/utils/listbox/navigation.d.ts +27 -0
  56. package/utils/listbox/navigation.js +53 -0
  57. package/utils/listbox/registry.d.ts +61 -0
  58. package/utils/listbox/registry.js +121 -0
  59. package/utils/listbox/scroll.d.ts +7 -0
  60. package/utils/listbox/scroll.js +15 -0
  61. package/utils/listbox/trigger.d.ts +16 -0
  62. package/utils/listbox/trigger.js +35 -0
@@ -130,10 +130,15 @@
130
130
  inset: 0;
131
131
  background-color: var(--#{sys.$prefix}color-bg-overlay);
132
132
  animation: #{sys.$prefix}fadeFromTransparent var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
133
+ }
133
134
 
134
- [data-state="closing"] > & {
135
- animation: #{sys.$prefix}fadeToTransparent var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing) forwards;
136
- }
135
+ // State/position animations. Top-level rules: trailing `&` would splice the
136
+ // interface prefix after the drawer attributes (`[data-state] > :where(…)`)
137
+ // and never match — which also meant closing never animated, so the panel's
138
+ // animationend (which unmounts the drawer) had nothing to fire from.
139
+ :where(.#{sys.$prefix}interface)
140
+ .#{sys.$prefix}sidebar-drawer[data-state="closing"] > .#{sys.$prefix}sidebar-drawer__backdrop {
141
+ animation: #{sys.$prefix}fadeToTransparent var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing) forwards;
137
142
  }
138
143
 
139
144
  :where(.#{sys.$prefix}interface) .#{sys.$prefix}sidebar-drawer__panel {
@@ -142,25 +147,6 @@
142
147
  max-width: 90vw;
143
148
  height: 100%;
144
149
 
145
- // Left position (default): slide in from left
146
- [data-position="left"] > & {
147
- animation: #{sys.$prefix}slideInFromLeft var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
148
- }
149
-
150
- // Right position: slide in from right
151
- [data-position="right"] > & {
152
- animation: #{sys.$prefix}slideInFromRight var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
153
- }
154
-
155
- // Closing: slide out
156
- [data-state="closing"][data-position="left"] > & {
157
- animation: #{sys.$prefix}slideOutToLeft var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing) forwards;
158
- }
159
-
160
- [data-state="closing"][data-position="right"] > & {
161
- animation: #{sys.$prefix}slideOutToRight var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing) forwards;
162
- }
163
-
164
150
  // Sidebar inside panel should fill height and remove side borders
165
151
  .#{sys.$prefix}sidebar {
166
152
  height: 100%;
@@ -169,6 +155,29 @@
169
155
  }
170
156
  }
171
157
 
158
+ // Left position (default): slide in from left
159
+ :where(.#{sys.$prefix}interface)
160
+ .#{sys.$prefix}sidebar-drawer[data-position="left"] > .#{sys.$prefix}sidebar-drawer__panel {
161
+ animation: #{sys.$prefix}slideInFromLeft var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
162
+ }
163
+
164
+ // Right position: slide in from right
165
+ :where(.#{sys.$prefix}interface)
166
+ .#{sys.$prefix}sidebar-drawer[data-position="right"] > .#{sys.$prefix}sidebar-drawer__panel {
167
+ animation: #{sys.$prefix}slideInFromRight var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
168
+ }
169
+
170
+ // Closing: slide out
171
+ :where(.#{sys.$prefix}interface)
172
+ .#{sys.$prefix}sidebar-drawer[data-state="closing"][data-position="left"] > .#{sys.$prefix}sidebar-drawer__panel {
173
+ animation: #{sys.$prefix}slideOutToLeft var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing) forwards;
174
+ }
175
+
176
+ :where(.#{sys.$prefix}interface)
177
+ .#{sys.$prefix}sidebar-drawer[data-state="closing"][data-position="right"] > .#{sys.$prefix}sidebar-drawer__panel {
178
+ animation: #{sys.$prefix}slideOutToRight var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing) forwards;
179
+ }
180
+
172
181
  // ---------------------------------------------------------------------------
173
182
  // Slide-in Keyframes
174
183
  // ---------------------------------------------------------------------------
@@ -81,23 +81,30 @@
81
81
  gap: var(--#{sys.$prefix}tabs-gap, var(--#{sys.$prefix}spacing-xs));
82
82
  align-items: center;
83
83
 
84
- // Pill variant: list has background
85
- [data-variant="pill"] & {
86
- background: var(--#{sys.$prefix}tabs-list-bg, var(--#{sys.$prefix}color-bg-muted));
87
- padding: var(--#{sys.$prefix}tabs-list-padding, var(--#{sys.$prefix}spacing-xs));
88
- border-radius: var(--#{sys.$prefix}tabs-list-radius, var(--#{sys.$prefix}radius-lg));
89
- }
84
+ }
90
85
 
91
- // Underline variant: bottom border on list
92
- [data-variant="underline"] & {
93
- gap: var(--#{sys.$prefix}tabs-gap, var(--#{sys.$prefix}spacing-md));
94
- border-block-end: var(--#{sys.$prefix}border-width) solid var(--#{sys.$prefix}color-border);
95
- }
86
+ // Variant list treatments. NOT `[data-variant] &` inside the list block —
87
+ // trailing `&` substitutes the FULL parent selector (interface prefix
88
+ // included), compiling to `[data-variant] :where(.tui-interface) …`, which
89
+ // requires the attribute ABOVE the interface and matches nothing. The
90
+ // attribute lives on the .tui-tabs root.
91
+
92
+ // Pill variant: list has background
93
+ :where(.#{sys.$prefix}interface) .#{sys.$prefix}tabs[data-variant="pill"] .#{sys.$prefix}tabs__list {
94
+ background: var(--#{sys.$prefix}tabs-list-bg, var(--#{sys.$prefix}color-bg-muted));
95
+ padding: var(--#{sys.$prefix}tabs-list-padding, var(--#{sys.$prefix}spacing-xs));
96
+ border-radius: var(--#{sys.$prefix}tabs-list-radius, var(--#{sys.$prefix}radius-lg));
97
+ }
96
98
 
97
- // Outline variant: no list background
98
- [data-variant="outline"] & {
99
- gap: var(--#{sys.$prefix}tabs-gap, var(--#{sys.$prefix}spacing-xs));
100
- }
99
+ // Underline variant: bottom border on list
100
+ :where(.#{sys.$prefix}interface) .#{sys.$prefix}tabs[data-variant="underline"] .#{sys.$prefix}tabs__list {
101
+ gap: var(--#{sys.$prefix}tabs-gap, var(--#{sys.$prefix}spacing-md));
102
+ border-block-end: var(--#{sys.$prefix}border-width) solid var(--#{sys.$prefix}color-border);
103
+ }
104
+
105
+ // Outline variant: no list background
106
+ :where(.#{sys.$prefix}interface) .#{sys.$prefix}tabs[data-variant="outline"] .#{sys.$prefix}tabs__list {
107
+ gap: var(--#{sys.$prefix}tabs-gap, var(--#{sys.$prefix}spacing-xs));
101
108
  }
102
109
 
103
110
  // ---------------------------------------------------------------------------
@@ -170,6 +177,10 @@
170
177
 
171
178
  .#{sys.$prefix}interface [data-variant="pill"] .#{sys.$prefix}tabs__tab {
172
179
  --_radius: var(--#{sys.$prefix}tabs-tab-radius, var(--#{sys.$prefix}radius-md));
180
+ // Pill tabs sit on the color-bg-muted track; inactive labels need full
181
+ // color-fg for 4.5:1 (fg-muted measures 4.39:1 on the track) — same
182
+ // treatment as SegmentedControl's pill items.
183
+ --_fg: var(--#{sys.$prefix}tabs-tab-fg, var(--#{sys.$prefix}color-fg));
173
184
  --_bg-hover: var(--#{sys.$prefix}tabs-tab-bg-hover, color-mix(in srgb, var(--#{sys.$prefix}color-fg) 8%, transparent));
174
185
 
175
186
  &[data-state="active"] {
package/tui-manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.2.7",
3
- "generated": "2026-08-15T05:33:19.704Z",
2
+ "version": "0.2.9",
3
+ "generated": "2026-08-15T17:38:52.605Z",
4
4
  "components": {
5
5
  "Accordion": {
6
6
  "props": {
@@ -1981,6 +1981,7 @@
1981
1981
  "--tui-notice-padding",
1982
1982
  "--tui-notice-gap",
1983
1983
  "--tui-notice-para-gap",
1984
+ "--tui-notice-icon",
1984
1985
  "--tui-notice-title-size",
1985
1986
  "--tui-notice-foot-basis"
1986
1987
  ],
@@ -2560,6 +2561,78 @@
2560
2561
  "use": null,
2561
2562
  "notFor": null
2562
2563
  },
2564
+ "SearchSelect": {
2565
+ "props": {
2566
+ "className": {
2567
+ "type": "string",
2568
+ "required": false
2569
+ },
2570
+ "children": {
2571
+ "type": "ReactNode",
2572
+ "required": false,
2573
+ "description": "Custom trigger content — replaces the default value/placeholder text\n(the chevron stays). The fields dynamic-value picker renders its\nbolt + type + key pill here. NOTE: with an `aria-label` on the Root the\naccessible name is frozen to that label — custom content is then\ninvisible to AT (family-wide follow-up in the roadmap)."
2574
+ },
2575
+ "disabled": {
2576
+ "type": "boolean",
2577
+ "required": false
2578
+ },
2579
+ "id": {
2580
+ "type": "string",
2581
+ "required": false
2582
+ },
2583
+ "style": {
2584
+ "type": "CSSProperties",
2585
+ "required": false
2586
+ },
2587
+ "title": {
2588
+ "type": "string",
2589
+ "required": false
2590
+ },
2591
+ "role": {
2592
+ "type": "AriaRole",
2593
+ "required": false
2594
+ },
2595
+ "rel": {
2596
+ "type": "string",
2597
+ "required": false
2598
+ },
2599
+ "onChange": {
2600
+ "type": "FormEventHandler<HTMLButtonElement>",
2601
+ "required": false
2602
+ },
2603
+ "onClick": {
2604
+ "type": "MouseEventHandler<HTMLButtonElement>",
2605
+ "required": false
2606
+ }
2607
+ },
2608
+ "cssTokens": [
2609
+ "--tui-search-select-trigger-bg",
2610
+ "--tui-search-select-trigger-fg",
2611
+ "--tui-search-select-trigger-border",
2612
+ "--tui-search-select-trigger-border-focus",
2613
+ "--tui-search-select-trigger-radius",
2614
+ "--tui-search-select-panel-bg",
2615
+ "--tui-search-select-panel-border",
2616
+ "--tui-search-select-panel-shadow",
2617
+ "--tui-search-select-panel-radius",
2618
+ "--tui-search-select-panel-width",
2619
+ "--tui-search-select-option-bg-hover",
2620
+ "--tui-search-select-option-bg-selected"
2621
+ ],
2622
+ "story": {
2623
+ "title": "Forms/SearchSelect",
2624
+ "tags": [
2625
+ "stable"
2626
+ ]
2627
+ },
2628
+ "subcomponents": null,
2629
+ "description": null,
2630
+ "gotchas": null,
2631
+ "examples": null,
2632
+ "related": null,
2633
+ "use": null,
2634
+ "notFor": null
2635
+ },
2563
2636
  "SegmentedControl": {
2564
2637
  "props": {
2565
2638
  "value": {
@@ -186,10 +186,22 @@ export function parseColor(value) {
186
186
  const raw = String(value ?? '').trim();
187
187
  if (!raw)
188
188
  return { kind: 'invalid', raw };
189
- // CSS variable reference — stored verbatim, not required to resolve.
189
+ // CSS variable reference — stored verbatim, not required to resolve. The
190
+ // fallback is deliberately NOT run back through parseColor: any <color> is
191
+ // legal there, including ones this grammar doesn't cover (named colours,
192
+ // currentColor, color-mix(), lab()/lch(), nested vars). Instead, reject
193
+ // resource-loading/legacy function tokens and declaration-breaking
194
+ // characters — the permissive grammar accepted `var(--x, url(//evil))` as a
195
+ // "valid colour", which then landed verbatim in style attributes downstream.
190
196
  const varMatch = raw.match(/^var\(\s*(--[A-Za-z0-9-_]+)\s*(?:,\s*([\s\S]+?)\s*)?\)$/);
191
197
  if (varMatch) {
192
- return { kind: 'var', raw, name: varMatch[1], fallback: varMatch[2] };
198
+ const fallback = varMatch[2];
199
+ const unsafeFallback = fallback != null &&
200
+ (/[;{}<>]/.test(fallback) ||
201
+ /(?:^|[^a-z-])(?:url|src|image|image-set|cross-fade|paint|element|expression)\s*\(/i.test(fallback));
202
+ if (unsafeFallback)
203
+ return { kind: 'invalid', raw };
204
+ return { kind: 'var', raw, name: varMatch[1], fallback };
193
205
  }
194
206
  // Hex
195
207
  if (raw.startsWith('#')) {
@@ -0,0 +1,14 @@
1
+ export declare function useListboxBlurGuard(options: {
2
+ open: boolean;
3
+ setOpen: (open: boolean) => void;
4
+ /** refs.floating from Floating UI. */
5
+ floatingRef: {
6
+ current: HTMLElement | null;
7
+ };
8
+ /** Additional element that keeps the listbox open when focus lands inside. */
9
+ extraContainerRef?: {
10
+ current: unknown;
11
+ };
12
+ /** Runs immediately before each close (both branches). */
13
+ onBeforeClose?: () => void;
14
+ }): (e: React.FocusEvent) => void;
@@ -0,0 +1,51 @@
1
+ import { useCallback } from 'react';
2
+ // =============================================================================
3
+ // Listbox blur guard
4
+ // =============================================================================
5
+ //
6
+ // The shared three-branch focus-loss algorithm all four listboxes use on
7
+ // their reference element:
8
+ //
9
+ // 1. relatedTarget === null → focus left the document (clicked outside the
10
+ // window) → close.
11
+ // 2. focus moved INTO the floating listbox (clicking an option) → stay open.
12
+ // 3. anything else → close.
13
+ //
14
+ // Deltas covered by options:
15
+ // - `extraContainer` (MultiCombobox): focus moving to a chip's × button —
16
+ // inside the reference wrapper but outside the input — must not close.
17
+ // - `onBeforeClose` (Combobox/MultiCombobox): end searching mode on every
18
+ // close path.
19
+ //
20
+ // =============================================================================
21
+ export function useListboxBlurGuard(options) {
22
+ const { open, setOpen, floatingRef, extraContainerRef, onBeforeClose } = options;
23
+ return useCallback((e) => {
24
+ if (!open)
25
+ return;
26
+ const relatedTarget = e.relatedTarget;
27
+ // Focus left the document entirely (e.g., clicked outside window)
28
+ if (relatedTarget === null) {
29
+ onBeforeClose?.();
30
+ setOpen(false);
31
+ return;
32
+ }
33
+ // Check if focus moved to the floating content (clicking an option)
34
+ const floating = floatingRef.current;
35
+ if (floating && relatedTarget && floating.contains(relatedTarget)) {
36
+ return;
37
+ }
38
+ // Focus moved into the extra container (e.g. a chip's remove button
39
+ // inside the token-field wrapper) — stay open
40
+ const extra = extraContainerRef?.current;
41
+ if (extra && relatedTarget && extra.contains?.(relatedTarget)) {
42
+ return;
43
+ }
44
+ // Focus moved somewhere outside our control — close
45
+ onBeforeClose?.();
46
+ setOpen(false);
47
+ },
48
+ // Refs are stable; callbacks are the caller's responsibility to memoise.
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ [open, setOpen, onBeforeClose]);
51
+ }
@@ -0,0 +1,16 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import type { RegisteredOption } from './registry';
3
+ export declare function useFilterStableActiveIndex(options: {
4
+ open: boolean;
5
+ orderedOptions: RegisteredOption[];
6
+ activeIndex: number;
7
+ setActiveIndex: (index: number) => void;
8
+ /**
9
+ * The useListNavigation listRef. When provided it is TRUNCATED to the
10
+ * filtered option count: options assign their element by index but a hidden
11
+ * option (index -1) never clears its old slot, so after filtering 8 → 2 the
12
+ * array still reports length 8 and Floating UI navigates six dead slots —
13
+ * no highlight, no aria-activedescendant, Enter a silent no-op.
14
+ */
15
+ listRef?: MutableRefObject<(HTMLElement | null)[]>;
16
+ }): void;
@@ -0,0 +1,72 @@
1
+ import { useEffect, useLayoutEffect, useRef } from 'react';
2
+ import { toKey } from '../value-key.js';
3
+ // =============================================================================
4
+ // Filter-stable active index
5
+ // =============================================================================
6
+ //
7
+ // For input-filtered listboxes (Combobox, SearchSelect): as the user types,
8
+ // options mount/unmount and indices shift. Keep the highlighted OPTION stable
9
+ // when it survives the filter; otherwise fall to the first enabled option;
10
+ // reset on close. Uses the `-1` sentinel activeIndex model.
11
+ //
12
+ // MultiCombobox deliberately keeps its own inline copy — its navigability
13
+ // predicate folds in max-reached state (extra deps), which this shared hook
14
+ // doesn't model.
15
+ //
16
+ // =============================================================================
17
+ export function useFilterStableActiveIndex(options) {
18
+ const { open, orderedOptions, activeIndex, setActiveIndex, listRef } = options;
19
+ // Truncate stale navigation slots BEFORE Floating UI reads them (layout
20
+ // effect: same phase options re-register in).
21
+ useLayoutEffect(() => {
22
+ if (listRef && listRef.current.length > orderedOptions.length) {
23
+ listRef.current.length = orderedOptions.length;
24
+ }
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, [orderedOptions]);
27
+ // Track previous highlighted value to maintain selection across filter changes
28
+ const prevHighlightedValueRef = useRef(null);
29
+ // Update activeIndex when options change (filtering)
30
+ // Stable logic: keep highlighted if still present, else first enabled, else -1
31
+ useEffect(() => {
32
+ if (!open)
33
+ return;
34
+ const prevValue = prevHighlightedValueRef.current;
35
+ const enabledOptions = orderedOptions.filter((opt) => !opt.disabled);
36
+ if (enabledOptions.length === 0) {
37
+ setActiveIndex(-1);
38
+ prevHighlightedValueRef.current = null;
39
+ return;
40
+ }
41
+ // If previously highlighted value still exists and is enabled, keep it
42
+ if (prevValue !== null) {
43
+ const prevIndex = orderedOptions.findIndex((opt) => toKey(opt.value) === toKey(prevValue) && !opt.disabled);
44
+ if (prevIndex >= 0) {
45
+ setActiveIndex(prevIndex);
46
+ return;
47
+ }
48
+ }
49
+ // Otherwise, set to first enabled option
50
+ const firstEnabledIndex = orderedOptions.findIndex((opt) => !opt.disabled);
51
+ setActiveIndex(firstEnabledIndex >= 0 ? firstEnabledIndex : -1);
52
+ if (firstEnabledIndex >= 0) {
53
+ prevHighlightedValueRef.current = orderedOptions[firstEnabledIndex].value;
54
+ }
55
+ // setActiveIndex is a stable state setter
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ }, [open, orderedOptions]);
58
+ // Track highlighted value when activeIndex changes
59
+ useEffect(() => {
60
+ if (activeIndex >= 0 && orderedOptions[activeIndex]) {
61
+ prevHighlightedValueRef.current = orderedOptions[activeIndex].value;
62
+ }
63
+ }, [activeIndex, orderedOptions]);
64
+ // Reset activeIndex when closing
65
+ useEffect(() => {
66
+ if (!open) {
67
+ setActiveIndex(-1);
68
+ prevHighlightedValueRef.current = null;
69
+ }
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, [open]);
72
+ }
@@ -0,0 +1,7 @@
1
+ import { type Placement, type UseFloatingReturn } from '@floating-ui/react';
2
+ export declare function useListboxFloating(options: {
3
+ open: boolean;
4
+ onOpenChange: (open: boolean) => void;
5
+ placement?: Placement;
6
+ offset?: number;
7
+ }): UseFloatingReturn;
@@ -0,0 +1,34 @@
1
+ import { autoUpdate, flip, offset, shift, size as sizeMiddleware, useFloating, } from '@floating-ui/react';
2
+ // =============================================================================
3
+ // Listbox floating panel
4
+ // =============================================================================
5
+ //
6
+ // The shared useFloating configuration: anchored panel that flips/shifts with
7
+ // 8px padding, caps its height to the available space (max 300px), and never
8
+ // renders narrower than its reference. Select parameterises placement/offset
9
+ // via props; the other three pin the defaults.
10
+ //
11
+ // =============================================================================
12
+ export function useListboxFloating(options) {
13
+ const { open, onOpenChange, placement = 'bottom-start', offset: offsetProp = 4 } = options;
14
+ return useFloating({
15
+ placement,
16
+ open,
17
+ onOpenChange,
18
+ middleware: [
19
+ offset(offsetProp),
20
+ flip({ padding: 8 }),
21
+ shift({ padding: 8 }),
22
+ sizeMiddleware({
23
+ apply({ availableHeight, rects, elements }) {
24
+ Object.assign(elements.floating.style, {
25
+ maxHeight: `${Math.min(availableHeight - 16, 300)}px`,
26
+ minWidth: `${rects.reference.width}px`,
27
+ });
28
+ },
29
+ padding: 8,
30
+ }),
31
+ ],
32
+ whileElementsMounted: autoUpdate,
33
+ });
34
+ }
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from 'react';
2
+ export type ListboxGroupProps = {
3
+ className?: string;
4
+ children?: ReactNode;
5
+ };
6
+ export type ListboxLabelProps = {
7
+ className?: string;
8
+ children?: ReactNode;
9
+ };
10
+ export declare function createListboxGroupComponents(config: {
11
+ /** e.g. 'Select' — used for displayNames and dev warnings. */
12
+ componentName: string;
13
+ /** e.g. 'tui-select__group' */
14
+ groupClass: string;
15
+ /** e.g. 'tui-select__label' */
16
+ labelClass: string;
17
+ }): {
18
+ Group: {
19
+ ({ className, children }: ListboxGroupProps): import("react/jsx-runtime").JSX.Element;
20
+ displayName: string;
21
+ };
22
+ Label: {
23
+ ({ className, children }: ListboxLabelProps): import("react/jsx-runtime").JSX.Element;
24
+ displayName: string;
25
+ };
26
+ };
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
3
+ import { cx } from '../cx.js';
4
+ import { isDev } from '../is-dev.js';
5
+ export function createListboxGroupComponents(config) {
6
+ const { componentName, groupClass, labelClass } = config;
7
+ const GroupContext = createContext(null);
8
+ function GroupComponent({ className, children }) {
9
+ const groupId = useId();
10
+ const groupRef = useRef(null);
11
+ const [hasLabel, setHasLabel] = useState(false);
12
+ // Check if a Label child rendered — guard aria-labelledby to prevent a
13
+ // dangling reference (see module header).
14
+ useLayoutEffect(() => {
15
+ if (groupRef.current) {
16
+ const labelEl = groupRef.current.querySelector(`#${CSS.escape(`${groupId}-label`)}`);
17
+ setHasLabel(!!labelEl);
18
+ }
19
+ }, [groupId, children]);
20
+ return (_jsx("div", { ref: groupRef, role: "group", "aria-labelledby": hasLabel ? `${groupId}-label` : undefined, className: cx(groupClass, className), children: _jsx(GroupContext.Provider, { value: { groupId }, children: children }) }));
21
+ }
22
+ GroupComponent.displayName = `${componentName}.Group`;
23
+ function LabelComponent({ className, children }) {
24
+ const groupContext = useContext(GroupContext);
25
+ // DEV: warn if Label is used outside a Group — it has no semantic effect there
26
+ const warnedRef = useRef(false);
27
+ useEffect(() => {
28
+ if (isDev() && !groupContext && !warnedRef.current) {
29
+ warnedRef.current = true;
30
+ console.warn(`${componentName}.Label rendered outside ${componentName}.Group has no effect. ` +
31
+ `Wrap in ${componentName}.Group so aria-labelledby is wired correctly.`);
32
+ }
33
+ }, [groupContext]);
34
+ // No aria-hidden — aria-labelledby on Group references this element,
35
+ // so screen readers need access to read the label text.
36
+ return (_jsx("div", { id: groupContext ? `${groupContext.groupId}-label` : undefined, className: cx(labelClass, className), children: children }));
37
+ }
38
+ LabelComponent.displayName = `${componentName}.Label`;
39
+ return { Group: GroupComponent, Label: LabelComponent };
40
+ }
@@ -0,0 +1,9 @@
1
+ import { type OptionValue } from '../value-key';
2
+ export declare function useListboxIds(controlIdProp: string | undefined, controlSuffix: 'trigger' | 'input'): {
3
+ controlId: string;
4
+ listboxId: string;
5
+ };
6
+ /** Index-based option ID (Select/MultiSelect). Undefined when unregistered. */
7
+ export declare function optionIdForIndex(listboxId: string, index: number): string | undefined;
8
+ /** Hash-based option ID (Combobox/MultiCombobox) — stable across filtering. */
9
+ export declare function optionIdForValue(listboxId: string, value: OptionValue): string;
@@ -0,0 +1,31 @@
1
+ import { useId } from 'react';
2
+ import { hashForId } from '../hash.js';
3
+ import { toKey } from '../value-key.js';
4
+ // =============================================================================
5
+ // Listbox ID plumbing
6
+ // =============================================================================
7
+ //
8
+ // Two option-ID schemes exist deliberately — do not unify:
9
+ // - INDEX-based (Select/MultiSelect): `${listboxId}-option-${index}`. Values
10
+ // may contain characters that are invalid in HTML IDs, so the index is the
11
+ // safe key. Static lists — indices are stable.
12
+ // - HASH-based (Combobox/MultiCombobox): `${listboxId}-opt-${hash}`. Filtered
13
+ // lists shift indices as the user types, so IDs key off the value instead
14
+ // (FNV-1a hash keeps them ID-safe).
15
+ //
16
+ // =============================================================================
17
+ export function useListboxIds(controlIdProp, controlSuffix) {
18
+ const baseId = useId();
19
+ return {
20
+ controlId: controlIdProp ?? `${baseId}-${controlSuffix}`,
21
+ listboxId: `${baseId}-listbox`,
22
+ };
23
+ }
24
+ /** Index-based option ID (Select/MultiSelect). Undefined when unregistered. */
25
+ export function optionIdForIndex(listboxId, index) {
26
+ return index >= 0 ? `${listboxId}-option-${index}` : undefined;
27
+ }
28
+ /** Hash-based option ID (Combobox/MultiCombobox) — stable across filtering. */
29
+ export function optionIdForValue(listboxId, value) {
30
+ return `${listboxId}-opt-${hashForId(toKey(value))}`;
31
+ }
@@ -0,0 +1,9 @@
1
+ export { useOptionRegistry, useOptionRegistration, deriveOptionText, type RegisteredOption, type OptionRegistry, } from './registry';
2
+ export { useListboxIds, optionIdForIndex, optionIdForValue } from './ids';
3
+ export { useListboxFloating } from './floating';
4
+ export { useActiveOptionScroll } from './scroll';
5
+ export { createListboxGroupComponents, type ListboxGroupProps, type ListboxLabelProps, } from './group';
6
+ export { useListboxNavigation } from './navigation';
7
+ export { useFilterStableActiveIndex } from './filter-active-index';
8
+ export { useListboxBlurGuard } from './blur';
9
+ export { useTriggerPointerDownFix, useFocusTriggerOnOpen } from './trigger';
@@ -0,0 +1,11 @@
1
+ // Shared listbox engine — internal to TUI, not exported from the package.
2
+ // Consumers: Select, MultiSelect, Combobox, MultiCombobox (and SearchSelect).
3
+ export { useOptionRegistry, useOptionRegistration, deriveOptionText, } from './registry.js';
4
+ export { useListboxIds, optionIdForIndex, optionIdForValue } from './ids.js';
5
+ export { useListboxFloating } from './floating.js';
6
+ export { useActiveOptionScroll } from './scroll.js';
7
+ export { createListboxGroupComponents, } from './group.js';
8
+ export { useListboxNavigation } from './navigation.js';
9
+ export { useFilterStableActiveIndex } from './filter-active-index.js';
10
+ export { useListboxBlurGuard } from './blur.js';
11
+ export { useTriggerPointerDownFix, useFocusTriggerOnOpen } from './trigger.js';
@@ -0,0 +1,27 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import { type FloatingContext } from '@floating-ui/react';
3
+ export declare function useListboxNavigation(context: FloatingContext, options: {
4
+ listRef: MutableRefObject<(HTMLElement | null)[]>;
5
+ /** Floating UI model: null = no active option (callers adapt sentinels). */
6
+ activeIndex: number | null;
7
+ onNavigate: (index: number | null) => void;
8
+ disabledIndices: number[];
9
+ /** Open on trigger click (Select/MultiSelect). Inputs open themselves. */
10
+ withClick: boolean;
11
+ /** Only spread when defined — Floating UI's default ('auto') differs from false. */
12
+ focusItemOnOpen?: boolean;
13
+ /** Select only: seed navigation from the selected option. */
14
+ selectedIndex?: number;
15
+ /** Enables typeahead (Select/MultiSelect). onMatch keeps caller guards local. */
16
+ typeahead?: {
17
+ listContentRef: MutableRefObject<string[]>;
18
+ onMatch: (index: number) => void;
19
+ };
20
+ /**
21
+ * Custom useDismiss outsidePress predicate. Needed when the component
22
+ * toggles open from its own click handler on an element that is NOT the
23
+ * domReference (SearchSelect's trigger): without excluding it, dismiss
24
+ * closes on pointerdown and the click handler re-opens — a flicker loop.
25
+ */
26
+ dismissOutsidePress?: (event: MouseEvent) => boolean;
27
+ }): import("@floating-ui/react").UseInteractionsReturn;