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(material/list): Selection List element should not be focusable. #18445

Merged
merged 2 commits into from
Feb 11, 2020
Merged

fix(material/list): Selection List element should not be focusable. #18445

merged 2 commits into from
Feb 11, 2020

Conversation

zelliott
Copy link
Collaborator

@zelliott zelliott commented Feb 9, 2020

Currently, the MatSelectionList listbox element itself receives focus on keyboard navigation. This does not follow the Listbox Design Pattern recommendation on the 1.1 ARIA practices (https://www.w3.org/TR/wai-aria-practices-1.1/#Listbox). Per their guidance:

When a single-select listbox receives focus:

  • If none of the options are selected before the listbox receives focus, the first option receives focus. Optionally, the first option may be automatically selected.
  • If an option is selected before the listbox receives focus, focus is set on the selected option.

This PR changes the keyboard interaction of MatSelectionList to follow the guidance above.

I would prefer to use the "roving tabindex" pattern, but given the list options are content-projected, I ran into issues keeping tabindices updated without ExpressionChangedAfter... errors. Thus, I instead essentially followed the implementation used in MatChipList. The listbox element has tabindex="0", and the option elements have tabindex="-1". When the listbox is focused, it redirects focus to the proper option element.

  • When a user attempts to tab out of the selection list, the selection list's tabindex is temporarily set to -1 to allow focus to escape (MatChipList does this as well).
  • When the selection list has no options, it is removed from the tab order.
  • The [tabIndex] input on MatSelectionList is now unused and should eventually be removed.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 9, 2020
@zelliott zelliott marked this pull request as ready for review February 10, 2020 00:13
@zelliott zelliott requested a review from mmalerba February 10, 2020 00:13
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 added Accessibility This issue is related to accessibility (a11y) P2 The issue is important to a large percentage of users, with a workaround pr: lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Feb 10, 2020
@mmalerba mmalerba merged commit fd1593d into angular:master Feb 11, 2020
mmalerba pushed a commit that referenced this pull request Feb 19, 2020
* fix(material/list): Selection list element should not take focus. Focus should move to previously active option.

* Nit changes to a few comments and accept API goldens.
@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 Mar 13, 2020
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 cla: yes PR author has agreed to Google's Contributor License Agreement 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.

4 participants