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

Color contrast should ignore overlapping elements that have transparent background #3464

Open
straker opened this issue May 18, 2022 · 10 comments
Labels
color contrast Color contrast issues fix Bug fixes pr A pr has been created for the issue
Milestone

Comments

@straker
Copy link
Contributor

straker commented May 18, 2022

Take the following example:

<style>
.overlap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
}
</style>

<span>Hello World</span>
<div class="overlap"></div>

This causes an incomplete result for color contrast because the .overlap element is on top of the <span> element in the DOM stack. However since the .overlap element has a transparent background it should just be ignored.

This same problem happens with Material Button components due to the ripple effect element that overlaps the button text.

<button class="mdc-button mdc-button--raised">
  <span class="mdc-button__label">Button</span>
  <div class="mdc-button__ripple"></div>
</button>
@straker straker added fix Bug fixes color contrast Color contrast issues labels May 18, 2022
@straker straker added this to the Axe-core 4.5 milestone May 18, 2022
@straker
Copy link
Contributor Author

straker commented May 18, 2022

We should look into restricting exactly what is ignored, as images or iframes that overlap won't have a background color but will interfere with the element. So possible solution is to ignore the element if it meets all of the following conditions:

  • has a fully transparent background
  • has no text content
  • has a presentational or no role

@WilcoFiers
Copy link
Contributor

It also can't have CSS filters, thick border, pseudo elements, embedded graphical content like img, canvas, object. There are a ton of ways in which something that at first glance may seem like an empty div, for it to have an impact on content that's behind it.

I think that 9 out of 10 times when we see a transparent element on top of text content, it's there to have some kind of effect on things that are behind it. Why would people put completely empty divs on top of their content?

@WilcoFiers WilcoFiers modified the milestone: Axe-core 4.5 May 20, 2022
@straker
Copy link
Contributor Author

straker commented Jun 3, 2022

A good example of this is the home page of https://arstechnica.com/. They use empty anchor tags with aria-hidden=true and tabindex=-1 to cover the entire card for the article links which makes every single node in the card return as needs review (165 total color contrast needs review items).

We could scope the requirement to ignore the element based on:

  • does not have text content
  • does not have a background color (i.e. transparent)
  • does not have pseudo elements
  • does not have a border, outline, filter, etc.

@straker
Copy link
Contributor Author

straker commented Oct 3, 2022

Another place this happens on is Material Inputs https://material.angular.io/components/input/overview. The inputs each contain a span which in turn contains the label element for the input. The span overlaps the input, but the label does not. Since the span itself has no background and no direct text children, we should ignore it as well.

@padmavemulapati
Copy link

Validated with the latest develop branch code base, for the test script:

<style>
.overlap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
}
</style>

<span>Hello World</span>
<div class="overlap"></div>

This snippet is giving an incomplete result for color contrast because the .overlap element is on top of the <span> element in the DOM stack.

Image

and with the below test script:

<button class="mdc-button mdc-button--raised">
  <span class="mdc-button__label">Button</span>
  <div class="mdc-button__ripple"></div>
</button>

the ripple effect element that overlaps the button text, so it is passing

@CHE1RON
Copy link

CHE1RON commented Jan 27, 2023

I know this was closed some time ago, but is there any chance to revive #3583 in order to prevent incomplete tests? 😕

@WilcoFiers
Copy link
Contributor

This was closed by mistake. We're going to look at this again.

@WilcoFiers WilcoFiers reopened this Jul 12, 2023
@WilcoFiers WilcoFiers modified the milestones: Axe-core 4.5, Axe-core 4.9 Jul 12, 2023
@CHE1RON
Copy link

CHE1RON commented Jul 12, 2023

Thanks! 🙏

@semisse
Copy link

semisse commented Mar 7, 2024

please, fix this!

v-rakeshsh added a commit to microsoft/accessibility-insights-web that referenced this issue Jun 12, 2024
#7348)

#### Details

This feature is to bind V8 theme for existing Fluent ui components and
V9 for new Fluent Ui components (next feature).

- So as part of Fluent UI V9 migration, we will not migrate entire
components from V8 to V9, as we are following migration in incremental
approach as V9 is also in development from fluent team.
- So to accommodate V8 and V9 components UI designs, we created V8 and
V9 theme wrapped in root. So that V8 components will pickup v8 theme and
V9 components (NEXT FEATURE) will pickup V9 theme.
- This feature also covers, high contrast themes for both v8 and v9
themes.
- Updated to latest V9 Fluent version @fluentui/react-components to
9.x.x
- Removed loadTheme from V8, as we are using theme as Wrapper instead of
calling function.
- Created custom V9 Dark theme to accommodate high contrast option.

**Updated below test cases :**
src/tests/end-to-end/tests/details-view/headings.test.ts
src/tests/end-to-end/tests/details-view/reflow-ui.test.ts

During e2e test cases encountered below errors for above 2 files:

![GetImage](https://github.com/microsoft/accessibility-insights-web/assets/155614445/96db2b81-389e-4537-b550-5bf5656b686a)

So from investigation, we can observe its false positive for high
contrast, and there is existing issues reported for transparent
background.
dequelabs/axe-core#3464
And the issue we are seeing is with **Assessment link** in high contrast
mode, inspecting this link in high contrast mode, we can see background
is in transparent.

- Removed loadTheme test case, as we are not using loadTheme anymore.

##### Motivation

To keep AI Web to accommodate both V8 and V9 components with respective
theme.

##### Context



#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a"
in the checkbox -->
- [ ] Addresses an existing issue: #0000
- [x] Ran `yarn fastpass`
- [x] Added/updated relevant unit test(s) (and ran `yarn test`)
- [x] Verified code coverage for the changes made. Check coverage report
at: `<rootDir>/test-results/unit/coverage`
- [x] PR title *AND* final merge commit title both start with a semantic
tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See
`CONTRIBUTING.md`.
- [x] (UI changes only) Added screenshots/GIFs to description above
- [ ] (UI changes only) Verified usability with NVDA/JAWS
@asyncLiz
Copy link

asyncLiz commented Oct 8, 2024

Hello from Material! We're running into this bug and it's suppressing color-contrast violations as incomplete due to our invisible touch target.

I create a repro here: https://jsbin.com/diqacijawi/edit?html,output. Minimal html:

<style>
  button {
    background: lightblue;
    color: green;

    /* place touch target in center */
    position: relative;
    display: grid;
  }

  .touch-target {
    outline: 1px dashed green;
    height: 48px;
    width: 100%;
    position: absolute;
    place-self: center;
  }
</style>
<button id="invalid-color-no-touch-target">
  Invalid color (caught)
</button>

<button id="invalid-color-with-touch-target">
  Invalid color + touch (incomplete, missed)
  <div class="touch-target"></div>
</button>

The reason for this floating empty element is to extend the "touch area" for a component on mobile for accessibility. The increased area helps users click on elements that are smaller than 48px.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color contrast Color contrast issues fix Bug fixes pr A pr has been created for the issue
Projects
None yet
Development

No branches or pull requests

6 participants