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

fix(cdk/a11y): correctly detect focus from input label #25232

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jul 6, 2022

In most cases focus moves during mousedown so all of our detection uses mousedown events to track it. It breaks down for the common use case where a label is connected to an input, because there focus moves on the click event instead. This has been a long-standing issue with the FocusMonitor that has caused problems for mat-checkbox, mat-radio-button and mat-slide-toggle.

These changes add special handling for the input + label case that checks if the previous mouse interaction was with a label belonging to the current input receiving focus.

Fixes #25090.

In most cases focus moves during the `mousedown` event so all of our detection uses `mousedown` events to track it. It breaks down for the common use case where a `label` is connected to an `input`, because there focus moves on the `click` event instead. This has been a long-standing issue with the `FocusMonitor` that has caused problems with `mat-checkbox`, `mat-radio-button` and `mat-slide-toggle`.

These changes add special handling for the `input` + `label` case that checks if the previous mouse interaction was with a label belonging to the current `input` receiving focus.

Fixes angular#25090.
* Returns whether an interaction is likely to have come from the user clicking the `label` of
* an `input` or `textarea` in order to focus it.
* @param focusEventTarget Target currently receiving focus.
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

A much simpler alternative I was considering was to listen to click events inside the InputModalityDetector instead and set the modality to mouse again. I decided against it, because it would've meant that modalityDetected would emit two consecutive mouse interactions on any click which can be annoying for consumers. Also this seems very much like a focus issue so it makes more sense to handle it in the FocusMonitor than the InputModalityDetector.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround Accessibility This issue is related to accessibility (a11y) target: patch This PR is targeted for the next patch release labels Jul 6, 2022
@crisbeto crisbeto requested a review from mmalerba July 6, 2022 07:36
@crisbeto crisbeto marked this pull request as ready for review July 6, 2022 07:36
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jul 6, 2022
@crisbeto crisbeto self-assigned this Jul 11, 2022
@crisbeto crisbeto merged commit 089eb6f into angular:main Jul 11, 2022
crisbeto added a commit that referenced this pull request Jul 11, 2022
In most cases focus moves during the `mousedown` event so all of our detection uses `mousedown` events to track it. It breaks down for the common use case where a `label` is connected to an `input`, because there focus moves on the `click` event instead. This has been a long-standing issue with the `FocusMonitor` that has caused problems with `mat-checkbox`, `mat-radio-button` and `mat-slide-toggle`.

These changes add special handling for the `input` + `label` case that checks if the previous mouse interaction was with a label belonging to the current `input` receiving focus.

Fixes #25090.

(cherry picked from commit 089eb6f)
crisbeto added a commit that referenced this pull request Jul 11, 2022
In most cases focus moves during the `mousedown` event so all of our detection uses `mousedown` events to track it. It breaks down for the common use case where a `label` is connected to an `input`, because there focus moves on the `click` event instead. This has been a long-standing issue with the `FocusMonitor` that has caused problems with `mat-checkbox`, `mat-radio-button` and `mat-slide-toggle`.

These changes add special handling for the `input` + `label` case that checks if the previous mouse interaction was with a label belonging to the current `input` receiving focus.

Fixes #25090.

(cherry picked from commit 089eb6f)
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jul 18, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/cdk](https://github.com/angular/components) | dependencies | patch | [`14.0.4` -> `14.0.5`](https://renovatebot.com/diffs/npm/@angular%2fcdk/14.0.4/14.0.5) |
| [@angular/material](https://github.com/angular/components) | dependencies | patch | [`14.0.4` -> `14.0.5`](https://renovatebot.com/diffs/npm/@angular%2fmaterial/14.0.4/14.0.5) |

---

### Release Notes

<details>
<summary>angular/components</summary>

### [`v14.0.5`](https://github.com/angular/components/blob/HEAD/CHANGELOG.md#&#8203;1405-metal-hamster-2022-07-14)

[Compare Source](angular/components@14.0.4...14.0.5)

##### cdk

| Commit | Type | Description |
| -- | -- | -- |
| [9cd5a6ad70](angular/components@9cd5a6a) | fix | **a11y:** correctly detect focus from input label ([#&#8203;25232](angular/components#25232)) |
| [938aa2fa13](angular/components@938aa2f) | fix | **clipboard:** page jumping on iOS ([#&#8203;25221](angular/components#25221)) |

##### material

| Commit | Type | Description |
| -- | -- | -- |
| [f5bdefe6fd](angular/components@f5bdefe) | fix | **checkbox:** broken appearance in some grid layouts ([#&#8203;25197](angular/components#25197)) |
| [25ce8e775c](angular/components@25ce8e7) | fix | **select:** add selected indication in high contrast mode ([#&#8203;25237](angular/components#25237)) |
| [76c0e9c1cd](angular/components@76c0e9c) | fix | **tabs:** ink bar not shown in some cases ([#&#8203;25218](angular/components#25218)) |

##### material-experimental

| Commit | Type | Description |
| -- | -- | -- |
| [a9c7f59240](angular/components@a9c7f59) | fix | **mdc-button:** always treat icon-button content as an icon ([#&#8203;25200](angular/components#25200)) |
| [7101a91ef5](angular/components@7101a91) | fix | **mdc-form-field:** ensure clip-path does not truncate label early ([#&#8203;25264](angular/components#25264)) |
| [84a4e9a742](angular/components@84a4e9a) | fix | **mdc-form-field:** fix notch visual artifact ([#&#8203;25201](angular/components#25201)) |
| [ce7f42b912](angular/components@ce7f42b) | fix | **mdc-form-field:** use a CSS var for the floating label scale ([#&#8203;25178](angular/components#25178)) |
| [c0716784b2](angular/components@c071678) | fix | **mdc-paginator:** allow form-field density to go lower than -4 ([#&#8203;25192](angular/components#25192)) |

#####

| Commit | Type | Description |
| -- | -- | -- |
| [89bc64a329](angular/components@89bc64a) | fix | making the parse format available for native date adapter extension ([#&#8203;25226](angular/components#25226)) |

##### multiple

| Commit | Type | Description |
| -- | -- | -- |
| [68edf42798](angular/components@68edf42) | fix | fix disabled label style ([#&#8203;25181](angular/components#25181)) |

#### Special Thanks

Andrew Seguin, Kai Schönberger, Kristiyan Kostadinov, Miles Malerba, Oliver Kierepka and Paul Gschwendtner

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xMTIuMCIsInVwZGF0ZWRJblZlciI6IjMyLjExNS4wIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1463
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@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 Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Accessibility This issue is related to accessibility (a11y) action: merge The PR is ready for merge by the caretaker P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(material/radio): Focus styling remains applied after mouseup
2 participants