Skip to content
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

Blur input on touch devices when clicking on the rest of the page. #170

Closed
wants to merge 4 commits into from
Closed

Blur input on touch devices when clicking on the rest of the page. #170

wants to merge 4 commits into from

Conversation

andysprout
Copy link
Contributor

@andysprout andysprout commented May 17, 2016

Before this change

On Safari (Mac OS), Chrome (Mac OS and android and Mac OS with touch device emulation):

  • when the user clicks on the <input> element
    • then the <input> element is focused
  • when the user clicks or taps outside the react-autosuggest component
    • then the <input> element loses focus

On Mobile Safari (iOS) and Chrome (iOS):

  • when the user clicks on the <input> element
    • then the <input> element is focused
  • when the user clicks or taps outside the react-autosuggest component
    • then the <input> element does NOT lose focus

The only way to cause it to loose focus was to click on another element that could receive focus or to press the 'minimise' button on the device's keyboard.

After this change

On Safari (Mac OS), Chrome (Mac OS, android and iOS), Mobile Safari (iOS):

  • when the user clicks on the <input> element
    • then the <input> element is focused
  • when the user clicks or taps outside the react-autosuggest component
    • then the <input> element loses focus

This replicates the behaviour of the search box on http://google.com

Also fixed bug where the user tapped or clicked on a suggestion, then dragged outside the component meaning the mouseup or touchend event wasn't triggered on the suggestion, so the justClickedSuggestion flag was not reset.

I tried to create some tests for this, but failed to correctly trigger events on the document.

const oldY = this.touchStart && this.touchStart.clientY || Number.MAX_VALUE;

if (!this.justTouchedInput && !this.justClickedOnSuggestion &&
Math.abs(oldX - clientX) < 20 && Math.abs(oldY - clientY) < 20) {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you explain please what's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal is to blur the input if the user taps on the page, but not blur it if the user scrolls or zooms. So I work out if the first touch object has moved more than 20px in the x or y direction since the touchstart event. Ideally I would bind to the click event, but on ios the click event is not bubbled to the document unless the target has css cursor: pointer http://www.quirksmode.org/blog/archives/2010/10/click_event_del_1.html

@moroshko
Copy link
Owner

@andysprout Thanks a lot for this!
Any chance you could split this PR into smaller PRs, that could be reviewed and merged independently?

@andysprout
Copy link
Contributor Author

I can have a go, while trying to fix the issue that makes ios inconsistent I managed to find and fix two other bugs - I'll try to create separate prs for those bug fixes, but the ios fix will be dependant on them.

@andysprout
Copy link
Contributor Author

Created #175 I'll update this PR if that is merged in.

@@ -46,8 +46,8 @@ function mapToAutowhateverTheme(theme) {
return result;
}

export default class AutosuggestContainer extends Component {
static propTypes = {
export default React.createClass({
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably keep this as a class since the React "eventual goal is for ES6 classes to replace React.createClass completely".

Andrew Stewart and others added 4 commits July 4, 2016 17:01
…ouchUp to reset the justClickedOnSuggestion flag
…ting a very weird bug where mouseup/touchstart/touchend on the page would cause all three of the handlers in the example to be fired three times).

Make logic around detemining a tap vs tap-drag a bit neater.
@nkbt
Copy link

nkbt commented Jul 4, 2016

Rebased and reverted back to ES6 classes

@ndao
Copy link

ndao commented Nov 15, 2016

@moroshko, @nkbt, @andysprout, can somebody please help me with this? I'm having issue and this might fix it.

@matheusml
Copy link

Having the same issue here @andysprout @moroshko

When I'm on iPad, after selecting an option (onSuggestionSelected), the input should trigger a blur, but apparently it's not. So, after selecting an option, the iPad keyboard stays there.

@moroshko
Copy link
Owner

@matheusml What you are describing sounds like a different issue. Have you tried:
focusInputOnSuggestionClick={false}
?

@moroshko
Copy link
Owner

moroshko commented Jun 9, 2017

Closing for no activity.

@ahmetkuslular
Copy link

ahmetkuslular commented Dec 30, 2019

@moroshko focusInputOnSuggestionClick still not working on ios devices. - (ios 12.x)2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants