Skip to content

fix(material/chips): provide ability to edit for all screen readers with a click on already focused chip #30983

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adolgachev
Copy link
Contributor

@adolgachev adolgachev commented Apr 29, 2025

Some screen readers have difficulty with allowing users to say double click or enter with voice control, preventing them from being able to edit a chip which currently requires a double click or an enter key event.

Single click conflicts with other behaviors, but allowing a click when the chips has already been focused is a natural way to edit the chip and does not affect other current behaviors.

Fixes b/290806246.

@adolgachev adolgachev added the dev-app preview When applied, previews of the dev-app are deployed to Firebase label Apr 29, 2025
Copy link

github-actions bot commented Apr 29, 2025

Deployed dev-app for c0bd1c1 to: https://ng-dev-previews-comp--pr-angular-components-30983-dev-9kax7hje.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@adolgachev adolgachev changed the title Begin editing on click on focused chip fix(chips): provide ability to edit for all screen readers with a click on already focused chip Apr 29, 2025
@adolgachev adolgachev changed the title fix(chips): provide ability to edit for all screen readers with a click on already focused chip fix(material/chips): provide ability to edit for all screen readers with a click on already focused chip Apr 29, 2025
@adolgachev adolgachev added the requires: TGP This PR requires a passing TGP before merging is allowed label Apr 29, 2025
@adolgachev adolgachev marked this pull request as ready for review May 5, 2025 19:35
@adolgachev adolgachev requested a review from a team as a code owner May 5, 2025 19:35
@adolgachev adolgachev requested review from mmalerba, andrewseguin and crisbeto and removed request for a team May 5, 2025 19:35
@adolgachev adolgachev added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 6, 2025
if (!this._isEditing && !this.disabled) {
// Need a timeout to ensure flag not set while handling the first click.
this._ngZone.runOutsideAngular(() => {
setTimeout(() => (this._alreadyFocused = true), 100);
Copy link
Member

Choose a reason for hiding this comment

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

I think we can do this without the timeout by checking whether the chip is focused on the mousedown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea! That works well and actually handles the long press better as well. Well, I could have argued that a long press to edit is a feature, but I won't now.

Only thing is then the spec needs to have a mousedown as well.

@adolgachev adolgachev added the Accessibility This issue is related to accessibility (a11y) label May 7, 2025
* edit mode on a subsequent click. Otherwise, the chip appears focused when handling the
* first click event.
*/
_alreadyFocused = false;
Copy link
Member

Choose a reason for hiding this comment

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

Should we make this private? Also maybe something more descriptive like _wasFocusedOnLastClick?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make it private. I think name is okay though, as the main point is that it has already been focused via a previous click or tab. I think with the comments and only used internally, that works. Else it would have to be really long.

@@ -135,6 +147,17 @@ export class MatChipRow extends MatChip implements AfterViewInit {
}
}

/** Sets _alreadyFocused (ahead of click) when chip already has focus. */
_handleMouseDown(event: MouseEvent) {
this._alreadyFocused = this._hasFocus();
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth binding this outside the NgZone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@adolgachev adolgachev added action: global presubmit The PR is in need of a google3 global presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility This issue is related to accessibility (a11y) action: global presubmit The PR is in need of a google3 global presubmit area: material/chips dev-app preview When applied, previews of the dev-app are deployed to Firebase requires: TGP This PR requires a passing TGP before merging is allowed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants