Skip to content

Commit 3dc7360

Browse files
author
Zabilsya
committed
[DOP-21974] add search to ManagedSelect
1 parent a1b48f2 commit 3dc7360

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './useSearch';
2+
export * from './types';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** Interface as Props for hook "useSearch" */
2+
export interface UseSearchProps {
3+
/** Callback on change search input value in Select */
4+
onSearch?: (value: string) => void;
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useDebouncedState } from '@shared/hooks';
2+
3+
import { SEARCH_VALUE_CHANGE_DELAY, SEARCH_VALUE_DEFAULT } from '../../constants';
4+
5+
import { UseSearchProps } from './types';
6+
7+
/** Hook for handling search value in Select */
8+
export const useSearch = ({ onSearch = () => undefined }: UseSearchProps) => {
9+
const {
10+
value: searchValue,
11+
setValue: setSearchValue,
12+
setDebouncedValue: setDebouncedSearchValue,
13+
} = useDebouncedState(SEARCH_VALUE_DEFAULT, SEARCH_VALUE_CHANGE_DELAY);
14+
15+
const handleSearch = (value: string) => {
16+
setDebouncedSearchValue(value);
17+
onSearch(value);
18+
};
19+
20+
return { searchValue, handleSearch, setSearchValue };
21+
};

0 commit comments

Comments
 (0)