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

Grouped autocomplete color contrast #19574

Closed
dmitriid opened this issue Feb 5, 2020 · 22 comments · Fixed by #20142
Closed

Grouped autocomplete color contrast #19574

dmitriid opened this issue Feb 5, 2020 · 22 comments · Fixed by #20142
Labels
component: autocomplete This is the name of the generic UI component, not the React module! 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. new feature New feature or request

Comments

@dmitriid
Copy link

dmitriid commented Feb 5, 2020

Filed as a bug, because it's more of a usability bug

  • [ x ] The issue is present in the latest release.
  • [ x ] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Regular Dark mode
Screenshot 2020-02-05 at 11 42 47 Screenshot 2020-02-05 at 15 30 02

Category names are indistinguishable from regular items as there's not enough color contrast between items (it looks better on retina screenshots than in real life). This will be even more noticeable when category names are longer.

It may be worse with disabled items thrown into the mix (haven't tested this though).

Expected Behavior 🤔

Category names should be more pronounced.

Could be solved with any of: different color, bold font, underline. A horizontal rule before the start of the category, perhaps. Offset could probably work, but needs testing with longer category names, might still be confusing.

Steps to Reproduce 🕹

Tested on https://material-ui.com/components/autocomplete/ -> Grouped

Context 🔦

Material Design in general suffers from very low contrast, or not enough contrast between elements

Your Environment 🌎

Safari 13.0.4 (15608.4.9.1.3), MacOS 10.15.2

@UniverseHan
Copy link

UniverseHan commented Feb 5, 2020

What should we do? Aren't there options for that?

@dmitriid
Copy link
Author

dmitriid commented Feb 5, 2020

Could be solved with any of: different color, bold font, underline. A horizontal rule before the start of the category, perhaps. Offset could probably work, but needs testing with longer category names, might still be confusing.

Possible solutions:

  • Start with a bold font. See if that helps. Possibly, bold font and capitalize (see "4 items in your cart" in the Transitions demo)

  • You could offset the items in the same way browsers do it (note: default browser representation on the Mac has very poor color contrast for group headers):

Screenshot 2020-02-05 at 15 54 39

Even better: a divider with a (subheader) in the theme's primary color. See this screenshot from the docs. Here the category is to the left of the list, but could be on its own line.

@oliviertassinari
Copy link
Member

Do we have examples of how Google solve this problem with its products? It could be an interesting source to benchmark with.

@oliviertassinari oliviertassinari added the new feature New feature or request label Feb 5, 2020
@TommyJackson85
Copy link
Contributor

TommyJackson85 commented Feb 5, 2020

@oliviertassinari
This one is of their search bar which just uses a hr line underneath.

Screenshot 2020-02-05 at 18 15 40

Here is just the search results which shows grey text above giving a rough overview of the results.

Screenshot 2020-02-05 at 18 16 11

Could use a combination of greyed text and a grey underline. It would be quite subtle. I don't think I would like bold text. Bold text would be better used to put emphasise on words in found results (i.e. words matching the word you searched). In the search results section you can see bold text is used to put emphasis on words not inputed by the user.

@oliviertassinari
Copy link
Member

Sorry, I should have been more precise. I meant how the select + categories/groups problem is solved.

@dmitriid
Copy link
Author

dmitriid commented Feb 5, 2020

I would advise against looking at what Google does.

  • it's a huge organization with very different approaches and levels of implementation. See this mess for an example: https://grumpy.website/post/0TBOWnfjB

  • even the official Material website is known to break its own rules

First and foremost I would look at accessibility guidelines, and go by those. Material's own guidelines are quite good: https://material.io/design/usability/accessibility.html

Quote:

Color and contrast can be used to help users see and interpret your app’s content, interact with the right elements, and understand actions.

Color can help communicate mood, tone, and critical information. Primary, secondary, and accent colors can be selected to support usability. Sufficient color contrast between elements can help users with low vision see and use your app.

Contrast ratios

Color contrast is important for users to distinguish various text and non-text elements.

Color contrast is important for users to distinguish various text and non-text elements.

end quote

@oliviertassinari
Copy link
Member

@dmitriid we won't be able to advance the resolution of this concern without benchmarking how others are solving this issue. I have noticed that select2 uses an indent. I would highly recommend to look at what Google is doing. I'm not that much interested in the consistency of their product nor how well they follow the specification. It's not a hard science. It's subject to interpretation.
I think that we should focus on reviewing the solutions smart UX/UI designers that have faced the problem in the past came up with.

@oliviertassinari oliviertassinari added discussion component: select This is the name of the generic UI component, not the React module! component: autocomplete This is the name of the generic UI component, not the React module! and removed new feature New feature or request labels Feb 6, 2020
@oliviertassinari
Copy link
Member

Thanks, very interesting.

@dmitriid
Copy link
Author

dmitriid commented Feb 6, 2020

It looks like very few (easily Googlable) projects to grouping in autocompletes

@oliviertassinari
Copy link
Member

We have the same problem with the Select component. Here is an example with Angular Material: https://material.angular.io/components/select/overview#creating-groups-of-options.

@embeddedt
Copy link
Contributor

I notice that Angular Material and the native select element for Firefox (at least on Ubuntu) use indentation and bold text to accent the category headings.

Screenshot from 2020-02-06 10-26-21

(The list is partially transparent because it begins fading out to close as soon as you press PrtScrn.)

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 6, 2020

Looking more closely at the material design specification and the google products, it seems that groups are not something they support. So, I think that we can take some freedom.

I would personally be in favor of introducing a light left indent (to follow native selects) and look at how we can solve #18200 at the same time.

@oliviertassinari oliviertassinari added new feature New feature or request and removed discussion labels Feb 6, 2020
@dmitriid
Copy link
Author

dmitriid commented Feb 6, 2020

👍

1em or 2em will probably be more than enough (but needs to be checked with a variety of text lengths).

@embeddedt
Copy link
Contributor

needs to be checked with a variety of text lengths

It seems that long option names do not get any special handling with the current implementation, at least from my limited testing here: https://codesandbox.io/s/mui-select-long-names-448b3

@oliviertassinari
Copy link
Member

I would propose the following diff:

Capture d’écran 2020-02-22 à 13 41 48

diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
index 463ff0f2f..3e7e1eb47 100644
--- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
+++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
@@ -162,17 +162,14 @@ export const styles = theme => ({
     ...theme.typography.body1,
     overflow: 'hidden',
     margin: '4px 0',
-    '& > ul': {
-      maxHeight: '40vh',
-      overflow: 'auto',
-    },
   },
   /* Styles applied to the `listbox` component. */
   listbox: {
     listStyle: 'none',
     margin: 0,
     padding: '8px 0px',
-    position: 'relative',
+    maxHeight: '40vh',
+    overflow: 'auto',
   },
   /* Styles applied to the loading wrapper. */
   loading: {
@@ -223,6 +220,9 @@ export const styles = theme => ({
   /* Styles applied to the group's ul elements. */
   groupUl: {
     padding: 0,
+    '& $option': {
+      paddingLeft: 24,
+    },
   },
 });

What do you guys think about it? @d0minikt Do you want to open a pull request? :)

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Feb 22, 2020
@dmitriid
Copy link
Author

Looks really good 👍

Can you try with longer category names? Though it still should look good :)

@oliviertassinari
Copy link
Member

28 pixels?

@embeddedt
Copy link
Contributor

I can make a PR to close this and #18200 together if you would like.

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 15, 2020

@embeddedt I think that we can handle the Select and Autocomplete component independently in this case. I'm not sure how the solution for the Select would look like, it will likely be way different. But it's worth exploring :)

@oliviertassinari oliviertassinari added component: select This is the name of the generic UI component, not the React module! and removed component: select This is the name of the generic UI component, not the React module! labels Mar 15, 2020
@embeddedt
Copy link
Contributor

Okay; I am working on a PR for the Autocomplete component. Once that's done I will look at the Select component.

@dmitriid
Copy link
Author

Thank you! 👍💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! 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. new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants