-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(Daypicker): add blur handler to capture all blur events #1924
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
base: master
Are you sure you want to change the base?
fix(Daypicker): add blur handler to capture all blur events #1924
Conversation
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the onBlur prop not just apply to the keyboard picker, but also to the DayPicker. Do you think the consumer would want to know which one is triggering it? Do you think it could be a breaking change for someone who's already passing onBlur?
test/components/DayPicker_spec.jsx
Outdated
| const wrapper = shallow(<DayPicker onBlur={onBlurStub} />); | ||
| expect(wrapper.prop('onBlur')).to.equal(onBlurStub); | ||
| wrapper.prop('onBlur')(); | ||
| expect(onBlurStub.callCount).to.equal(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expect(onBlurStub.callCount).to.equal(1); | |
| expect(onBlurStub).to.have.property('callCount', 1); |
test/components/DayPicker_spec.jsx
Outdated
| it('should pass onBlur to <DayPicker />', () => { | ||
| const onBlurStub = sinon.stub(); | ||
| const wrapper = shallow(<DayPicker onBlur={onBlurStub} />); | ||
| expect(wrapper.prop('onBlur')).to.equal(onBlurStub); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expect(wrapper.prop('onBlur')).to.equal(onBlurStub); | |
| expect(wrapper.props()).to.have.property('onBlur', onBlurStub); |
Could you please clarify it for me? |
|
Someone who is currently passing |
ok, I will fix it. |
| onDatesChange({ startDate, endDate }); | ||
| } | ||
|
|
||
| onBlur(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing this call is a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But blur event from CalendarDay.jsx is being captured but this(<div onBlur={this.onBlur}>) in DayPickerRangeController.jsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason for onBlur call inside onDayClick function in DayPickerRangeController is because of this.
We can pass custom renderCalendarDay which might not trigger blur event and on day click may unnecessary call onBlur if placed inside of onDayClick
PR checklist
Overview of change:
Ordinarily, the focus and blur events in the DOM dot not bubble. React will bubble these events through its event model. So we can listen for blur events at the root of a component and react to these events fired on its child nodes.