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

fix: improve color contrast in menu element example for accessibility #2840

Closed
wants to merge 3 commits into from

Conversation

yashrajbharti
Copy link

Description

I changed the background color of the menu element example from bisque to black to fix the inaccessible color contrast issue, improving readability and meeting WCAG 2.1 contrast ratio standards.

Motivation

The previous background color did not meet the minimum contrast ratio requirement, making the text difficult to read for users with visual impairments (and even hard for normal users). This change improves accessibility across browsers.

Additional details

  • MDN menu element example
  • The issue is reproducible on macOS Monterey using Safari 17.5, Chrome 128.0.6613.138, and Firefox 130.0.

Related issues and pull requests

Fixes #2839

@yashrajbharti yashrajbharti requested a review from a team as a code owner September 16, 2024 06:23
@yashrajbharti yashrajbharti requested review from estelle and removed request for a team September 16, 2024 06:23
Copy link

It looks like this is your first pull request. 🎉 Thank you for your contribution! One of the project maintainers will triage and assign the pull request for review. We appreciate your patience. To safeguard the health of the project, please take a moment to read our code of conduct.

@@ -1,5 +1,5 @@
.news {
background-color: bisque;
background-color: black;
Copy link
Member

Choose a reason for hiding this comment

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

this makes it more accessible in dark mode, but makes the link above impossible to read in light mode.
Screenshot 2024-09-16 at 3 04 04 AM

Copy link
Author

Choose a reason for hiding this comment

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

Okay, fixing it for both light and dark modes and checking in all the major browsers

Copy link
Author

Choose a reason for hiding this comment

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

Making the following changes fixes the color contrast issue as checked in all major browsers:

(But I couldn't find a way without using a @media query for color schemes, and I didn't wanted to re-color the states of anchor tag, which by default comes with accessibility out of the box.)

.news {
  background-color: bisque;
  padding: 1em;
  border: solid thin black;

  @media (prefers-color-scheme: dark) {
    background-color: black;
  }
}

menu {
  list-style-type: none;
  display: flex;
  padding: 0;
  margin-bottom: 0;
  gap: 1em;
}

button {
  color: black;
  background: white;
}

Screenshot 2024-09-16 at 6 14 23 PM
Screenshot 2024-09-16 at 6 14 29 PM
Screenshot 2024-09-16 at 6 16 10 PM
Screenshot 2024-09-16 at 6 15 37 PM

@estelle Should I go for it?

@bsmth bsmth changed the title Fix inaccessible color contrast in menu element example for accessibility fix: improve color contrast in menu element example for accessibility Sep 18, 2024
Button color set to contrast colors from the user agent injected button text color that affected accessibility in safari, and fixed color contrast for dark theme
@yashrajbharti
Copy link
Author

yashrajbharti commented Sep 18, 2024

The latest commit fixes the color contrast issues that occurred in Safari due to its user agent style sheet setting the color buttontext. This can also be fixed using color: unset.
The commit also cares about the light and dark modes where color contrast are now better for readability (greater than 5.6 in all cases).

Added image below:
Light theme:
Screenshot 2024-09-18 at 7 39 51 PM
Dark theme:
Screenshot 2024-09-18 at 7 39 43 PM
Safari (17.5)
Screenshot 2024-09-18 at 7 40 33 PM

@estelle
Copy link
Member

estelle commented Oct 21, 2024

I added a comment to #2839 (comment) which I thought I had added here. I am hesitant to merge anything targeting the issue with the Safari button as this should be a webkit fix.

@yashrajbharti
Copy link
Author

yashrajbharti commented Oct 26, 2024

There is something more to it, the same code gives different results if pasted from interactive example in the docs to the mdn playground, thus I fail to reproduce the bug on MDN playground. However, I have added a report to webkit bugzilla with a link to this a11y button issue #2839 , and <menu> element example from mdn web docs | menu.

Screenshot 2024-10-26 at 2 58 46 PM Screenshot 2024-10-26 at 2 58 41 PM

@estelle
Copy link
Member

estelle commented Oct 29, 2024

Thanks @yashrajbharti. Let's close this rather than commit it, as it is better to keep the examples as basic as possible (the fewest features needed).

@estelle estelle closed this Oct 29, 2024
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.

Inaccessible color contrast ratio in menu element example
3 participants