Skip to content

Commit

Permalink
chore: temp commit with timeouts will be squashed
Browse files Browse the repository at this point in the history
  • Loading branch information
edleeks87 committed Sep 19, 2024
1 parent 47189ec commit 42f5872
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 9 deletions.
26 changes: 23 additions & 3 deletions src/components/date/date.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(
);
const isInitialValue = useRef(true);
const pickerTabGuardId = useRef(guid());
const timerRef = useRef<NodeJS.Timeout | null>(null);

const computeInvalidRawValue = (inputValue: string) =>
allowEmptyValue && !inputValue.length ? inputValue : null;
Expand Down Expand Up @@ -293,7 +294,13 @@ export const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(
isBlurBlocked.current = false;

if (!open && !alreadyFocused.current) {
setOpen(true);
/* istanbul ignore if */
if (timerRef.current) {
clearTimeout(timerRef.current);
}
timerRef.current = setTimeout(() => {
setOpen(true);
}, 0);
} else {
alreadyFocused.current = false;
}
Expand Down Expand Up @@ -351,9 +358,22 @@ export const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(

if (type !== "text") {
alreadyFocused.current = true;
setOpen((prev) => !prev);

/* istanbul ignore if */
if (timerRef.current) {
clearTimeout(timerRef.current);
}
timerRef.current = setTimeout(() => {
setOpen((prev) => !prev);
}, 0);
} else if (!open) {
setOpen(true);
/* istanbul ignore if */
if (timerRef.current) {
clearTimeout(timerRef.current);
}
timerRef.current = setTimeout(() => {
setOpen(true);
}, 0);
}
};

Expand Down
Loading

0 comments on commit 42f5872

Please sign in to comment.