Skip to content

fix(material/sidenav): fix tabindex issue on side mode #30979

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

DBowen33
Copy link
Contributor

@DBowen33 DBowen33 commented Apr 29, 2025

remove tabindex=-1 from mat-drawer when in mode="side" so that the mat-drawer container it is not focusable by mobile screen readers such as TalkBack

Before Screencast: https://screencast.googleplex.com/cast/NTYzNjAxNjE0Nzc5MTg3MnwzOGVlNmNmZC1jYQ
After Screencast: https://screencast.googleplex.com/cast/NDg5NzA2MTg1NzEzMjU0NHxjZTcyZGY5MS04OA

fixes b/286459024

remove tabindex=-1 from mat-drawer when in mode="side" so mobile
screen readers like TalkBack does not focus on the container

fixes b/286459024
@andrewseguin andrewseguin added the dev-app preview When applied, previews of the dev-app are deployed to Firebase label Apr 30, 2025
Copy link

Deployed dev-app for a1c6329 to: https://ng-dev-previews-comp--pr-angular-components-30979-dev-a2aqsdxi.web.app

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

@DBowen33 DBowen33 marked this pull request as ready for review April 30, 2025 17:10
@DBowen33 DBowen33 requested a review from a team as a code owner April 30, 2025 17:10
@DBowen33 DBowen33 requested review from adolgachev and crisbeto and removed request for a team April 30, 2025 17:10
@@ -165,7 +165,7 @@ export class MatDrawerContent extends CdkScrollable implements AfterContentInit
// this was also done by the animations module which some internal tests seem to depend on.
// Simulate it by toggling the `hidden` attribute instead.
'[style.visibility]': '(!_container && !opened) ? "hidden" : null',
'tabIndex': '-1',
'[attr.tabindex]': 'mode === "side" ? null : "-1"',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: please move up to go after '[attr.align]'.

@adolgachev adolgachev added the requires: TGP This PR requires a passing TGP before merging is allowed label May 1, 2025
@@ -165,7 +165,7 @@ export class MatDrawerContent extends CdkScrollable implements AfterContentInit
// this was also done by the animations module which some internal tests seem to depend on.
// Simulate it by toggling the `hidden` attribute instead.
'[style.visibility]': '(!_container && !opened) ? "hidden" : null',
'tabIndex': '-1',
'[attr.tabindex]': 'mode === "side" ? null : "-1"',
Copy link
Member

@crisbeto crisbeto May 2, 2025

Choose a reason for hiding this comment

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

I think that it needs to remain focusable, because this logic falls back to it if it can't find any focusable elements inside the content. Maybe it's more appropriate to clear the tabindex when the sidenav is closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clearing the tabindex when the sidenav is closed will still cause TB focus to focus on the container when it's open due to the tabindex="-1" still being present.

I was thinking that since mode="side", the autofocus value will always be dialog according to this logic. Since the value is dialog, it won't reach the first-tabbable case when it's side mode.

Copy link
Member

Choose a reason for hiding this comment

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

I meant that you can do '[attr.tabindex]': 'isOpen ? -1 : null' which would prevent it from receiving focus. Another option can be to mark it as inert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/sidenav 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.

4 participants