Skip to content

Commit d78d52c

Browse files
Merge pull request #5448 from qburst/issue-5366/fix/refocus-issue-on-controlled-state-management
Fix #5366: 🐛 Fix the re-focus issue of the DatePicker element when the open state is controlled manually
2 parents 4c1fdf4 + 1dd9352 commit d78d52c

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)