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

Executing onBlur function on months navigation buttons #600

Closed
phlex89 opened this issue Jan 5, 2018 · 18 comments
Closed

Executing onBlur function on months navigation buttons #600

phlex89 opened this issue Jan 5, 2018 · 18 comments
Labels
abandoned The issue or Pull Request is wontfix bug Bug or Bug fixes help wanted Extra attention is needed

Comments

@phlex89
Copy link

phlex89 commented Jan 5, 2018

Jump to relevant #600 (comment)


I want to hide the DayPicker to onBlur but it is triggering also when I click on navigation buttons.

How can I fix this?

@gpbl
Copy link
Owner

gpbl commented Jan 5, 2018

It hides already when the input blurs... please add a codesandbox to reproduce, thanks!

@phlex89
Copy link
Author

phlex89 commented Jan 8, 2018

I don't use DayPickerInput, I just use DayPicker showing and hiding it "manually" so I would like to trigger the "custom hide" function on onBlur but it triggers also if I click on months navigation buttons.

@phlex89 phlex89 changed the title Exectuting onBlur function on months navigation buttons Executing onBlur function on months navigation buttons Jan 8, 2018
@gpbl
Copy link
Owner

gpbl commented Jan 8, 2018

@phlex89 sorry I don't follow :) Which is the element firing the blur event? The DayPicker? Please add a CodeSandbox to reproduce your issue, thanks: https://codesandbox.io/s/XDAE3x0W8

@phlex89
Copy link
Author

phlex89 commented Jan 8, 2018

I just added an onBlur function to DayPicker: https://codesandbox.io/s/93q14zxwl4

You can see the function is triggering also on months navigation buttons.

@gpbl
Copy link
Owner

gpbl commented Jan 8, 2018

Thanks for the follow up. Sadly, the blur event works this way. I suggest you to find another way to hide the calendar that's not relying on the blur event.

@gpbl gpbl closed this as completed Jan 8, 2018
@petergombos
Copy link

I'm having the same problem, onBlur seems to fire when there is no day selected yet and the user is paginating the months. In many form libs this makes the field marked as 'touched' and since it has no value it shows invalid. Any suggestions?

@paulcredmond
Copy link

+1. Same issue as with @petergombos

It's a common approach to use onBlur() to check if the user has entered a date before leaving the field for validation, but this fires when navigating the calendar.

@gpbl gpbl reopened this Mar 17, 2018
@gpbl
Copy link
Owner

gpbl commented Mar 17, 2018

reopened ! i’ll look on it again!

@paulcredmond
Copy link

Hi @gpbl did you get a chance to look at this? Many thanks!

@petergombos
Copy link

@paulcredmond this is a dirty hack I use as a workaround in the meantime
screen shot 2018-03-26 at 14 06 26

@paulcredmond
Copy link

paulcredmond commented Mar 26, 2018

Oh, I see what you did there @petergombos

Thanks, I'll use that.

@gpbl
Copy link
Owner

gpbl commented Mar 26, 2018

@paulcredmond

Hi @gpbl did you get a chance to look at this? Many thanks!

Not yet, sorry!

@gpbl gpbl added good first issue Good for newcomers help wanted Extra attention is needed improvement and removed user support 🚑 labels Mar 26, 2018
@apalanki
Copy link

apalanki commented Mar 29, 2018

A good check to place in onBlur is the source of events

 onBlur = (event) => {
        if (!(event.relatedTarget && event.relatedTarget.classList.contains('DayPicker-Day'))) {
               // The navigation button events are filtered by ^ check
          }
}

@paulcredmond
Copy link

paulcredmond commented Apr 3, 2018

@apalanki Thanks, this works fine for me.

      if (!e.relatedTarget) {
         this.setState({
            firstPass: true // Used for validation.
         });
      }

@gpbl
Copy link
Owner

gpbl commented May 7, 2018

I'd like to look at this again but I'm not sure I understand your problem:

https://codesandbox.io/s/93q14zxwl4

  1. I click the May 2018 header
  2. the wrapper element (.DayPicker-wrapper) get the focus
  3. now I click the arrows to change the month
  4. the wrapper element loses the focus and calls onBlur

What you don't like here is the last step, i.e. you are saying we shouldn't call onBlur here. Am I understanding this right? In which case this behaviour gives you problems?

@gpbl gpbl added needs more info 😔 and removed good first issue Good for newcomers help wanted Extra attention is needed improvement labels May 7, 2018
@nmchaves
Copy link

nmchaves commented Dec 2, 2018

What you don't like here is the last step, i.e. you are saying we shouldn't call onBlur here?

@gpbl Exactly! This last step makes it more difficult to use form validation.

Let's say you wrap the <DayPicker/> inside a form and use a form validation library to enforce that the date field is required. In many cases, it's best to trigger the validation on blur. If the user ever clicks away from the day picker wrapper before selecting a value, it's best to give the user immediate feedback that the field is required.

However, we don't want to trigger the validation when the user interacts with the month pagination. After all, the user is still interacting with the day picker at that point, so it doesn't make sense to display an error.

In other words, it would be better if onBlur only got called when the user interacted with something outside of the day picker.

In the case of a <DayPickerInput/>, it would also be nice if onBlur did not get called when the user interacted with the input element. I haven't actually tested the <DayPickerInput/> blurring though, so it might already behave like this.

@Kamilius
Copy link

Just got a problem with same thing.

@gpbl the main issue here, is that when I'm using DayPicker already reproduced in sandbox above:

  • by clicking Previous month button in DayPicker's header, it calls onBlur for whole DayPicker component. (Intended behavior? How's that?) That means, if I somehow need to know if DayPicker itself triggered onBlur, it's non-reliable, as it'll call blur not only on day select, but on each clicked button each time.
  • Using multiple DayPickers inside same group (ex. entering StartDate/EndDates separately), forces us to rely onBlur to fix issue described here Problems with DayPicker Overlay focus and hiding #926

So issue with onBlur being triggered on not only days inside of a calendar, but each buttons, for me specifically is a blocker, as makes DayPicker non-usable when it comes to using more than one DayPicker on a page

@gpbl gpbl added help wanted Extra attention is needed Priority: Medium PR Welcome Welcome to Pull Request bug Bug or Bug fixes labels Apr 17, 2020
@gpbl gpbl added abandoned The issue or Pull Request is wontfix and removed PR Welcome Welcome to Pull Request labels Feb 10, 2021
@gpbl
Copy link
Owner

gpbl commented Feb 10, 2021

Closing, as that input component is bugged since too long and it will be removed from the next version.

@gpbl gpbl closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned The issue or Pull Request is wontfix bug Bug or Bug fixes help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants