@tangible/ui 0.2.8 → 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.
- 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 +444 -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 +134 -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,9 +1,9 @@
|
|
|
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 { getPortalRootFor } from '../../utils/portal.js';
|
|
6
|
+
import { useOptionRegistry, useOptionRegistration, useListboxIds, useListboxFloating, useListboxNavigation, useListboxBlurGuard, useTriggerPointerDownFix, useFocusTriggerOnOpen, useActiveOptionScroll, optionIdForIndex, createListboxGroupComponents, } from '../../utils/listbox/index.js';
|
|
7
7
|
import { Icon } from '../Icon/index.js';
|
|
8
8
|
import { Chip } from '../Chip/index.js';
|
|
9
9
|
import { MultiSelectActionsContext, MultiSelectStateContext, MultiSelectContentContext, useMultiSelectContext, useMultiSelectContentContext, } from './MultiSelectContext.js';
|
|
@@ -20,11 +20,6 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
20
20
|
const value = (isValueControlled ? controlledValue : uncontrolledValue);
|
|
21
21
|
// Track selected text values for display when closed
|
|
22
22
|
const selectedTextMapRef = useRef(new Map());
|
|
23
|
-
// Option registration
|
|
24
|
-
const optionsRef = useRef(new Map());
|
|
25
|
-
const [registryVersion, setRegistryVersion] = useState(0);
|
|
26
|
-
// Track open state via ref so unregisterOption can check synchronously
|
|
27
|
-
const openRef = useRef(false);
|
|
28
23
|
// Is selected helper
|
|
29
24
|
const isSelected = useCallback((optionValue) => {
|
|
30
25
|
const key = toKey(optionValue);
|
|
@@ -71,6 +66,27 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
71
66
|
}
|
|
72
67
|
onValueChange?.([]);
|
|
73
68
|
}, [isValueControlled, onValueChange]);
|
|
69
|
+
// Controlled/uncontrolled open
|
|
70
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen ?? false);
|
|
71
|
+
const isOpenControlled = controlledOpen !== undefined;
|
|
72
|
+
const open = isOpenControlled ? controlledOpen : uncontrolledOpen;
|
|
73
|
+
const setOpen = useCallback((nextOpen) => {
|
|
74
|
+
if (disabled)
|
|
75
|
+
return;
|
|
76
|
+
if (!isOpenControlled) {
|
|
77
|
+
setUncontrolledOpen(nextOpen);
|
|
78
|
+
}
|
|
79
|
+
onOpenChange?.(nextOpen);
|
|
80
|
+
}, [disabled, isOpenControlled, onOpenChange]);
|
|
81
|
+
// IDs
|
|
82
|
+
const { controlId: triggerId, listboxId } = useListboxIds(triggerIdProp, 'trigger');
|
|
83
|
+
// Refs for list navigation
|
|
84
|
+
const listRef = useRef([]);
|
|
85
|
+
const listContentRef = useRef([]);
|
|
86
|
+
// Active index for navigation
|
|
87
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
88
|
+
// Shared option registry (listbox engine)
|
|
89
|
+
const { optionsRef, registryVersion, registerOption, unregisterOption, orderedOptions, } = useOptionRegistry({ open, listContentRef });
|
|
74
90
|
// Sync selectedTextMap when controlled value changes
|
|
75
91
|
useEffect(() => {
|
|
76
92
|
if (isValueControlled && controlledValue) {
|
|
@@ -92,6 +108,8 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
110
|
}
|
|
111
|
+
// optionsRef is a stable ref from the registry hook
|
|
112
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
113
|
}, [controlledValue, isValueControlled]);
|
|
96
114
|
// Initialize selectedTextMap when options register (handles defaultValue)
|
|
97
115
|
useEffect(() => {
|
|
@@ -104,52 +122,8 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
104
122
|
}
|
|
105
123
|
}
|
|
106
124
|
}
|
|
107
|
-
}, [registryVersion, value]);
|
|
108
|
-
// Controlled/uncontrolled open
|
|
109
|
-
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen ?? false);
|
|
110
|
-
const isOpenControlled = controlledOpen !== undefined;
|
|
111
|
-
const open = isOpenControlled ? controlledOpen : uncontrolledOpen;
|
|
112
|
-
openRef.current = open;
|
|
113
|
-
const setOpen = useCallback((nextOpen) => {
|
|
114
|
-
if (disabled)
|
|
115
|
-
return;
|
|
116
|
-
if (!isOpenControlled) {
|
|
117
|
-
setUncontrolledOpen(nextOpen);
|
|
118
|
-
}
|
|
119
|
-
onOpenChange?.(nextOpen);
|
|
120
|
-
}, [disabled, isOpenControlled, onOpenChange]);
|
|
121
|
-
// IDs
|
|
122
|
-
const baseId = useId();
|
|
123
|
-
const triggerId = triggerIdProp ?? `${baseId}-trigger`;
|
|
124
|
-
const listboxId = `${baseId}-listbox`;
|
|
125
|
-
// Refs for list navigation
|
|
126
|
-
const listRef = useRef([]);
|
|
127
|
-
const listContentRef = useRef([]);
|
|
128
|
-
// Active index for navigation
|
|
129
|
-
const [activeIndex, setActiveIndex] = useState(null);
|
|
130
|
-
// Get ordered options
|
|
131
|
-
const getOrderedOptions = useCallback(() => {
|
|
132
|
-
const options = Array.from(optionsRef.current.values());
|
|
133
|
-
return options.sort((a, b) => {
|
|
134
|
-
if (!a.ref.current || !b.ref.current)
|
|
135
|
-
return 0;
|
|
136
|
-
const position = a.ref.current.compareDocumentPosition(b.ref.current);
|
|
137
|
-
if (position & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
138
|
-
return -1;
|
|
139
|
-
if (position & Node.DOCUMENT_POSITION_PRECEDING)
|
|
140
|
-
return 1;
|
|
141
|
-
return 0;
|
|
142
|
-
});
|
|
143
|
-
}, []);
|
|
144
|
-
// Memoized ordered options - recompute when registry changes
|
|
145
|
-
// getOrderedOptions is intentionally omitted - we only want to recompute when registryVersion changes
|
|
146
|
-
const orderedOptions = useMemo(() => {
|
|
147
|
-
const options = getOrderedOptions();
|
|
148
|
-
// Update typeahead ref synchronously
|
|
149
|
-
listContentRef.current = options.map((opt) => opt.textValue);
|
|
150
|
-
return options;
|
|
151
125
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
152
|
-
}, [registryVersion]);
|
|
126
|
+
}, [registryVersion, value]);
|
|
153
127
|
// Compute disabled indices for keyboard navigation
|
|
154
128
|
// Skip disabled options AND unselected options when max reached
|
|
155
129
|
const disabledIndices = useMemo(() => orderedOptions.reduce((acc, opt, i) => {
|
|
@@ -160,82 +134,28 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
160
134
|
return acc;
|
|
161
135
|
}, []), [orderedOptions, maxReached, isSelected]);
|
|
162
136
|
// Floating UI setup
|
|
163
|
-
const { refs, floatingStyles, context } =
|
|
164
|
-
placement: 'bottom-start',
|
|
137
|
+
const { refs, floatingStyles, context } = useListboxFloating({
|
|
165
138
|
open,
|
|
166
139
|
onOpenChange: setOpen,
|
|
167
|
-
middleware: [
|
|
168
|
-
offset(4),
|
|
169
|
-
flip({ padding: 8 }),
|
|
170
|
-
shift({ padding: 8 }),
|
|
171
|
-
sizeMiddleware({
|
|
172
|
-
apply({ availableHeight, rects, elements }) {
|
|
173
|
-
Object.assign(elements.floating.style, {
|
|
174
|
-
maxHeight: `${Math.min(availableHeight - 16, 300)}px`,
|
|
175
|
-
minWidth: `${rects.reference.width}px`,
|
|
176
|
-
});
|
|
177
|
-
},
|
|
178
|
-
padding: 8,
|
|
179
|
-
}),
|
|
180
|
-
],
|
|
181
|
-
whileElementsMounted: autoUpdate,
|
|
182
140
|
});
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
// This ensures keyboard navigation works immediately
|
|
186
|
-
const click = useClick(context);
|
|
187
|
-
const dismiss = useDismiss(context);
|
|
188
|
-
const role = useRole(context, { role: 'listbox' });
|
|
189
|
-
const listNavigation = useListNavigation(context, {
|
|
141
|
+
// Shared interaction stack (listbox engine)
|
|
142
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = useListboxNavigation(context, {
|
|
190
143
|
listRef,
|
|
191
144
|
activeIndex,
|
|
192
145
|
onNavigate: setActiveIndex,
|
|
193
|
-
loop: true,
|
|
194
|
-
virtual: true,
|
|
195
|
-
focusItemOnOpen: true,
|
|
196
146
|
disabledIndices,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
147
|
+
withClick: true,
|
|
148
|
+
focusItemOnOpen: true,
|
|
149
|
+
typeahead: {
|
|
150
|
+
listContentRef,
|
|
151
|
+
onMatch: (index) => {
|
|
152
|
+
// Only match if the option is selectable
|
|
153
|
+
if (open && !disabledIndices.includes(index)) {
|
|
154
|
+
setActiveIndex(index);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
206
157
|
},
|
|
207
|
-
resetMs: 500,
|
|
208
158
|
});
|
|
209
|
-
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([
|
|
210
|
-
click,
|
|
211
|
-
dismiss,
|
|
212
|
-
role,
|
|
213
|
-
listNavigation,
|
|
214
|
-
typeahead,
|
|
215
|
-
]);
|
|
216
|
-
// Register option
|
|
217
|
-
// Flag: first registerOption call after open clears stale entries.
|
|
218
|
-
const prevOpenForFlush = useRef(open);
|
|
219
|
-
const needsFlushRef = useRef(false);
|
|
220
|
-
if (open && !prevOpenForFlush.current)
|
|
221
|
-
needsFlushRef.current = true;
|
|
222
|
-
prevOpenForFlush.current = open;
|
|
223
|
-
const registerOption = useCallback((option) => {
|
|
224
|
-
if (needsFlushRef.current) {
|
|
225
|
-
optionsRef.current.clear();
|
|
226
|
-
needsFlushRef.current = false;
|
|
227
|
-
}
|
|
228
|
-
optionsRef.current.set(toKey(option.value), option);
|
|
229
|
-
setRegistryVersion((v) => v + 1);
|
|
230
|
-
}, []);
|
|
231
|
-
const unregisterOption = useCallback((optionValue) => {
|
|
232
|
-
// Skip when closing — preserve registry for chip display text.
|
|
233
|
-
// Options re-register on next open (same keys).
|
|
234
|
-
if (!openRef.current)
|
|
235
|
-
return;
|
|
236
|
-
optionsRef.current.delete(toKey(optionValue));
|
|
237
|
-
setRegistryVersion((v) => v + 1);
|
|
238
|
-
}, []);
|
|
239
159
|
// Get selected options for trigger display
|
|
240
160
|
const getSelectedOptions = useCallback(() => {
|
|
241
161
|
return value
|
|
@@ -249,7 +169,8 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
249
169
|
return { value: v, ref: { current: null }, disabled: false, textValue };
|
|
250
170
|
})
|
|
251
171
|
.filter(Boolean);
|
|
252
|
-
|
|
172
|
+
// optionsRef is a stable ref from the registry hook
|
|
173
|
+
}, [value, optionsRef]);
|
|
253
174
|
// Highlighted value for keyboard navigation
|
|
254
175
|
const highlightedValue = activeIndex !== null ? orderedOptions[activeIndex]?.value ?? null : null;
|
|
255
176
|
// Track previous open state to detect open/close transitions
|
|
@@ -274,11 +195,7 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
274
195
|
// Note: Don't reset activeIndex while open - that would jump focus on toggle
|
|
275
196
|
}, [open, orderedOptions, value, max]);
|
|
276
197
|
// Scroll active option into view
|
|
277
|
-
|
|
278
|
-
if (open && activeIndex !== null && listRef.current[activeIndex]) {
|
|
279
|
-
listRef.current[activeIndex]?.scrollIntoView({ block: 'nearest' });
|
|
280
|
-
}
|
|
281
|
-
}, [open, activeIndex]);
|
|
198
|
+
useActiveOptionScroll(open, activeIndex, listRef);
|
|
282
199
|
// ==========================================================================
|
|
283
200
|
// Split Context Values
|
|
284
201
|
// ==========================================================================
|
|
@@ -383,11 +300,7 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
383
300
|
const selectedOptions = getSelectedOptions();
|
|
384
301
|
const hasSelection = selectedOptions.length > 0;
|
|
385
302
|
// Ensure trigger has focus when dropdown opens (Safari doesn't focus buttons on click)
|
|
386
|
-
|
|
387
|
-
if (open && refs.reference.current) {
|
|
388
|
-
refs.reference.current.focus();
|
|
389
|
-
}
|
|
390
|
-
}, [open, refs.reference]);
|
|
303
|
+
useFocusTriggerOnOpen(open, refs.reference);
|
|
391
304
|
// Handle keyboard interactions (Enter/Space for toggle when open)
|
|
392
305
|
// Note: Backspace/Delete handled directly on button element to avoid typeahead interference
|
|
393
306
|
const handleKeyDown = useCallback((e) => {
|
|
@@ -408,23 +321,12 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
408
321
|
}, [open, activeIndex, orderedOptions, isSelected, maxReached, toggleOption]);
|
|
409
322
|
// Close dropdown when focus leaves trigger
|
|
410
323
|
// Uses blur guard pattern: only close if focus moved outside controlled elements
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
setOpen(false);
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
// Check if focus moved to the floating content (clicking an option)
|
|
421
|
-
const floating = refs.floating.current;
|
|
422
|
-
if (floating && relatedTarget && floating.contains(relatedTarget)) {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
// Focus moved somewhere outside our control — close
|
|
426
|
-
setOpen(false);
|
|
427
|
-
}, [open, setOpen, refs.floating]);
|
|
324
|
+
// Shared three-branch focus-loss guard (listbox engine)
|
|
325
|
+
const handleBlur = useListboxBlurGuard({
|
|
326
|
+
open,
|
|
327
|
+
setOpen,
|
|
328
|
+
floatingRef: refs.floating,
|
|
329
|
+
});
|
|
428
330
|
// Handle clear button click
|
|
429
331
|
const handleClearClick = useCallback((e) => {
|
|
430
332
|
e.stopPropagation(); // Prevent triggering the dropdown
|
|
@@ -432,19 +334,8 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
432
334
|
return;
|
|
433
335
|
clearAll();
|
|
434
336
|
}, [disabled, clearAll]);
|
|
435
|
-
// Safari
|
|
436
|
-
|
|
437
|
-
// on the open trigger closes-then-reopens and never visibly toggles. Focus
|
|
438
|
-
// the trigger ourselves and cancel the browser's focus juggling. Mouse/pen
|
|
439
|
-
// only: cancelling pointerdown on touch swallows the compatibility click.
|
|
440
|
-
const handleTriggerPointerDown = useCallback((e) => {
|
|
441
|
-
if (e.pointerType !== 'mouse' && e.pointerType !== 'pen')
|
|
442
|
-
return;
|
|
443
|
-
if (e.button !== 0)
|
|
444
|
-
return;
|
|
445
|
-
e.preventDefault();
|
|
446
|
-
e.currentTarget.focus();
|
|
447
|
-
}, []);
|
|
337
|
+
// Safari focus-on-mousedown fix (listbox engine — see hook doc)
|
|
338
|
+
const handleTriggerPointerDown = useTriggerPointerDownFix();
|
|
448
339
|
// Get Floating UI's reference props
|
|
449
340
|
const floatingProps = getReferenceProps({
|
|
450
341
|
'aria-activedescendant': activeIndex !== null ? `${listboxId}-option-${activeIndex}` : undefined,
|
|
@@ -592,21 +483,17 @@ function MultiSelectOptionComponent({ value: optionValue, disabled = false, text
|
|
|
592
483
|
const { isSelected, toggleOption, listboxId, registerOption, unregisterOption, highlightedValue, getItemProps, maxReached, } = useMultiSelectContext();
|
|
593
484
|
const { listRef, orderedOptions } = useMultiSelectContentContext();
|
|
594
485
|
const ref = useRef(null);
|
|
595
|
-
//
|
|
596
|
-
const textValue =
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
useLayoutEffect(() => {
|
|
607
|
-
registerOption({ value: optionValue, ref, disabled, textValue });
|
|
608
|
-
return () => unregisterOption(optionValue);
|
|
609
|
-
}, [optionValue, disabled, textValue, registerOption, unregisterOption]);
|
|
486
|
+
// Shared registration: textValue derivation, dev warn, layout-effect register
|
|
487
|
+
const textValue = useOptionRegistration({
|
|
488
|
+
value: optionValue,
|
|
489
|
+
disabled,
|
|
490
|
+
textValue: explicitTextValue,
|
|
491
|
+
children,
|
|
492
|
+
componentName: 'MultiSelect.Option',
|
|
493
|
+
elementRef: ref,
|
|
494
|
+
registerOption,
|
|
495
|
+
unregisterOption,
|
|
496
|
+
});
|
|
610
497
|
// Find this option's index in ordered list
|
|
611
498
|
const index = orderedOptions.findIndex((opt) => toKey(opt.value) === toKey(optionValue));
|
|
612
499
|
// Assign ref to listRef for navigation
|
|
@@ -630,7 +517,7 @@ function MultiSelectOptionComponent({ value: optionValue, disabled = false, text
|
|
|
630
517
|
return;
|
|
631
518
|
toggleOption(optionValue, textValue);
|
|
632
519
|
}, [isSelectable, optionValue, textValue, toggleOption]);
|
|
633
|
-
return (_jsxs("div", { ref: ref, id:
|
|
520
|
+
return (_jsxs("div", { ref: ref, id: optionIdForIndex(listboxId, index), role: "option", className: cx('tui-multiselect__option', className), "aria-selected": selected, "aria-disabled": !isSelectable || undefined, "data-highlighted": isHighlighted || undefined, "data-disabled": disabled || undefined, "data-blocked": isBlocked || undefined, ...getItemProps({
|
|
634
521
|
onClick: isSelectable ? handleClick : undefined,
|
|
635
522
|
onPointerDown: handlePointerDown,
|
|
636
523
|
}), children: [_jsx("span", { className: cx('tui-multiselect__checkbox', selected && 'is-checked'), "aria-hidden": "true", children: selected && _jsx(Icon, { name: "system/check", size: "xs" }) }), _jsx("span", { className: "tui-multiselect__option-content", children: children })] }));
|
|
@@ -639,36 +526,12 @@ MultiSelectOptionComponent.displayName = 'MultiSelect.Option';
|
|
|
639
526
|
// =============================================================================
|
|
640
527
|
// MultiSelect.Group
|
|
641
528
|
// =============================================================================
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
if (groupRef.current) {
|
|
649
|
-
const labelEl = groupRef.current.querySelector(`#${CSS.escape(`${groupId}-label`)}`);
|
|
650
|
-
setHasLabel(!!labelEl);
|
|
651
|
-
}
|
|
652
|
-
}, [groupId, children]);
|
|
653
|
-
return (_jsx("div", { ref: groupRef, role: "group", "aria-labelledby": hasLabel ? `${groupId}-label` : undefined, className: cx('tui-multiselect__group', className), children: _jsx(MultiSelectGroupContext.Provider, { value: { groupId }, children: children }) }));
|
|
654
|
-
}
|
|
655
|
-
MultiSelectGroupComponent.displayName = 'MultiSelect.Group';
|
|
656
|
-
const MultiSelectGroupContext = React.createContext(null);
|
|
657
|
-
// =============================================================================
|
|
658
|
-
// MultiSelect.Label
|
|
659
|
-
// =============================================================================
|
|
660
|
-
function MultiSelectLabelComponent({ className, children }) {
|
|
661
|
-
const groupContext = React.useContext(MultiSelectGroupContext);
|
|
662
|
-
const warnedRef = useRef(false);
|
|
663
|
-
useEffect(() => {
|
|
664
|
-
if (isDev() && !groupContext && !warnedRef.current) {
|
|
665
|
-
warnedRef.current = true;
|
|
666
|
-
console.warn('MultiSelect.Label should be used inside MultiSelect.Group for accessibility.');
|
|
667
|
-
}
|
|
668
|
-
}, [groupContext]);
|
|
669
|
-
return (_jsx("div", { id: groupContext ? `${groupContext.groupId}-label` : undefined, className: cx('tui-multiselect__label', className), children: children }));
|
|
670
|
-
}
|
|
671
|
-
MultiSelectLabelComponent.displayName = 'MultiSelect.Label';
|
|
529
|
+
// Shared Group/Label pair from the listbox engine.
|
|
530
|
+
const { Group: MultiSelectGroupComponent, Label: MultiSelectLabelComponent } = createListboxGroupComponents({
|
|
531
|
+
componentName: 'MultiSelect',
|
|
532
|
+
groupClass: 'tui-multiselect__group',
|
|
533
|
+
labelClass: 'tui-multiselect__label',
|
|
534
|
+
});
|
|
672
535
|
export const MultiSelect = MultiSelectRoot;
|
|
673
536
|
MultiSelect.Trigger = MultiSelectTriggerComponent;
|
|
674
537
|
MultiSelect.Content = MultiSelectContentComponent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FloatingContext, 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 { toKey, type OptionValue } from '../../utils/value-key';
|
|
5
5
|
export { toKey, type OptionValue };
|
|
@@ -183,14 +183,11 @@ export type MultiSelectLabelProps = {
|
|
|
183
183
|
children: React.ReactNode;
|
|
184
184
|
};
|
|
185
185
|
/**
|
|
186
|
-
* Registration record for an option
|
|
186
|
+
* Registration record for an option — now defined by the shared listbox
|
|
187
|
+
* engine; re-exported here for back-compat.
|
|
187
188
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
ref: RefObject<HTMLElement | null>;
|
|
191
|
-
disabled: boolean;
|
|
192
|
-
textValue: string;
|
|
193
|
-
};
|
|
189
|
+
import type { RegisteredOption } from '../../utils/listbox';
|
|
190
|
+
export type { RegisteredOption };
|
|
194
191
|
/**
|
|
195
192
|
* Stable context: config, IDs, refs, and stable callbacks.
|
|
196
193
|
* Rarely changes — safe to subscribe without rerender concerns.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type SearchSelectProps, type SearchSelectTriggerProps, type SearchSelectContentProps, type SearchSelectOptionProps } from './types';
|
|
2
|
+
declare function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, inputValue: controlledInputValue, onInputChange, filter, disabled, placeholder, size, id: triggerIdProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, labels: labelsProp, children, }: SearchSelectProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare namespace SearchSelectRoot {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
declare function SearchSelectTriggerComponent({ className, children, onClick: onClickProp, onKeyDown: onKeyDownProp, onPointerDown: onPointerDownProp, ...rest }: SearchSelectTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare namespace SearchSelectTriggerComponent {
|
|
8
|
+
var displayName: string;
|
|
9
|
+
}
|
|
10
|
+
declare function SearchSelectContentComponent({ className, children }: SearchSelectContentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
+
declare namespace SearchSelectContentComponent {
|
|
12
|
+
var displayName: string;
|
|
13
|
+
}
|
|
14
|
+
declare function SearchSelectOptionComponent({ value: optionValue, disabled, textValue: explicitTextValue, className, children, }: SearchSelectOptionProps): import("react/jsx-runtime").JSX.Element | null;
|
|
15
|
+
declare namespace SearchSelectOptionComponent {
|
|
16
|
+
var displayName: string;
|
|
17
|
+
}
|
|
18
|
+
declare const SearchSelectGroupComponent: {
|
|
19
|
+
({ className, children }: import("./types").SearchSelectGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
displayName: string;
|
|
21
|
+
}, SearchSelectLabelComponent: {
|
|
22
|
+
({ className, children }: import("./types").SearchSelectLabelProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
25
|
+
type SearchSelectCompound = typeof SearchSelectRoot & {
|
|
26
|
+
Trigger: typeof SearchSelectTriggerComponent;
|
|
27
|
+
Content: typeof SearchSelectContentComponent;
|
|
28
|
+
Option: typeof SearchSelectOptionComponent;
|
|
29
|
+
Group: typeof SearchSelectGroupComponent;
|
|
30
|
+
Label: typeof SearchSelectLabelComponent;
|
|
31
|
+
};
|
|
32
|
+
declare const SearchSelect: SearchSelectCompound;
|
|
33
|
+
export { SearchSelect, SearchSelectTriggerComponent as SearchSelectTrigger, SearchSelectContentComponent as SearchSelectContent, SearchSelectOptionComponent as SearchSelectOption, SearchSelectGroupComponent as SearchSelectGroup, SearchSelectLabelComponent as SearchSelectLabel, };
|
|
34
|
+
export { useSearchSelect } from './SearchSelectContext';
|