Skip to content

Commit

Permalink
fix: keep search field in Select focused
Browse files Browse the repository at this point in the history
  • Loading branch information
maximgrs committed Jan 30, 2025
1 parent c63e84a commit 014963d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ export const BoemlySelect: React.FC<BoemlySelectProps> = ({

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(
Expand Down

0 comments on commit 014963d

Please sign in to comment.