axe-core icon indicating copy to clipboard operation
axe-core copied to clipboard

Test for color-contrast of OPTION elements

Open masi opened this issue 5 years ago • 7 comments

Expectation: <option style="color:#fff;background-color:#fff"> triggers an error.

Actual: No error is triggered.

Motivation: Chromium based browsers support setting color and background-colors of OPTION elements.


axe-core version: 3.5.7
browser-plugin: 4.5.3 (Chromium on Linux)

masi avatar Aug 27 '20 16:08 masi

Interesting. I'm not seeing Chrome setting the color or background color of the option element.

image

straker avatar Aug 28 '20 15:08 straker

Odd, I can:

<html>
<style>
.a {
  color: red;
  background-color: green;
}
.b {
  color: blue;
  background-color: red;
}
</style>
<select>
<option>-</option>
<option class="a">item 1</option>
<option class="b">item 2</option>
</select>
</html>

Bildschirmfoto vom 2020-08-31 20-42-53

masi avatar Aug 31 '20 18:08 masi

What browser/system/versions are you using? Any flags enabled?

I'm using Chrome 85.0.4183.83 on Mac Catalina 10.15.6, no flags. Can't see colors on options.

image

straker avatar Aug 31 '20 19:08 straker

Version 85.0.4183.83 (Offizieller Build) (64-Bit) on Fedora (Linux) Version 84.0.4147.125 (Offizieller Build) (64-Bit) on Windows 10

I assume that macOS has a stronger policy regarding the styling of system widgets.

IE11 can set the colours on Windows 10. Firefox 80.0 will set the colours on Windows 10 but not on Linux.

masi avatar Sep 01 '20 08:09 masi

Alright, did some testing of this:

  • Mac
    • Chrome- no support
    • Safari- no support
    • Firefox- supports
  • Win10
    • Chrome - supports
    • Firefox - supports
    • IE11 - supports
    • Edge - supports

So it seems Chrome and Safari on Mac are the only ones not supporting it.

The main problem I foresee is that there is no way to tell if the current browser supports the pattern. Doing window.getComputedStyle(document.querySelector('.a')).color results in rgb(255,0,0) even if the browser doesn't support it. So if we report a color contrast violation on the option in Chrome, a user may be a bit confused as to why as the browser isn't rendering it.

straker avatar Sep 03 '20 16:09 straker

How about telling the user that the problem may not be visible depending on browser and operating system with the information of the reported combination of colour and background colour.

masi avatar Sep 04 '20 09:09 masi

Chrome 135 will be releasing with full support for fully customizable select elements. This includes being able to add span elements inside option elements and changing their color / background color.

Docs: https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select

straker avatar Mar 31 '25 16:03 straker