Skip to content

Commit

Permalink
use setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jsartisan committed Feb 3, 2025
1 parent 7d0cb9b commit 9eba1e3
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/client/packages/design-system/ads/src/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import type { SelectProps } from "./Select.types";
import { Spinner } from "../Spinner";
import { SearchInput } from "../SearchInput";

let intervalId: number;

/*
TODO:
- Lots of warnings are generated from this component. Fix them.
Expand Down Expand Up @@ -58,16 +56,14 @@ function Select(props: SelectProps) {
const handleDropdownVisibleChange = (open: boolean) => {
if (open) {
// this is a hack to get the search input to focus when the dropdown is opened
intervalId = setInterval(() => {
// the reason is, rc-select does not support putting the search input in the dropdown
// and rc-select focus its native input element on dropdown open, but we need to focus the search input
// so we use a timeout to focus the search input after the dropdown is opened
setTimeout(() => {
if (!searchRef.current) return;

searchRef.current?.focus();
}, 100);
}

// clear the interval
if (!open && intervalId) {
clearInterval(intervalId);
}, 200);
}
};

Expand Down

0 comments on commit 9eba1e3

Please sign in to comment.