fix(web): suggestions stay open when you return to the search quickly
Leaving the field scheduled a close 120 ms later; coming back and typing within that window let the old timer hide the fresh suggestions. Focus now cancels the pending close. This also made the search box test flaky. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
860072e542
commit
823d1eb841
1 file changed
+4
-1
@@ -38,6 +38,7 @@ export function SearchBox({ align = 'center' }: { align?: 'left' | 'center' | 'r
|
|||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [active, setActive] = useState(-1);
|
const [active, setActive] = useState(-1);
|
||||||
const [focused, setFocused] = useState(false);
|
const [focused, setFocused] = useState(false);
|
||||||
|
const blurTimer = useRef<ReturnType<typeof setTimeout>>(undefined);
|
||||||
// Свёрнут в круглую кнопку, пока не нужен: раскрывается по клику, «/» или Ctrl+K.
|
// Свёрнут в круглую кнопку, пока не нужен: раскрывается по клику, «/» или Ctrl+K.
|
||||||
const expanded = focused || q !== '';
|
const expanded = focused || q !== '';
|
||||||
|
|
||||||
@@ -167,12 +168,14 @@ export function SearchBox({ align = 'center' }: { align?: 'left' | 'center' | 'r
|
|||||||
setActive(-1);
|
setActive(-1);
|
||||||
}}
|
}}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
|
// Вернулись в поле раньше, чем сработало закрытие по blur, — подсказки не прячем.
|
||||||
|
clearTimeout(blurTimer.current);
|
||||||
setFocused(true);
|
setFocused(true);
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
setFocused(false);
|
setFocused(false);
|
||||||
setTimeout(close, 120);
|
blurTimer.current = setTimeout(close, 120);
|
||||||
}}
|
}}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user