Skip to content

Commit f1e6dd4

Browse files
authored
on filtered children change cb (#2725)
* on filtered children change cb * removed the onFilterChange prop
1 parent f1e5557 commit f1e6dd4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/components/picker/helpers/usePickerSearch.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ const usePickerSearch = (props: UsePickerSearchProps) => {
99
const {showSearch, onSearchChange, children, getItemLabel} = props;
1010
const [searchValue, setSearchValue] = useState('');
1111

12-
const _onSearchChange = useCallback((searchValue: string) => {
13-
setSearchValue(searchValue);
14-
onSearchChange?.(searchValue);
15-
},
16-
[onSearchChange]);
17-
1812
const filteredChildren = useMemo(() => {
1913
if (showSearch && !_.isEmpty(searchValue)) {
2014
// @ts-expect-error need to fix children type
@@ -25,9 +19,16 @@ const usePickerSearch = (props: UsePickerSearchProps) => {
2519
return !shouldFilterOut(searchValue, itemLabel);
2620
});
2721
}
22+
2823
return children;
2924
}, [showSearch, searchValue, children]);
3025

26+
const _onSearchChange = useCallback((searchValue: string) => {
27+
setSearchValue(searchValue);
28+
onSearchChange?.(searchValue, filteredChildren);
29+
},
30+
[onSearchChange, filteredChildren]);
31+
3132
return {setSearchValue, onSearchChange: _onSearchChange, filteredChildren};
3233
};
3334

src/components/picker/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
140140
/**
141141
* callback for picker modal search input text change (only when passing showSearch)
142142
*/
143-
onSearchChange?: (searchValue: string) => void;
143+
onSearchChange?: (searchValue: string, filteredChildren?: ReactNode | undefined) => void;
144144
/**
145145
* Render custom search input (only when passing showSearch)
146146
*/

0 commit comments

Comments
 (0)