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

Problems with DayPicker Overlay focus and hiding #926

Closed
zovcharov opened this issue Aug 28, 2019 · 5 comments
Closed

Problems with DayPicker Overlay focus and hiding #926

zovcharov opened this issue Aug 28, 2019 · 5 comments

Comments

@zovcharov
Copy link

zovcharov commented Aug 28, 2019

Hi
When I am using day picker with custom input field, there is one problem.
After focusing on DayPickerOverlay, click on any place on the screen calls only onOverlayFocus handler, not onBlur
That`s why after overlay had been focused once I cant close it by click on some other area on the screen.
What can I do for solving this problem?

Thanks

@gitpash
Copy link

gitpash commented Sep 8, 2019

@zovcharov seems like UX issue, can suggest only workaround like this
you need just createRef on DayPickerInput

ref={inputRef}
dayPickerProps={{
          // other props
          onBlur: () => {
            const activeElement = document.activeElement;
            const overlayContainer = document.getElementsByClassName('DayPickerInput-Overlay');

            if (overlayContainer && !overlayContainer[0].contains(activeElement)) {
              inputRef.current.hideAfterDayClick();
            }
          }
        }}

@Kamilius
Copy link

Kamilius commented Jan 3, 2020

Having same issue.
Downside of workaround proposed by @gitpash is an error inside console:

Screen Shot 2020-01-03 at 8 50 54 AM

@zovcharov
Copy link
Author

zovcharov commented Jan 6, 2020

The problem can also be if you have more than one DatePicker on the page. To avoid this issue you can try to create custom ref for each one of the DatePicker instance.

And also you can try something like this.
Create handler for blur event of your DatePickers.

const handlerOnBlur = function() { setTimeout(() => { const elClicked = document.activeElement; const container = document.getElementsByName(props.name); if (container && !container[0].contains(elClicked)) { dayPickerInputRef.hideDayPicker(); } }, 1); };
And after that you can use DatePicker in container:

<div name={props.name}> <DayPickerInput ref={ref => (dayPickerInputRef = ref)} component={InputComp} dayPickerProps={{ input: InputComp, onBlur: handlerOnBlur, }} value={props.date} keepFocus={false} /> </div>

It`s possible to use this way if you have two or more DatePickers on the page.

@Kamilius
Copy link

Kamilius commented Jan 13, 2020

@zovcharov already using similar solution, but there is an issue with relying on onBlur callback. It is being triggered even when clicking first a nextMonth and then - prevMonth buttons or vise versa. Which causes this dropdown to close each time you're trying to return to previously shown month... :(

Btw, instead of relying on onBlur, fixed those issues via writing a custom hook for clickOutside handling, and having no issues with using multiple datepickers now

@Ahmad-Zahid
Copy link

@Kamilius can you please share your custom hook solution in detail?

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

5 participants