Skip to content

Commit c4838be

Browse files
authored
Merge pull request #272 from chrishiguto/fix/date-picker-debounced
fix: debounced search function and filter onchange submodule
2 parents 61d8cd2 + 166bb82 commit c4838be

File tree

2 files changed

+12
-5
lines changed
  • packages/react-material-ui/src/components

2 files changed

+12
-5
lines changed

packages/react-material-ui/src/components/DatePickerField/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@ const DatePickerField = ({
2222
const handleDebouncedSearch =
2323
onDebouncedSearchChange &&
2424
useMemo(
25-
() => debounce(onDebouncedSearchChange, wait),
26-
[props?.value, search],
25+
() =>
26+
debounce(() => {
27+
if (onDebouncedSearchChange) {
28+
onDebouncedSearchChange(value);
29+
}
30+
}, wait),
31+
[wait, value],
2732
);
2833

2934
const handleChange = (value: Date | null, context) => {
3035
setSearch(value);
3136
onChange?.(value, context);
32-
handleDebouncedSearch?.(value);
37+
handleDebouncedSearch?.();
3338
};
3439

3540
useEffect(() => {
3641
// Keep track of the first render to avoid triggering onDebouncedSearchChange
3742
// on the initial render. Only trigger when the 'value' changes.
3843
if (!firstRender.current) {
39-
handleDebouncedSearch?.(value);
44+
handleDebouncedSearch?.();
4045
} else {
4146
firstRender.current = false;
4247
}
@@ -55,7 +60,7 @@ const DatePickerField = ({
5560
field: {
5661
clearable: true,
5762
onClear: () => {
58-
handleDebouncedSearch?.(null);
63+
onDebouncedSearchChange?.(null);
5964
},
6065
},
6166
textField: {

packages/react-material-ui/src/components/submodules/Filter/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ const FilterSubmodule = (props: Props) => {
259259
: typeof value === 'undefined'
260260
? null
261261
: (value as Date),
262+
onChange: (val: Date | null) =>
263+
onFilterChange(id, val, false, reference, referenceValidationFn),
262264
onDebouncedSearchChange: (val: Date | null) =>
263265
onFilterChange(id, val, true, reference, referenceValidationFn),
264266
};

0 commit comments

Comments
 (0)