@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
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
@use "./sidebar" as sidebar;
|
|
36
36
|
@use "./step-indicator" as stepindicator;
|
|
37
37
|
@use "./search-input" as searchinput;
|
|
38
|
+
@use "./search-select" as searchselect;
|
|
38
39
|
@use "./step-list" as steplist;
|
|
39
40
|
@use "./table" as table;
|
|
40
41
|
@use "./tabs" as tabs;
|
|
@@ -53,10 +54,11 @@
|
|
|
53
54
|
// gradient-picker renders TextInput internally for its numeric fields.
|
|
54
55
|
// NOTE: a subset build requesting gradient-picker must ALSO request
|
|
55
56
|
// color-picker, popover, select, tooltip, button, and icon-button — the
|
|
56
|
-
// panel composes all of them.
|
|
57
|
-
// input
|
|
58
|
-
//
|
|
59
|
-
|
|
57
|
+
// panel composes all of them. Likewise search-select must also request
|
|
58
|
+
// search-input (its panel embeds one). The dependents mechanism below only
|
|
59
|
+
// covers the input core; extend it to full dependency sets if subset builds
|
|
60
|
+
// become a real workflow (Pager has the same latent gap).
|
|
61
|
+
$-input-dependents: (input, field, text-input, textarea, pager, search-input, search-select, gradient-picker);
|
|
60
62
|
|
|
61
63
|
@function -needs-input($only) {
|
|
62
64
|
@if $only == null {
|
|
@@ -92,6 +94,8 @@ $-input-dependents: (input, field, text-input, textarea, pager, search-input, gr
|
|
|
92
94
|
@if -wants($only, field) { @include field.styles(); }
|
|
93
95
|
@if -wants($only, multi-select) { @include multiselect.styles(); }
|
|
94
96
|
@if -wants($only, select) { @include select.styles(); }
|
|
97
|
+
// search-select embeds a SearchInput, hence its place in $-input-dependents
|
|
98
|
+
@if -wants($only, search-select) { @include searchselect.styles(); }
|
|
95
99
|
@if -needs-input($only) { @include input.styles(); }
|
|
96
100
|
@include icon.styles();
|
|
97
101
|
@if -wants($only, icon-button) { @include iconbutton.styles(); }
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
@use "../system" as sys;
|
|
2
|
+
|
|
3
|
+
/* @tui-tokens
|
|
4
|
+
--tui-search-select-trigger-bg
|
|
5
|
+
--tui-search-select-trigger-fg
|
|
6
|
+
--tui-search-select-trigger-border
|
|
7
|
+
--tui-search-select-trigger-border-focus
|
|
8
|
+
--tui-search-select-trigger-radius
|
|
9
|
+
--tui-search-select-panel-bg
|
|
10
|
+
--tui-search-select-panel-border
|
|
11
|
+
--tui-search-select-panel-shadow
|
|
12
|
+
--tui-search-select-panel-radius
|
|
13
|
+
--tui-search-select-panel-width
|
|
14
|
+
--tui-search-select-option-bg-hover
|
|
15
|
+
--tui-search-select-option-bg-selected
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
@mixin styles() {
|
|
19
|
+
// ==========================================================================
|
|
20
|
+
// SearchSelect
|
|
21
|
+
// ==========================================================================
|
|
22
|
+
//
|
|
23
|
+
// Component API tokens (never defined here, only read via fallback — the
|
|
24
|
+
// fallback chain runs through Select's tokens so context remaps of the
|
|
25
|
+
// select family carry over automatically):
|
|
26
|
+
// --tui-search-select-trigger-bg / -fg / -border / -border-focus / -radius
|
|
27
|
+
// --tui-search-select-panel-bg / -border / -shadow / -radius
|
|
28
|
+
// --tui-search-select-panel-width Panel inline-size (default: reference
|
|
29
|
+
// width via the floating min-width)
|
|
30
|
+
// --tui-search-select-option-bg-hover / -bg-selected
|
|
31
|
+
//
|
|
32
|
+
// ==========================================================================
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Root
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
.#{sys.$prefix}interface .#{sys.$prefix}search-select {
|
|
38
|
+
position: relative;
|
|
39
|
+
display: inline-block;
|
|
40
|
+
width: 100%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Trigger — a select-shaped button
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
.#{sys.$prefix}interface .#{sys.$prefix}search-select__trigger {
|
|
47
|
+
--_bg: var(--#{sys.$prefix}search-select-trigger-bg, var(--#{sys.$prefix}select-trigger-bg, var(--#{sys.$prefix}color-bg-surface)));
|
|
48
|
+
--_fg: var(--#{sys.$prefix}search-select-trigger-fg, var(--#{sys.$prefix}select-trigger-fg, var(--#{sys.$prefix}color-fg)));
|
|
49
|
+
--_border: var(--#{sys.$prefix}search-select-trigger-border, var(--#{sys.$prefix}select-trigger-border, var(--#{sys.$prefix}color-border)));
|
|
50
|
+
--_border-focus: var(--#{sys.$prefix}search-select-trigger-border-focus, var(--#{sys.$prefix}select-trigger-border-focus, var(--#{sys.$prefix}theme-primary-base)));
|
|
51
|
+
--_radius: var(--#{sys.$prefix}search-select-trigger-radius, var(--#{sys.$prefix}select-trigger-radius, var(--#{sys.$prefix}radius-md)));
|
|
52
|
+
|
|
53
|
+
// Reset
|
|
54
|
+
appearance: none;
|
|
55
|
+
margin: 0;
|
|
56
|
+
|
|
57
|
+
// Unified control sizing (height + font ladder)
|
|
58
|
+
@include sys.control-sizing(sys.$prefix);
|
|
59
|
+
|
|
60
|
+
display: inline-flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: space-between;
|
|
63
|
+
gap: var(--#{sys.$prefix}spacing-xs);
|
|
64
|
+
width: 100%;
|
|
65
|
+
padding-inline: var(--#{sys.$prefix}spacing-sm);
|
|
66
|
+
text-align: start;
|
|
67
|
+
|
|
68
|
+
background-color: var(--_bg);
|
|
69
|
+
color: var(--_fg);
|
|
70
|
+
border: var(--#{sys.$prefix}border-width) solid var(--_border);
|
|
71
|
+
border-radius: var(--_radius);
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
transition: border-color var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
|
|
74
|
+
|
|
75
|
+
&:focus-visible {
|
|
76
|
+
border-color: var(--_border-focus);
|
|
77
|
+
outline: var(--#{sys.$prefix}focus-ring-width) solid var(--#{sys.$prefix}focus-ring-color);
|
|
78
|
+
outline-offset: var(--#{sys.$prefix}focus-ring-offset);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&:disabled {
|
|
82
|
+
opacity: var(--#{sys.$prefix}opacity-disabled);
|
|
83
|
+
cursor: not-allowed;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__value {
|
|
88
|
+
flex: 1 1 auto;
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
text-overflow: ellipsis;
|
|
91
|
+
white-space: nowrap;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__placeholder {
|
|
95
|
+
color: var(--#{sys.$prefix}input-fg-placeholder, var(--#{sys.$prefix}color-fg-muted));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__icon {
|
|
99
|
+
flex-shrink: 0;
|
|
100
|
+
color: var(--#{sys.$prefix}color-fg-muted);
|
|
101
|
+
transition: transform var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Open-state rotation — top-level rule (trailing `&` splices the interface
|
|
105
|
+
// prefix into an impossible position; see the CLAUDE.md Sass gotcha)
|
|
106
|
+
.#{sys.$prefix}interface
|
|
107
|
+
.#{sys.$prefix}search-select__trigger[data-state="open"] .#{sys.$prefix}search-select__icon {
|
|
108
|
+
transform: rotate(180deg);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// Panel — dialog holding the search field + listbox
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__panel {
|
|
115
|
+
--_bg: var(--#{sys.$prefix}search-select-panel-bg, var(--#{sys.$prefix}select-content-bg, var(--#{sys.$prefix}color-bg-elevated)));
|
|
116
|
+
--_border: var(--#{sys.$prefix}search-select-panel-border, var(--#{sys.$prefix}select-content-border, var(--#{sys.$prefix}color-border)));
|
|
117
|
+
--_shadow: var(--#{sys.$prefix}search-select-panel-shadow, var(--#{sys.$prefix}select-content-shadow, var(--#{sys.$prefix}shadow-dropdown)));
|
|
118
|
+
--_radius: var(--#{sys.$prefix}search-select-panel-radius, var(--#{sys.$prefix}select-content-radius, var(--#{sys.$prefix}radius-md)));
|
|
119
|
+
|
|
120
|
+
z-index: var(--#{sys.$prefix}layer-top);
|
|
121
|
+
inline-size: var(--#{sys.$prefix}search-select-panel-width, auto);
|
|
122
|
+
|
|
123
|
+
// The floating size middleware caps max-height on THIS element; flex keeps
|
|
124
|
+
// the search field pinned while the listbox scrolls.
|
|
125
|
+
display: flex;
|
|
126
|
+
flex-direction: column;
|
|
127
|
+
pointer-events: auto;
|
|
128
|
+
|
|
129
|
+
background-color: var(--_bg);
|
|
130
|
+
border: var(--#{sys.$prefix}border-width) solid var(--_border);
|
|
131
|
+
border-radius: var(--_radius);
|
|
132
|
+
box-shadow: var(--_shadow);
|
|
133
|
+
|
|
134
|
+
animation: #{sys.$prefix}fadeFromTransparent var(--#{sys.$prefix}motion-duration) var(--#{sys.$prefix}motion-timing);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__search {
|
|
138
|
+
flex-shrink: 0;
|
|
139
|
+
padding: var(--#{sys.$prefix}spacing-xs);
|
|
140
|
+
border-block-end: var(--#{sys.$prefix}border-width) solid var(--#{sys.$prefix}color-border);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__listbox {
|
|
144
|
+
flex: 1 1 auto;
|
|
145
|
+
min-block-size: 0;
|
|
146
|
+
padding: var(--#{sys.$prefix}spacing-xxs);
|
|
147
|
+
overflow-y: auto;
|
|
148
|
+
overscroll-behavior: contain;
|
|
149
|
+
|
|
150
|
+
scrollbar-width: thin;
|
|
151
|
+
scrollbar-color: var(--#{sys.$prefix}color-fg-muted) transparent;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__empty {
|
|
155
|
+
padding: var(--#{sys.$prefix}spacing-sm);
|
|
156
|
+
color: var(--#{sys.$prefix}color-fg-muted);
|
|
157
|
+
font-size: var(--#{sys.$prefix}typography-size-sm);
|
|
158
|
+
text-align: center;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
// Option — mirrors Select's option anatomy
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__option {
|
|
165
|
+
--_option-bg-hover: var(--#{sys.$prefix}search-select-option-bg-hover, var(--#{sys.$prefix}select-option-bg-hover, var(--#{sys.$prefix}color-fill-subtle)));
|
|
166
|
+
--_option-bg-selected: var(--#{sys.$prefix}search-select-option-bg-selected, var(--#{sys.$prefix}select-option-bg-selected, var(--#{sys.$prefix}theme-primary-subtlest)));
|
|
167
|
+
|
|
168
|
+
display: flex;
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: space-between;
|
|
171
|
+
gap: var(--#{sys.$prefix}spacing-xs);
|
|
172
|
+
padding: var(--#{sys.$prefix}spacing-xxs) var(--#{sys.$prefix}spacing-sm);
|
|
173
|
+
border-radius: var(--#{sys.$prefix}radius-sm);
|
|
174
|
+
color: var(--#{sys.$prefix}color-fg);
|
|
175
|
+
font-size: var(--#{sys.$prefix}typography-size-sm);
|
|
176
|
+
cursor: pointer;
|
|
177
|
+
user-select: none;
|
|
178
|
+
|
|
179
|
+
@media (hover: hover) {
|
|
180
|
+
&:hover {
|
|
181
|
+
background-color: var(--_option-bg-hover);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&[data-highlighted] {
|
|
186
|
+
background-color: var(--_option-bg-hover);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
&[aria-selected="true"] {
|
|
190
|
+
background-color: var(--_option-bg-selected);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
&[data-disabled] {
|
|
194
|
+
opacity: var(--#{sys.$prefix}opacity-disabled);
|
|
195
|
+
cursor: not-allowed;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__option-content {
|
|
200
|
+
flex: 1 1 auto;
|
|
201
|
+
overflow: hidden;
|
|
202
|
+
text-overflow: ellipsis;
|
|
203
|
+
white-space: nowrap;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__option-check {
|
|
207
|
+
flex-shrink: 0;
|
|
208
|
+
color: var(--#{sys.$prefix}theme-primary-base);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ---------------------------------------------------------------------------
|
|
212
|
+
// Group / Label
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// A group whose options all filtered out hides entirely — otherwise its
|
|
215
|
+
// heading lingers over nothing (and over the "No results" state).
|
|
216
|
+
:where(.#{sys.$prefix}interface)
|
|
217
|
+
.#{sys.$prefix}search-select__group:not(:has(.#{sys.$prefix}search-select__option)) {
|
|
218
|
+
display: none;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__group + .#{sys.$prefix}search-select__group {
|
|
222
|
+
margin-block-start: var(--#{sys.$prefix}spacing-xxs);
|
|
223
|
+
padding-block-start: var(--#{sys.$prefix}spacing-xxs);
|
|
224
|
+
border-block-start: var(--#{sys.$prefix}border-width) solid var(--#{sys.$prefix}color-border);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
:where(.#{sys.$prefix}interface) .#{sys.$prefix}search-select__label {
|
|
228
|
+
padding: var(--#{sys.$prefix}spacing-xxs) var(--#{sys.$prefix}spacing-sm);
|
|
229
|
+
color: var(--#{sys.$prefix}color-fg-muted);
|
|
230
|
+
font-size: var(--#{sys.$prefix}typography-size-xs);
|
|
231
|
+
font-weight: var(--#{sys.$prefix}typography-weight-medium, 600);
|
|
232
|
+
text-transform: uppercase;
|
|
233
|
+
letter-spacing: 0.05em;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// High-contrast mode: keep highlighted/selected legible
|
|
237
|
+
@media (forced-colors: active) {
|
|
238
|
+
.#{sys.$prefix}interface .#{sys.$prefix}search-select__option[data-highlighted] {
|
|
239
|
+
background-color: Highlight;
|
|
240
|
+
color: HighlightText;
|
|
241
|
+
forced-color-adjust: none;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
package/tui-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
3
|
-
"generated": "2026-08-
|
|
2
|
+
"version": "0.2.10",
|
|
3
|
+
"generated": "2026-08-15T18:31:38.646Z",
|
|
4
4
|
"components": {
|
|
5
5
|
"Accordion": {
|
|
6
6
|
"props": {
|
|
@@ -2561,6 +2561,78 @@
|
|
|
2561
2561
|
"use": null,
|
|
2562
2562
|
"notFor": null
|
|
2563
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
|
+
},
|
|
2564
2636
|
"SegmentedControl": {
|
|
2565
2637
|
"props": {
|
|
2566
2638
|
"value": {
|
|
@@ -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,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;
|