Skip to content

fix(slide-toggle): clicks not landing correctly in some cases on Chrome #18285

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

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

crisbeto
Copy link
Member

Any time the slide toggle host receives focus we forward it immediately to the underlying input element. This bouncing around of focus seems to interrupt click events in some cases on Chrome. These changes make it so that we only forward focus for events originating from the keyboard or programmatically.

Fixes #18269.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jan 25, 2020
@crisbeto crisbeto requested a review from devversion as a code owner January 25, 2020 10:05
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 25, 2020
@crisbeto crisbeto changed the title fix(slide-toggle): clicks on landing correctly in some cases on Chrome fix(slide-toggle): clicks not landing correctly in some cases on Chrome Jan 25, 2020
Any time the slide toggle host receives focus we forward it immediately to the underlying `input` element. This bouncing around of focus seems to interrupt click events in some cases on Chrome. These changes make it so that we only forward focus for events originating from the keyboard or programmatically.

Fixes angular#18269.
@crisbeto crisbeto force-pushed the 18269/slide-toggle-click branch from e52a847 to c454df5 Compare January 25, 2020 10:10
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM. Sounds reasonable to me. The focus redirection might also explain why the focus origin was wrong for the native input in the past IIRC:

// 1. It can prevent clicks from landing in Chrome (see #18269).
// 2. They're already handled by the wrapping `label` element.
if (focusOrigin === 'keyboard' || focusOrigin === 'program') {
this._inputElement.nativeElement.focus();
Copy link
Member

Choose a reason for hiding this comment

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

Related to that, did we consider forwarding the focus origin here? (through focusVia)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't mind changing it if you feel strongly about it. I didn't do it, because there's nothing reacting to different focus origins on the input anyway so it seemed redundant.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it was mostly for sanity. I don't feel strongly about it. Let's just leave it as is.

@devversion devversion added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jan 27, 2020
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn merged commit 99b27e8 into angular:master Jan 29, 2020
yifange pushed a commit to yifange/components that referenced this pull request Jan 30, 2020
…me (angular#18285)

Any time the slide toggle host receives focus we forward it immediately to the underlying `input` element. This bouncing around of focus seems to interrupt click events in some cases on Chrome. These changes make it so that we only forward focus for events originating from the keyboard or programmatically.

Fixes angular#18269.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 31, 2020
This is along the same lines as angular#18285 since the radio button and slide toggle have a very similar setup. Whenever the radio button host receives focus we forward it immediately to the underlying input, but this bouncing around of focus could cause clicks to be interrupted in some cases. These changes make it so that we only move focus if the host was focused by the keyboard or mouse.
mmalerba pushed a commit that referenced this pull request Feb 4, 2020
This is along the same lines as #18285 since the radio button and slide toggle have a very similar setup. Whenever the radio button host receives focus we forward it immediately to the underlying input, but this bouncing around of focus could cause clicks to be interrupted in some cases. These changes make it so that we only move focus if the host was focused by the keyboard or mouse.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mat-slide-toggle fails to toggle upon mouse click when text is selected elsewhere on form
4 participants