-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Menu] Improve hover/select/focus UI display #5186
Comments
@oliviertassinari Hi, sorry to be inactive for awhile! Moving discussion from closed PR I am not sure i understand Nathan... Problem is with Selected item has grey background. Hovered items also have grey background. So visually, you have 2 selected items when you move your mouse inside Menu (1 selected, 1 by hover). What should mouse hovering signify?
Should i implement that 2) option? |
@ArcanisCz I have been doing some benchmark, it's even worse than that. We have 3 possibles state. The focus, selected, and hover. You can have all of them at the same time:
The selected item is focused by default, otherwise, the first one.
|
I think that the best option is to keep the default focus behavior and to change the style of the three possible different states. I like the react-bootstrap solution (same as bootrap@4-alpha). |
I would also be interested in an option to not have the first value selected. You may want a menu that performs actions and you never select an item. In order to get my desired effect, I have had to do the following: <MenuItem key="placeholder" style={{display: "none"}} /> This is always the first item in the list so it gets highlighted but you don't see it cause it's hidden. Although this works, it is not ideal. |
I would really like to see this feature. Currently I'm using a Above work-around would also work, but is not ideal. |
In Google inbox, hover removes keyboard focus, so there is only ever one focused item. (Same as for Mac OS). For the Drawer list, they're using a slightly different shade for selected vs focus. |
@mbrookes The "three state" approach seems quite common: I'm going with this approach. |
The logic is no longer implemented, something has caused a regression, somewhere. We should take care of it. Also, it's a good opportunity to challenge what the best tradeoff is. |
@oliviertassinari Do you have a reproduction I can look at? I'm not sure what I'm looking for :) |
@joshwooding We have explored different approaches in #16331 (comment). What do you think of the approach n°1? |
I want to double down on this quote:
I completely agree here. One important part of a11y is that you consider focus(-visible) like any cursor. A sighted user can use the mouse to navigate to actions while screen reader users can use tab-focus. The focus outline marks the item that will be activated on-enter just like the hover marks the item that activates on mousedown. Enter and mousedown+up will both trigger a click event in the DOM. Styling hover and focus the same way is the only sensible thing if you think about it from a functional standpoint. Since it's already hard enough to distinguish selected and focus I'd be perfectly fine with styling focus and hover the same way. |
@eps1lon Agree. I have looked at the specification, I couldn't find any resources on the problem.
In this context, I would propose this fix: diff --git a/packages/material-ui/src/ListItem/ListItem.js b/packages/material-ui/src/ListItem/ListItem.js
index d663d8934..9d11b30a3 100644
--- a/packages/material-ui/src/ListItem/ListItem.js
+++ b/packages/material-ui/src/ListItem/ListItem.js
@@ -23,7 +23,7 @@ export const styles = theme => ({
paddingTop: 8,
paddingBottom: 8,
'&$focusVisible': {
- backgroundColor: theme.palette.action.selected,
+ backgroundColor: theme.palette.action.hover,
},
'&$selected, &$selected:hover': {
backgroundColor: theme.palette.action.selected, We use to have this logic, it seems to have been lost (by mistake?) between #14680 and #14212. I'm not sure what I had in mind 🤔. Would it work for you guys? |
Also interesting that native |
@eps1lon On which environment? On macOS, I have: Regarding the multi-select use case, the keyboard focus state needs to take precedence over the selected state, otherwise, you can't see where your focus is if you have, let's say 3 options selected consecutively. I would propose a slightly different version to #5186 (comment) I like this tradeoff:
What do you think? diff --git a/packages/material-ui/src/ListItem/ListItem.js b/packages/material-ui/src/ListItem/ListItem.js
index d663d8934..dd03def41 100644
--- a/packages/material-ui/src/ListItem/ListItem.js
+++ b/packages/material-ui/src/ListItem/ListItem.js
@@ -23,7 +23,9 @@ export const styles = theme => ({
paddingTop: 8,
paddingBottom: 8,
'&$focusVisible': {
- backgroundColor: theme.palette.action.selected,
+ backgroundColor: theme.palette.action.hover,
+ outline: '2px solid #999',
+ outlineOffset: -2,
},
'&$selected, &$selected:hover': {
backgroundColor: theme.palette.action.selected, or
diff --git a/packages/material-ui/src/ListItem/ListItem.js b/packages/material-ui/src/ListItem/ListItem.js
index d663d8934..bf00ec1fe 100644
--- a/packages/material-ui/src/ListItem/ListItem.js
+++ b/packages/material-ui/src/ListItem/ListItem.js
@@ -22,11 +22,11 @@ export const styles = theme => ({
textAlign: 'left',
paddingTop: 8,
paddingBottom: 8,
- '&$focusVisible': {
+ '&$selected': {
backgroundColor: theme.palette.action.selected,
},
- '&$selected, &$selected:hover': {
- backgroundColor: theme.palette.action.selected,
+ '&$focusVisible': {
+ backgroundColor: theme.palette.action.hover,
},
'&$disabled': {
opacity: 0.5, |
I would need a render preview for that. Pure code is for UI/UX hard to review. |
We might have a recommendation from the specification: |
Problem description
After initial open of menu, first item remains highlighted even after hovering off.
Steps to reproduce
next
branch, menus demo http://localhost:3000/#/component-demos/menusVersions
next
branch a38068fImages
The text was updated successfully, but these errors were encountered: