@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.
- package/components/Combobox/Combobox.d.ts +16 -11
- package/components/Combobox/Combobox.js +42 -196
- package/components/Combobox/types.d.ts +3 -7
- package/components/MultiCombobox/MultiCombobox.d.ts +16 -11
- package/components/MultiCombobox/MultiCombobox.js +42 -154
- package/components/MultiCombobox/types.d.ts +4 -7
- package/components/MultiSelect/MultiSelect.d.ts +16 -11
- package/components/MultiSelect/MultiSelect.js +70 -207
- package/components/MultiSelect/types.d.ts +5 -8
- package/components/SearchSelect/SearchSelect.d.ts +34 -0
- package/components/SearchSelect/SearchSelect.js +462 -0
- package/components/SearchSelect/SearchSelectContext.d.ts +7 -0
- package/components/SearchSelect/SearchSelectContext.js +21 -0
- package/components/SearchSelect/index.d.ts +2 -0
- package/components/SearchSelect/index.js +1 -0
- package/components/SearchSelect/types.d.ts +153 -0
- package/components/SearchSelect/types.js +5 -0
- package/components/Select/Select.d.ts +16 -11
- package/components/Select/Select.js +78 -237
- package/components/Select/types.d.ts +5 -8
- package/components/index.d.ts +2 -0
- package/components/index.js +1 -0
- package/package.json +5 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +180 -0
- package/styles/all.expanded.unlayered.css +180 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +8 -4
- package/styles/components/search-select.scss +244 -0
- package/tui-manifest.json +74 -2
- package/utils/listbox/blur.d.ts +14 -0
- package/utils/listbox/blur.js +51 -0
- package/utils/listbox/filter-active-index.d.ts +16 -0
- package/utils/listbox/filter-active-index.js +72 -0
- package/utils/listbox/floating.d.ts +7 -0
- package/utils/listbox/floating.js +34 -0
- package/utils/listbox/group.d.ts +26 -0
- package/utils/listbox/group.js +40 -0
- package/utils/listbox/ids.d.ts +9 -0
- package/utils/listbox/ids.js +31 -0
- package/utils/listbox/index.d.ts +9 -0
- package/utils/listbox/index.js +11 -0
- package/utils/listbox/navigation.d.ts +27 -0
- package/utils/listbox/navigation.js +53 -0
- package/utils/listbox/registry.d.ts +61 -0
- package/utils/listbox/registry.js +121 -0
- package/utils/listbox/scroll.d.ts +7 -0
- package/utils/listbox/scroll.js +15 -0
- package/utils/listbox/trigger.d.ts +16 -0
- package/utils/listbox/trigger.js +35 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SelectProps, type SelectTriggerProps, type SelectContentProps, type SelectOptionProps
|
|
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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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:
|
|
38
|
-
|
|
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,
|
|
3
|
-
import {
|
|
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
|
|
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
|
-
//
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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 } =
|
|
120
|
-
placement,
|
|
84
|
+
const { refs, floatingStyles, context } = useListboxFloating({
|
|
121
85
|
open,
|
|
122
86
|
onOpenChange: setOpen,
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
},
|
|
149
|
-
//
|
|
150
|
-
|
|
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
|
-
|
|
108
|
+
// Shared interaction stack (listbox engine)
|
|
109
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = useListboxNavigation(context, {
|
|
162
110
|
listRef,
|
|
163
111
|
activeIndex,
|
|
164
112
|
onNavigate: setActiveIndex,
|
|
165
|
-
|
|
166
|
-
|
|
113
|
+
disabledIndices,
|
|
114
|
+
withClick: true,
|
|
167
115
|
focusItemOnOpen: true,
|
|
168
116
|
selectedIndex: value !== undefined ? (optionIndexMap.get(toKey(value)) ?? -1) : -1,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
|
368
|
-
|
|
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
|
-
//
|
|
484
|
-
const textValue =
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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:
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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 {
|
|
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
|
-
|
|
163
|
-
|
|
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.
|
package/components/index.d.ts
CHANGED
|
@@ -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';
|
package/components/index.js
CHANGED
|
@@ -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.
|
|
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"
|