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

feat(list): Add arrow key a11y support. #2871

Merged
merged 15 commits into from
Jun 6, 2018
Merged

Conversation

williamernest
Copy link
Contributor

fixes: #2850

@williamernest williamernest force-pushed the feat/list/new-component branch 2 times, most recently from 9785d07 to b7d0370 Compare June 4, 2018 21:56
@codecov-io
Copy link

codecov-io commented Jun 4, 2018

Codecov Report

Merging #2871 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2871      +/-   ##
=========================================
+ Coverage   98.25%   98.3%   +0.05%     
=========================================
  Files          98     101       +3     
  Lines        4231    4359     +128     
  Branches      540     563      +23     
=========================================
+ Hits         4157    4285     +128     
  Misses         74      74
Impacted Files Coverage Δ
packages/mdc-list/constants.js 100% <100%> (ø)
packages/mdc-list/index.js 100% <100%> (ø)
packages/mdc-list/foundation.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3de2d40...6d80333. Read the comment docs.

Copy link
Contributor

@moog16 moog16 left a comment

Choose a reason for hiding this comment

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

  1. missing tabindex='0' on this line https://github.com/material-components/material-components-web/pull/2871/files#diff-c054c03788286df0d6a7acf64dcd3945R966

  2. All demos are not orientation=vertical, which is more intuitive to me. Do you agree they should be vertical too?

  3. The hero list has 2 meta data icons. I don't think that is in the spec/not recommended (I'm just guessing).

* @private
*/
preventDefaultEvent_(evt) {
const tagName = ('' + evt.target.tagName).toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

you could do

`${evt.target.tagName}`.toLowerCase()

}

focusFirstElement() {
this.adapter_.focusItemAtIndex(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need a check here to make sure there this.adapter_.getListItemCount() > 0 ?

* @private
*/
getListItem_(target) {
while (!target.classList.contains('mdc-list-item')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think 'mdc-list-item' should be in strings

import {strings} from './constants';

/**
* @extends MDCComponent<!MDCistFoundation>
Copy link
Contributor

Choose a reason for hiding this comment

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

MDCistFoundation => MDCListFoundation

const direction = this.root_.getAttribute(strings.ARIA_ORIENTATION);
this.vertical = direction === strings.ARIA_ORIENTATION_VERTICAL;

// List items need to have at least tabindex=-1 to be focusable.
Copy link
Contributor

Choose a reason for hiding this comment

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

you mean tabindex=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, tabindex=-1. li elements cannot be focused unless they have a tabIndex value. If it's 0, then they're in the tab order. If it's -1, they're not in the tab order, but they are focusable.


As the user navigates through the list, any `button` or `a` elements within the list will receive `tabindex="-1"`
when the list item is not focused. When the list item receives focus, the child `button` and `a` elements will
receive `tabIndex="0"`. This allows for the user to tab through a list items elements and then tab to the
Copy link
Contributor

Choose a reason for hiding this comment

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

through list item elements and...

--- | ---
`ArrowUp` | When the list is in a vertical orientation, it will cause the previous list item to receive focus.
`ArrowDown` | When the list is in a vertical orientation, it will cause the next list item to receive focus.
`ArrowLeft` | When the list is in a horizontal orientation, it will cause the previous list item to receive focus.
Copy link
Contributor

Choose a reason for hiding this comment

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

When the list is in a horizontal orientation (default), ...

`setWrapFocus(value: Boolean) => void` | Sets the list to allow the up arrow on the first element to focus the last element of the list and vice versa.
`setVerticalOrientation(value: Boolean) => void` | Sets the list to an orientation causing the keys used for navigation to change. `true` results in the Up/Down arrow keys being used. `false` results in the Left/Right arrow keys being used.
`handleFocusIn(evt: Event) => void` | Handles the changing of `tabindex` to `0` for all `button` and `a` elements when a list item receives focus.
`handleFocusOut(evt: Event) => void` | Handles the changing of `tabindex` to `-1` for all `button` and `a` elements when a list item receives focus.
Copy link
Contributor

Choose a reason for hiding this comment

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

when a list item loses focus (blur)?

@patbou02
Copy link

I am investigating a bug where pressing the up/down keys while a list is expanded will make the selected list item skip an element of the list. Is anyone familiar with this? Thank you in advance.

@RebeccaStankus
Copy link

RebeccaStankus commented Oct 16, 2020

@patbou02 We came across this same issue with the arrow keys skipping every other element in our list. We found that the MDC drawer and MDC list are both trying to control the arrow key functions, so we removed the MDCList instantiation from our JavaScript code and the arrow keys work with our list as expected now. Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mdc-list should support up/down keyboard navigation
5 participants