Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable To Set Focus After Date Selection #5134

Open
vinaysharma14 opened this issue Sep 27, 2024 · 0 comments
Open

Unable To Set Focus After Date Selection #5134

vinaysharma14 opened this issue Sep 27, 2024 · 0 comments

Comments

@vinaysharma14
Copy link

Describe the bug
For example, unable to focus the end date text input after start date has been selected.

To Reproduce
Here's a MCVE

const endDateRef = useRef<DatePicker>(null);

<DatePicker
  // ... rest props
  selectsStart
  onSelect={() => endDateRef.current?.setFocus()}
/>

<DatePicker
  // ... rest props
  selectsEnd
  ref={endDateRef}
/>

Expected behavior
DatePicker should accept a prop to NOT reset focus back to the input.

Desktop (please complete the following information):

  • OS: macOS Sonoma
  • Browser: Chrome
  • Version: 129.0.6668.59

Additional context
Its happening because the start date text input is focused asynchronously after start date has been selected and end date text input has been focused.

if (this.props.shouldCloseOnSelect && !this.props.showTimeSelect) {
// Preventing onFocus event to fix issue
// https://github.com/Hacker0x01/react-datepicker/issues/628
this.sendFocusBackToInput();
}

sendFocusBackToInput = (): void => {
// Clear previous timeout if it exists
if (this.preventFocusTimeout) {
this.clearPreventFocusTimeout();
}
// close the popper and refocus the input
// stop the input from auto opening onFocus
// setFocus to the input
this.setState({ preventFocus: true }, (): void => {
this.preventFocusTimeout = setTimeout((): void => {
this.setFocus();
this.setState({ preventFocus: false });
});
});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant