-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Comments
@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? |
@oliviertassinari Yes -- looks good. Here's a sandbox where I played around with it a bit: https://codesandbox.io/s/select-focus-rf8wl |
Just a heads up that this is a bigger issue than |
But that is not directly related to this issue, no? |
@ianschmitz Definitely, hence the |
Disabling The |
@eps1lon It's the same fix: #15973 (comment). |
@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)? :) |
…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
Closed with #16323 |
* Apply diff from #15973 * Update docs from previous commit * fix height issue * Sebastian review
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. |
The Select component is no longer accessible as of v4.0 if the Select input does not have a selected option.
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:
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: