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

color-contrast incorrectly calculating background color of an element in closed `<details>`

Open wojtekmaj opened this issue 1 year ago • 5 comments

Product: axe-core

Expectation: When calculating contrast ratio for an element in closed <details>, either:

  • take background color of open <details> element (might not be possible without page interaction, which could be a roadblock),
  • or don't take any background color at all, effectively skipping the color-contrast test for this element.
  • or if we really really would like to take background color of where the element would have been if the <details> element was open, ignore <details>'s siblings when calculating background colors, because they will be pushed down when <details> is eventually opened.

Actual: background color is taken from the place where the element would have been if the <details> element was open. Unfortunately, in our example, in this place we have a dark blue button which, when combined with black text, fails the test.

Motivation: Current behavior is obviously faulty.


axe-core version: checked on: 4.0.0, …, 4.1.0, …, 4.2.0, …, 4.3.0, …, 4.4.0, …, 4.4.2

Browser and Assistive Technology versions
Chrome 103.0.5060.53

Repro:

<html lang="en-US">
  <head>
    <style>
      span {
        position: relative;
      }

      button {
        background-color: darkblue;
        color: #fff;
      }
    </style>
    <title>color-contrast bug</title>
  </head>

  <body>
    <header>
      <h1>color-contrast bug</h1>
    </header>
    <main>
      <details>
        <summary>Summary</summary>
        <span>Some text</span>
      </details>
      <button>A blue button</button>
    </main>
  </body>
</html>

wojtekmaj avatar Jul 04 '22 20:07 wojtekmaj

It appears that the problem is in filteredRectStack function, which in this case, returns [span, button, main, body, html].

wojtekmaj avatar Jul 05 '22 06:07 wojtekmaj

Thanks for reporting. We'll take a closer look ASAP.

WilcoFiers avatar Jul 05 '22 17:07 WilcoFiers

Looking at the issue, it appears we don't treat elements inside the <details> as hidden when the element is collapsed. As is, we think the <span> element is currently visible and positioned right above the button, so that's why we reporting the overlapping element.

I believe <details> elements have the open attribute when expanded, so we should be able to use that to determine visibility.

straker avatar Jul 13 '22 16:07 straker

Need to discuss with Wilco the ramifications of saying elements inside closed detail elements are hidden as we may not run axe-core rules against them.

straker avatar Jul 28 '22 17:07 straker

We discussed this and the resolution is we'll update the is-hidden function to account for this. This means rules will not run against elements inside of a closed <details> elements and users will need to expand the details in order to get accessibility checks.

straker avatar Aug 05 '22 15:08 straker

Validated with the latest develop branch code base, and here for the test script, inside <details> closed tag

and are passing the color-contrast rule as it is counting the elements inside closed details as hidden

<main>
      <details>
        <summary>Summary</summary>
        <span>Some text</span>
      </details>
      <button>A blue button</button>
    </main>
image

padmavemulapati avatar Oct 19 '22 13:10 padmavemulapati