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

Problem with two datepickers for date range on Safari #1077

Closed
InekeScheffers opened this issue Oct 18, 2017 · 13 comments
Closed

Problem with two datepickers for date range on Safari #1077

InekeScheffers opened this issue Oct 18, 2017 · 13 comments
Labels

Comments

@InekeScheffers
Copy link

react-datepicker-safari
On Safari when you select a date on one of the datepickers and change to the other datepicker too quickly, both open the calendar and the focus on the input fields keeps switching.

@cliener
Copy link

cliener commented Oct 23, 2017

I've seen similar oddities in iOS Safari. Looks like events are firing out of order potentially related to #597
May also be related to #830

@echarso
Copy link

echarso commented Oct 23, 2017

Hi I am facing the same issue here with Safari

@pmacmillan
Copy link
Contributor

pmacmillan commented Oct 26, 2017

The place where the click happens seems to matter.

datepickerissue

If I click past the end of input, everything works fine. If I click in the middle of the input, the issue crops up.

datepickerissue-part2

@pmacmillan
Copy link
Contributor

What I am seeing is: if I have one open and...

  • click after the end of the other input, then handleCalendarClickOutside gets called
  • click within the value of the other input, handleCalendarClickOutside is never called

In both cases, onBlur is called, but in the second instance the value of this.state.open is true and the component uses deferFocusInput to regain focus.

(all within src/datepicker.jsx).

In Chrome and Firefox, handleCalendarClickOutside is always called.

@pmacmillan
Copy link
Contributor

Looks like Safari is event drunk.

safari-events

vs

chrome-events

from: https://www.quirksmode.org/dom/events/tests/blurfocus.html

Basically, if you click within the content of the text input with another input element focused, you get something like:

blur on textarea
focus on text
blur on text
focus on textarea
blur on textarea
focus on text

This would explain the observed behaviour.

I suppose an approach to fix this might be to debounce the focus/blur events, reacting only to the last one... but... yikes.

@pmacmillan
Copy link
Contributor

Interesting: facebook/react#10871 Related?

@pmacmillan
Copy link
Contributor

At issue are the spurious events that safari seems to emit like crazy.

In thinking about this issue, I found this workaround.

As a proof of concept, I created this fiddle to demonstrate the problem and the workaround (see capture from safari below).

ignore-spurious-events

So, I think I'm on to a workaround here and would totally welcome feedback before plodding any further ahead ;)

@pmacmillan
Copy link
Contributor

This gist provides a WIP workaround for the issue in Safari. Supplying it to DatePicker as a custom input seems to resolve the issue:

https://gist.github.com/pmacmillan/5e78836821ac22031567382dadd4a72e

But I'm not terribly happy with it and I don't think it belongs in this library (i.e. it feels like should be fixed either as part of React or as part of an environment compat polyfill).

@cliener
Copy link

cliener commented Nov 16, 2017

The same problem here triggers a crash in Safari iOS however whatever is underlying cause seems to be different. Having stolen @pmacmillan's code, I have a test case that breaks in MacOS Safari only. Need to investigate more to find out what's causing issues in Safari.

@cliener
Copy link

cliener commented Nov 28, 2017

I've put together a fix (in part borrowing @pmacmillan's work) though I'm unsure if it should live inside React or as a separate library. Assuming the latter, it's now available for implementation: https://github.com/cliener/input-fixer
I'm now working on a fork of react-datepicker incorporating this library. Stay tuned!

@cliener
Copy link

cliener commented Nov 30, 2017

My fork is done https://github.com/cliener/react-datepicker
Scoped npm install if anyone's keen https://www.npmjs.com/package/@cliener/react-datepicker

I've fixed the immediate problem of the endless event loop however we're now left with the the originally opened calendar sometimes stays open. Removing outsideClickIgnoreClass={outsideClickIgnoreClass} from line 440 fixes this issue but then leaves the problem of the calendar re-rendering every time the input is clicked.

I've made some attempt at resolving this bug but don't haven't yet found a solution. I'm open to suggestions/contributions on this.

It seems a similar endless loop in iOS has also been fixed with the changes I've made. I'll test this shortly.

Any thoughts about whether I should create a PR at this point?

@cliener
Copy link

cliener commented Dec 1, 2017

PR as above. The code is now in a better state having at least fixed the endless loop. iOS Safari is entirely happy now from my tests.

@stale
Copy link

stale bot commented Aug 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

4 participants