Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Select Accessibility #15973

Closed
2 tasks done
austinChappell opened this issue May 31, 2019 · 10 comments · Fixed by #16294
Closed
2 tasks done

Select Accessibility #15973

austinChappell opened this issue May 31, 2019 · 10 comments · Fixed by #16294
Labels
accessibility a11y component: select This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. priority: important This change can make a difference

Comments

@austinChappell
Copy link

austinChappell commented May 31, 2019

The Select component is no longer accessible as of v4.0 if the Select input does not have a selected option.

  • This is not a v3.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

If rendering a Select component that does not have a selected value, the options should be accessible via the keyboard

Current Behavior 😯

The options are only available if there is a selection already made. (Note: This bug does not occur in MUI v3.x)

Steps to Reproduce 🕹

Link:

  1. sandbox

Context 🔦

Your Environment 🌎

Tech Version
Material-UI v4.0.1
React v16.8.6
Browser
TypeScript
etc.
@eps1lon eps1lon added accessibility a11y component: select This is the name of the generic UI component, not the React module! labels May 31, 2019
@oliviertassinari
Copy link
Member

oliviertassinari commented May 31, 2019

@austinChappell You are not supposed to provide value outside of the options available. However, I believe we can solve the problem like this:

diff --git a/packages/material-ui/src/ListItem/ListItem.js b/packages/material-ui/src/ListItem/ListItem.js
index ef02c38f1..a43bcd215 100644
--- a/packages/material-ui/src/ListItem/ListItem.js
+++ b/packages/material-ui/src/ListItem/ListItem.js
@@ -91,7 +91,7 @@ const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : Reac
 const ListItem = React.forwardRef(function ListItem(props, ref) {
   const {
     alignItems = 'center',
-    autoFocus,
+    autoFocus = false,
     button = false,
     children: childrenProp,
     classes,
diff --git a/packages/material-ui/src/MenuList/MenuList.js b/packages/material-ui/src/MenuList/MenuList.js
index 8226da2fe..c7008613f 100644
--- a/packages/material-ui/src/MenuList/MenuList.js
+++ b/packages/material-ui/src/MenuList/MenuList.js
@@ -44,7 +44,11 @@ function textCriteriaMatches(nextFocus, textCriteria) {

 function moveFocus(list, currentFocus, disableListWrap, traversalFunction, textCriteria) {
   let wrappedOnce = false;
-  let nextFocus = traversalFunction(list, currentFocus, currentFocus ? disableListWrap : false);
+  let nextFocus = traversalFunction(
+    list,
+    currentFocus,
+    currentFocus && currentFocus !== list ? disableListWrap : false,
+  );

   while (nextFocus) {
     // Prevent infinite loop.
@@ -76,7 +80,14 @@ function moveFocus(list, currentFocus, disableListWrap, traversalFunction, textC
 const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;

 const MenuList = React.forwardRef(function MenuList(props, ref) {
-  const { actions, autoFocus, className, onKeyDown, disableListWrap = false, ...other } = props;
+  const {
+    actions,
+    autoFocus = false,
+    className,
+    disableListWrap = false,
+    onKeyDown,
+    ...other
+  } = props;
   const listRef = React.useRef(null);
   const textCriteriaRef = React.useRef({
     keys: [],
@@ -116,10 +127,7 @@ const MenuList = React.forwardRef(function MenuList(props, ref) {
     const key = event.key;
     const currentFocus = ownerDocument(list).activeElement;

-    if (
-      (key === 'ArrowUp' || key === 'ArrowDown') &&
-      (!currentFocus || (currentFocus && !list.contains(currentFocus)))
-    ) {
+    if ((key === 'ArrowUp' || key === 'ArrowDown') && !list.contains(currentFocus)) {
       moveFocus(list, null, disableListWrap, nextItem);
     } else if (key === 'ArrowDown') {
       event.preventDefault();
diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js
index 812aa8ae0..7388707cb 100644
--- a/packages/material-ui/src/Select/SelectInput.js
+++ b/packages/material-ui/src/Select/SelectInput.js
@@ -172,7 +172,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
   delete other['aria-invalid'];

   let display;
-  let displaySingle = '';
+  let displaySingle;
   const displayMultiple = [];
   let computeDisplay = false;

@ryancogswell Could you confirm I'm on the right track?
@austinChappell Do you want to submit a pull request?

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label May 31, 2019
@ryancogswell
Copy link
Contributor

Could you confirm I'm on the right track?

@oliviertassinari Yes -- looks good.

Here's a sandbox where I played around with it a bit: https://codesandbox.io/s/select-focus-rf8wl

@oliviertassinari oliviertassinari added the priority: important This change can make a difference label Jun 1, 2019
@ianschmitz
Copy link
Contributor

Just a heads up that this is a bigger issue than Select. Menu/MenuList have lost keyboard a11y. I've been trying to fix it in a branch but it's proving to be pretty tricky.

@eps1lon
Copy link
Member

eps1lon commented Jun 12, 2019

Just a heads up that this is a bigger issue than Select. Menu/MenuList have lost keyboard a11y. I've been trying to fix it in a branch but it's proving to be pretty tricky.

Seems like a regression from 4.0.2. At least if I understand the issue https://v4-0-2.material-ui.com/components/menus/ seems to work fine.

But that is not directly related to this issue, no?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 12, 2019

@ianschmitz Definitely, hence the important flag :), only 10% of our issues have this flag.
@eps1lon v4.0.2 doesn't behave correctly from my perspective. Use the keyboard. Tab to focus the element. Enter to open it. Keydown doesn't work.

@ianschmitz
Copy link
Contributor

ianschmitz commented Jun 12, 2019

Disabling keepMounted in the "Simple Menu" example in docs gets us as far as having the ul focused, which allows the up/down arrow keys to work, however the first item is not focused by default.

The useLayoutEffect that runs in MenuList runs just after the initial render. By the time the Menu is opened, the list.focus() doesn't run from what i can tell.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 12, 2019

But that is not directly related to this issue, no?

@eps1lon It's the same fix: #15973 (comment).

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 15, 2019

@plumpNation I see that you are experiencing this problem too in #16242. Do you want to submit a pull request with the fix proposed in #15973 (comment)? :)

ianschmitz pushed a commit to ianschmitz/material-ui that referenced this issue Jun 19, 2019
eps1lon referenced this issue Jun 22, 2019
…6323)

* renderCount -> commitCount

If it happens in a passive effect it happend after a commit. A render
is only a call to the render function

* [test] Rework MenuList integration tests

* Cleanup lint config [skip ci]

* f

* Reduce number of goto statements

* [MenuList] Fix keyboard navigation when no item focused

* [docs] Adjust one demo to showcase behavior with no initial selection

* Format

* Better expect focused diff

* Address ryan's review

* expectSingleMenuItemFocusable _> expectSingleMenuItemTabFocusable

* Skip failing karma test

* test karma

* Skip whole MenuList integration in chrome 49

* Remove unused mount
@eps1lon
Copy link
Member

eps1lon commented Jun 22, 2019

Closed with #16323

@eps1lon eps1lon closed this as completed Jun 22, 2019
oliviertassinari pushed a commit to ianschmitz/material-ui that referenced this issue Jun 22, 2019
oliviertassinari pushed a commit that referenced this issue Jun 22, 2019
* Apply diff from #15973

* Update docs from previous commit

* fix height issue

* Sebastian review
@pelikhan
Copy link

It seems that this issue back. When trying the samples in https://material-ui.com/components/selects/ in latest Edge, the keyboard navigation does not work on menu items.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
accessibility a11y component: select This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. priority: important This change can make a difference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants