Skip to content

Commit 1dd9352

Browse files
committed
šŸ› Fix the re-focus issue of the DatePicker element when the open state is controlled manually
- Defer the blur call alone to fix the issue #5084 - Fix the bug caused in the commit d07308d Closes #5366
1 parent cd1789c commit 1dd9352

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

ā€Žsrc/index.tsxā€Ž

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -452,27 +452,22 @@ export default class DatePicker extends Component<
452452
}
453453
};
454454

455-
safeFocus = () => {
456-
setTimeout(() => {
457-
this.input?.focus?.({ preventScroll: true });
458-
}, 0);
459-
};
460-
461-
safeBlur = () => {
462-
setTimeout(() => {
463-
this.input?.blur?.();
464-
}, 0);
465-
};
466-
467455
setFocus = () => {
468-
this.safeFocus();
456+
this.input?.focus?.({ preventScroll: true });
469457
};
470458

471459
setBlur = () => {
472-
this.safeBlur();
460+
this.input?.blur?.();
473461
this.cancelFocusInput();
474462
};
475463

464+
deferBlur = () => {
465+
requestAnimationFrame(() => {
466+
console.log("reached");
467+
this.setBlur();
468+
});
469+
};
470+
476471
setOpen = (open: boolean, skipSetBlur: boolean = false): void => {
477472
this.setState(
478473
{
@@ -490,7 +485,7 @@ export default class DatePicker extends Component<
490485
focused: skipSetBlur ? prev.focused : false,
491486
}),
492487
() => {
493-
!skipSetBlur && this.setBlur();
488+
!skipSetBlur && this.deferBlur();
494489

495490
this.setState({ inputValue: null });
496491
},

0 commit comments

Comments
Ā (0)