-
-
Notifications
You must be signed in to change notification settings - Fork 732
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
Alternate solution for timeout blur #598
Conversation
Thanks @bartpeeters for your PR. I want to try it first, sure we have to remove that timeout thing since it doesn't work. I don't understand why the new |
Codecov Report
@@ Coverage Diff @@
## master #598 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 15 15
Lines 621 620 -1
Branches 133 133
=====================================
- Hits 621 620 -1
Continue to review full report at Codecov.
|
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.
tabIndex on the daypicker (here) makes it so the span is focusable.
This does not make sense to me. The tabIndex
in the DayPicker may fire a blur
event, but when it is focused. Why should the parent span
fire a blur
event? blur
does not bubble 🤔
src/DayPickerInput.js
Outdated
ref={el => (this.daypicker = el)} | ||
onTodayButtonClick={onTodayButtonClick} | ||
{...dayPickerProps} | ||
<span onBlur={this.handleInputBlur}> |
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.
My suspect is that this line does nothing. We should add an unit test to it.
@@ -52,18 +52,6 @@ describe('DayPickerInput', () => { | |||
wrapper.find('input').simulate('blur'); | |||
expect(onBlur).toHaveBeenCalledTimes(1); | |||
}); | |||
it('should focus the input if blur after clicking the overlay', done => { |
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 test must stay here :) Why does your change make it fail?
@gpbl Thanks for the feedback. I implemented another solution, using the onFocus event of the overlay to always make sure the DaypickerInput input field is focused. But do we want this? What if we have a custom overlay that includes an input? Now this input is unusable because it can't be focused. We can check if the nodeName of the focus event target is an input, but I don't really know if that is the way to go. I also replaced the clickInside with the timeout by using a ref on the Overlay and checking if the relatedTarget of blur event is inside the overlay. I'm not sure that this is better than using a timeout. About the bubbling of the onFocus and onBlur on the span which contains the overlay, the React Synthetic onFocus and onBlur events do bubble, unlike the normal blur and focus events. |
@bartpeeters thanks for the updates. I've not checked your changes yet, however I'm proposing a different solution:
if (this.clickedInside) {
- this.blurTimeout = setTimeout(() => this.input.focus(), 0);
+ this.input.focus();
}
- if (this.clickedInside) {
+ if (!isFirefox && this.clickedInside) {
|
@gpbl I like the idea of a new prop The solution you propose has the same effect as these changes except they dont use |
@gpbl how can I help push this forward? would really appreciate being able to set |
… onFocus of the overlay to always make the DaypickerInput focused, but do we wanth this?
input, when false focusing the overlay will let the event through Add onBlur on overlay that hides the overlay when clicked outside overlay ant not on input. Add tests for keepFocus and overlayblur, these are hard because enzyme focus and blur don't work like in a real browser: focusing the overlay will not let actually focus it, body will still be focused, so we check that the input is not focused when keepFocus is false.
docs/src/pages/api/DayPickerInput.js
Outdated
@@ -246,6 +247,16 @@ function MyDayPickerInput(props) { | |||
<p> | |||
The value of the <code>input</code> field. | |||
</p> | |||
<h3> | |||
<Anchor id="keepFocus" /> | |||
keeFocus <code>boolean = true</code> |
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.
keepFocus
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.
Thanks!
Hey guys! How soon can we expect a new version release with the new |
@rdiwelm soon ! I have been pretty busy the last month, hoping to catch up all this weekend 🙏🏽 sorry for the lack of communication. |
I also have a feature depending on this release! |
Hey guys! Sorry to be asking again. Is there any ETA on this? We're kinda blocked too. :/ |
@roginfarrer @rdiwelm I was blocked by this too so we forked this dependency until this change gets merged. I understand that is not always a viable option. |
Published as v7.1.0. |
Awesome! Thanks a lot, guys! :) |
Alternate solution for timeout blur
Follow up from #579 (comment), should replace #525.
Issue:
The fix using a setTimeout onBlur to call this.input.focus() caused new issues: