inputProps.onBlur not working on mobile
See original GitHub issue- Try out the homepage or codepen examples on mobile (iOS or Android). No issue on desktop browsers.
- Steps to reproduce:
- Select the component, type a character to open the dropdown suggestion list.
- Select any item in the dropdown; e.g. scroll the list if possible.
- Tap elsewhere on the page (e.g. another dropdown).
- Observe that the original component doesn’t “close” (dropdown still open).
- Expected behavior: The dropdown should have closed (and
inputProps.onBlur
event fired) when another component is selected.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
React material UI Select box onBlur event not working
Material UI's Select component doesn't have onBlur prop. Try onClose instead. https://material-ui.com/api/select/#props.
Read more >react hook form onblur not working - You.com | The AI Search ...
You're missing to spread the InputProps , so basically you're overwriting all the default properties of your InputProps . The function signature of...
Read more >onBlur not working on Mobile Devices - SAP Community
I've created an ITS application and generated the html code for the screen. I've added javascript code that triggers the onBlur event upon...
Read more >Initializing focus state in React: you might be doing it wrong
function Input(props) { const [hasFocus, setFocus] = useState(false); ... In terms of conditional rendering, you can hide or show elements, but not mount...
Read more >react-phone-number-input - npm
Start using react-phone-number-input in your project by running `npm i react-phone-number-input`. There are 284 other projects in the npm ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey all,
The issue is that justSelectedSuggestion is set to true while you scroll and then blocks the .blur() in the onBlur function when you try and blur it afterwards. The displaying of the suggestions is not intrinsically bound to whether the suggestions are focused at the code level. So if justSelectedSuggestion is true then it can’t blur.
On mousedown sets justSelectedSuggestion to true even if you’re just scrolling. But it doesn’t properly unset.
This blocking with mousedown and not releasing is also linked to https://github.com/moroshko/react-autosuggest/issues/412
For this specific scroll event, a fix is to do this:
Look for these handlers
And add this underneath
onTouchMove: _this3.onTouchMove,
Yours might look a little different as I’m just working off the dist code.
Now add this function below the this.onSuggestionMouseDown function
This means that moving your finger while touching will allow focus again.
However to fully fix this blur() blocking it might need some heavy changes or to catch other cases like this.
I don’t want to assume, since I haven’t been able to understand the focusing and blurring side of the code. But could aria-activedescendant be used to keep the input focused instead of justSelectedSuggestion? You can see that if you select a suggestion it unfocuses the input and then refocuses it just a moment after. This can be seen in the codepen examples by applying a colored border when focused. I know aria-activedescendant is already on it, but it doesn’t seem to be working as intended.
@moroshko Hi, can you please explain why these lines are required?
Looks like they are causing the issue and it’s not iOS related.
You can reproduce it on desktop:
Suggestion list will remain on the screen and can be removed only by clicking at any suggestion because
this.justSelectedSuggestion
is setfalse
only inonSuggestionClick
event handler by these lines:UPD: Also looks like it’s identical to #412