@lotics/ui 2.3.0 → 2.3.1
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/package.json +1 -1
- package/src/combobox.tsx +21 -0
package/package.json
CHANGED
package/src/combobox.tsx
CHANGED
|
@@ -132,6 +132,13 @@ export function Combobox<T extends string = string, D = unknown>(props: Combobox
|
|
|
132
132
|
const triggerRef = useRef<View>(null);
|
|
133
133
|
const inputRef = useRef<RNTextInput>(null);
|
|
134
134
|
const scrollRef = useRef<ScrollView>(null);
|
|
135
|
+
// Options are focusable (RN-Web Pressable), so a mouse-press on one blurs the
|
|
136
|
+
// input; commit then refocuses it to keep the textbox focus (aria pattern),
|
|
137
|
+
// which would re-fire onFocus and reopen the popover. This one-shot flag lets
|
|
138
|
+
// that programmatic refocus pass without reopening — set on a single-select
|
|
139
|
+
// commit, consumed by the next onFocus, and cleared on blur (the keyboard
|
|
140
|
+
// path never blurs, so the refocus is a no-op and onFocus never fires).
|
|
141
|
+
const suppressFocusOpenRef = useRef(false);
|
|
135
142
|
const baseId = useId();
|
|
136
143
|
const listboxId = `${baseId}-listbox`;
|
|
137
144
|
const optionId = (i: number) => `${baseId}-option-${i}`;
|
|
@@ -188,6 +195,9 @@ export function Combobox<T extends string = string, D = unknown>(props: Combobox
|
|
|
188
195
|
setQuery("");
|
|
189
196
|
}
|
|
190
197
|
setOpen(false);
|
|
198
|
+
// Single-select: the refocus below must not reopen the just-closed menu.
|
|
199
|
+
// Multi-select keeps the menu open to add more, so it isn't suppressed.
|
|
200
|
+
if (!multi) suppressFocusOpenRef.current = true;
|
|
191
201
|
inputRef.current?.focus();
|
|
192
202
|
},
|
|
193
203
|
[onValueChange, isServer, debouncedSearch, onSearchChange, multi, reflectSelection],
|
|
@@ -278,8 +288,19 @@ export function Combobox<T extends string = string, D = unknown>(props: Combobox
|
|
|
278
288
|
onClear={onClear}
|
|
279
289
|
onChangeText={handleChangeText}
|
|
280
290
|
onFocus={() => {
|
|
291
|
+
// A programmatic refocus right after a single-select commit must not
|
|
292
|
+
// reopen the menu; consume the one-shot flag instead of opening.
|
|
293
|
+
if (suppressFocusOpenRef.current) {
|
|
294
|
+
suppressFocusOpenRef.current = false;
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
281
297
|
if (!disabled) setOpen(true);
|
|
282
298
|
}}
|
|
299
|
+
onBlur={() => {
|
|
300
|
+
// Clear a flag the keyboard path left set (its refocus was a no-op,
|
|
301
|
+
// so onFocus never consumed it) — the next real focus opens normally.
|
|
302
|
+
suppressFocusOpenRef.current = false;
|
|
303
|
+
}}
|
|
283
304
|
onKeyPress={handleKeyPress}
|
|
284
305
|
placeholder={chips.length > 0 ? undefined : placeholder}
|
|
285
306
|
placeholderTextColor={colors.zinc["400"]}
|