From 014963d4ff3d9cff001b1100dd2e5964128a445f Mon Sep 17 00:00:00 2001 From: Maxim Date: Wed, 29 Jan 2025 23:56:34 +0100 Subject: [PATCH] fix: keep search field in Select focused --- src/components/Select/Select.stories.tsx | 3 +++ src/components/Select/Select.tsx | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Select/Select.stories.tsx b/src/components/Select/Select.stories.tsx index 7202680..d60d7e5 100644 --- a/src/components/Select/Select.stories.tsx +++ b/src/components/Select/Select.stories.tsx @@ -8,6 +8,9 @@ const commonOptions = [ { label: 'Option 3', value: 'option_3' }, { label: 'Option 4', value: 'option_4' }, { label: 'Option 5', value: 'option_5' }, + { label: 'Option 5', value: 'option_5' }, + { label: 'Option 5', value: 'option_5' }, + { label: 'Option 5', value: 'option_5' }, ]; export default { diff --git a/src/components/Select/Select.tsx b/src/components/Select/Select.tsx index e0a50d2..07cf440 100644 --- a/src/components/Select/Select.tsx +++ b/src/components/Select/Select.tsx @@ -98,9 +98,13 @@ export const BoemlySelect: React.FC = ({ useEffect(() => { if (isOpen && isSearchable && inputRef.current) { - inputRef.current.focus(); + requestAnimationFrame(() => { + if (inputRef.current) { + inputRef.current.focus(); + } + }); } - }, [isOpen, isSearchable]); + }, [filteredOptions.length, isOpen, isSearchable]); // Handle selecting an option const handleOptionSelect = useCallback(