Skip to content

Conversation

@tanmoyopenroot
Copy link

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.

Copy link
Member

@ljharb ljharb left a 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?

const wrapper = shallow(<DayPicker onBlur={onBlurStub} />);
expect(wrapper.prop('onBlur')).to.equal(onBlurStub);
wrapper.prop('onBlur')();
expect(onBlurStub.callCount).to.equal(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(onBlurStub.callCount).to.equal(1);
expect(onBlurStub).to.have.property('callCount', 1);

it('should pass onBlur to <DayPicker />', () => {
const onBlurStub = sinon.stub();
const wrapper = shallow(<DayPicker onBlur={onBlurStub} />);
expect(wrapper.prop('onBlur')).to.equal(onBlurStub);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(wrapper.prop('onBlur')).to.equal(onBlurStub);
expect(wrapper.props()).to.have.property('onBlur', onBlurStub);

@ljharb ljharb added the semver-minor: new stuff Any feature or API addition. label Feb 7, 2020
@tanmoyopenroot
Copy link
Author

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?

Could you please clarify it for me?

@ljharb
Copy link
Member

ljharb commented Feb 8, 2020

Someone who is currently passing onBlur expects it to only be fired from the current components it's passed to; silently and suddenly passing it to new components means their callback will suddenly be invoked more times than they expect, on different components - that makes this a breaking change for them.

@tanmoyopenroot
Copy link
Author

Someone who is currently passing onBlur expects it to only be fired from the current components it's passed to; silently and suddenly passing it to new components means their callback will suddenly be invoked more times than they expect, on different components - that makes this a breaking change for them.

ok, I will fix it.
Do we need to listen to all onblur events within the calendar(like blur event from navigation button, shortcut and day click) or only when it loses focus from the calendar boundary?

onDatesChange({ startDate, endDate });
}

onBlur();
Copy link
Member

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

Copy link
Author

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

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-minor: new stuff Any feature or API addition.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected onBlur behavior for DayPickerRangeController?

2 participants