-
Notifications
You must be signed in to change notification settings - Fork 587
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
Fix suggestions not disappering under some conditions #566
Conversation
@aberezkin Thanks so much for taking the initiative to research and fix this long-standing issue! Changes look good. Let's just make sure that the tests pass, and if you could add a test for this specific bug that would be appreciated! |
@moroshko, I added some tests and now First 3 tests in |
@aberezkin Thanks again for the effort! |
@moroshko Nice, thank you. |
onSuggestionTouchMove = () => { | ||
this.justSelectedSuggestion = false; | ||
this.pressedSuggestion = null; | ||
this.input.focus(); |
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.
Why would you need to refocus the input when onTouchMove
?
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.
Honestly, I don't remember what exactly happened. But probably touchMove did remove focus from input and that caused suggestions to not disappear on touching something other than input.
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, I ended up extending the library myself to allow suggestions to remain on screen while dismissing keyboard on an iOS/Android device. So far I haven't had any complications due to rewriting this method. Would you be open to a PR changing this?
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.
Of course I will be open to any PR but I am just a contributor. I think it's to better ask @moroshko about this. Anyway there are tests to prevent degradation in this area. Also, I think it would be reasonable to add a prop to control behaviour introduced by your PR, something like endureKeyboardDismiss={false|true}
.
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.
Yes exactly!! Cool I will throw something together this week.
In this PR I'm trying to solve the problem I described in this comment. I decided to propose a separate PR because both #417 and #507 seems to be abandoned and stale.
First of all, #380 and #412 are caused by the same code and practically identical, so are solved together in this PR.
There is a thing that nor #417 nor #507 don't take in the account. The thing is that despite we should set
this.justSelectedSuggestion
tofalse
if the mouse leaves the suggestion we need to set it back totrue
if mouse enters back becauseonClick
is fired in that case and the suggestion is selected.The third important thing is that since we are changing
onSuggestionMouseDown
event, we need to create separateonSuggestionTouchStart
event, but because most of the browsers are duplicatingtouchstart
event withmousedown
event we need to preventonSuggestionMouseDown
from firing. Usually, you would doe.preventDefault()
but as @gaearon pointed out in facebook/react#9809 this won't work on latest chrome with current version of React (but will work in future when facebook/react#2043 is merged) so for now we can just check ifthis.justSelectedSuggestion
is alreadytrue
to not setthis.pressedSuggestion
cause it causes some bugs in mobile browsers.npm run build
seems to fail on coverage summary so I also need to write some tests for that (hopefully tests from #417 will suit) but we already can discuss the changes.Fix #412, fix #380
Close #417, close #507