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

Background color for certain DOM elements is incorrect

Open rkomiyama opened this issue 9 years ago • 16 comments

The error message from aXe is telling me that the DOM element has a background color of white (#ffffff) when the parent DOM element is a purple color.

Is there a way to get the error message to print out the origin of this white background color? I have no idea where it gets a value of #ffffff for background-color when it is clearly a non-white background color.

rkomiyama avatar Jun 13 '17 18:06 rkomiyama

Hi there, you should be able to look at the relatedNodes to see where the colors are being picked up. If your parent element isn't in the list, it may be related to some bug fixes I'm working on in #330 and #319.

To help us debug, we need more information about the DOM elements. Here are some questions I'll need answered:

  • What elements are they? e.g. DIV, TR, SPAN, etc.
  • How is the parent background color applied? i.e. background-color on the node, border-color, :before, etc.
  • What are the display values for both the child and the parent? i.e. block or inline
  • Do either of the elements have any tricky positioning or transforms?

marcysutton avatar Jun 13 '17 18:06 marcysutton

Gotcha, I'll have to check out relatedNodes then. Not sure where/how I can access it, but I'll figure it out if it's in one of the GitHub issues.

To answer your questions:

  • They are just <a> tags in the <footer>. I've tried wrapping them around <div> and <span>, but the results are the same (says background color is white).
  • I've tried applying background-color on the element, as well as its parent, and its parent's parent.
  • I've tried using <div> with inline display.
  • The <footer> has relative positioning with bottom: 0.

rkomiyama avatar Jun 13 '17 19:06 rkomiyama

relatedNodes is part of the results object. If you're using axe-core, it will be in the specific node information for an issue. In the aXe browser extensions, it will be displayed in the UI. You can reference the API here: https://github.com/dequelabs/axe-core/blob/master/doc/API.md#result-arrays

Can you provide a code snippet or Codepen showing the issue? That will help us debug it the fastest.

marcysutton avatar Jun 13 '17 19:06 marcysutton

The footer is part of a large React project, but hopefully this helps.

<footer className="ProductFooter">
  <div className="grid">
    <div className="row">
      <div className="col ProductFooter__feedback">
        <Link className={className} to="/feedback">
          Feedback
        </Link>
        <h6 className="ProductFooter__text">Blah blah blah</h6>
      </div>
      <div className="col ProductFooter__links">
        <Link className={className} to="/faq">
          FAQ
        </Link>
        <Link className={className} to="/legal">
          Legal Notices
        </Link>
        <Link className={className} to="/terms">
          Terms of Use
        </Link>
        <Link className={className} to="/about">
          About
        </Link>
      </div>
    </div>
  </div>
</footer>

rkomiyama avatar Jun 13 '17 19:06 rkomiyama

Thanks! We need the styles too, however.

marcysutton avatar Jun 13 '17 19:06 marcysutton

.ProductFooterContainer {
  position: relative;
  background-color: $neutral-white-40;
}

.ProductFooter {
  position: relative;
  bottom: 0;
  width: 100%;
  background-color: $indigo-90;
  padding: $spacing-x-large 0;
}

.ProductFooter__text {
  position: absolute;
  color: $white;
  line-height: 1.5;
}

.ProductFooter__links.col {
  text-align: right;
}

.ProductFooter__links > .Link {
  @include font-size('14');

  margin-right: $spacing-medium;
}

.ProductFooter__links > .Link:last-child {
  margin-right: 0;
}

.Link {
  @include font--bold;
  @include font-size('16');
  @include line-height('body');

  color: $violet-60;
  text-decoration: none;
  transition: 0.3s color ease;
  cursor: pointer;
  border: none;
  background: none;
}

.Link:hover {
  color: $violet-80;
  text-decoration: underline;
}

.Link[disabled],
.Link[disabled]:hover {
  color: $gray-50;
  cursor: inherit;
}

.Link--dark {
  color: $violet-20;
}

.Link--dark:hover {
  color: $violet-10;
  text-decoration: underline;
}

rkomiyama avatar Jun 13 '17 19:06 rkomiyama

screen shot 2017-06-13 at 3 16 20 pm

Unfortunately, I am unable to see relatedNodes in the aXe browser extension.

rkomiyama avatar Jun 13 '17 19:06 rkomiyama

Is it possible to get a working demo? The CSS is all variables, and it's difficult to parse out of context. Something that we can run in the browser will make this process go a lot faster.

marcysutton avatar Jun 13 '17 19:06 marcysutton

I don't know how much of the code I'm allowed to put out in the public, but I can try to see if I can get a similar page layout on a code pen.

~~BTW, we're using react-axe in our project. I'm wondering if there's a way to console.log the relatedNodes somewhere in the project.~~

Edit: Turns out that relatedNodes does output information, but not for the elements that I mentioned previously.

screen shot 2017-06-14 at 10 14 51 am

rkomiyama avatar Jun 13 '17 19:06 rkomiyama

@rkomiyama can you create a ticket in the react-axe project for the relatedNodes printing

dylanb avatar Jun 13 '17 20:06 dylanb

I'd like to point out that this issue only comes up when the elements in question are being loaded outside of the viewing window (which requires you to scroll down to see the footer). Which brings up my question as to what point in the rendering process does aXe check the elements' color contrasts? Because aXe may be picking up the white background color before the footer's purple background color is done rendering.

To add to all of this, the aXe browser extension is no longer showing the violations that I've mentioned (not sure what changes caused this to happen), but the React-axe plugin still shows them.

rkomiyama avatar Jun 20 '17 13:06 rkomiyama

I've finally finished a working demo. Here's App.js and App.css respectively.

App.js

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
        <div style={{height:'1500px'}} />
        <footer style={{'backgroundColor':'#272149'}}>
          <div className="grid">
            <div className="row">
              <div className="col">
                <a href="/home" style={{color:'white'}}>Home</a>
              </div>
            </div>
          </div>
        </footer>
      </div>
    );
  }
}

export default App;

App.css

.App {
  text-align: center;
}

.App-logo {
  animation: App-logo-spin infinite 20s linear;
  height: 80px;
}

.App-header {
  background-color: #222;
  height: 150px;
  padding: 20px;
  color: white;
}

.App-intro {
  font-size: large;
}

@keyframes App-logo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.grid {
  display: block;
  margin: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  list-style-image: none;
  list-style-position: outside;
  list-style-type: none;
  margin-top: -1.25rem;
  margin-left: -1.25rem;
}

.col {
  display: block;
  flex: 0 0 auto;
  padding-top: 1.25rem;
  padding-left: 1.25rem;
}

Seems like it's an issue with the negative margins in .row and positive padding in .col. And unfortunately, this is an integral part of our project's grid-layout system, so we are unable to take it out of our project at this point in time.

Here's a screenshot of the aXe warning (notice that it says the background color is white when it is actually #272149) with the footer in the page.

screen shot 2017-06-20 at 1 32 49 pm

rkomiyama avatar Jun 20 '17 17:06 rkomiyama

@rkomiyama this might be a timing issue - react-axe runs the analysis (with debouncing) in onComponentDidUpdate - one option is to increase the debounce timer. You can do this by adding a third option to your call to initialize the plugin. The timeout is in milliseconds

https://github.com/dequelabs/react-axe/blob/master/index.js#L170

dylanb avatar Jun 20 '17 18:06 dylanb

@dylanb I tried it with 20000ms, but unfortunately the error is still there. With that being said, the error doesn't show up if I scroll down to the footer location before the timer goes off.

rkomiyama avatar Jun 21 '17 13:06 rkomiyama

@rkomiyama aaah, I know why. Because of the continual analysis mode, we set the "noScroll" option on the color-contrast rule. This can lead to false positives because the foreground and background colors cannot always be accurately determined.

There is a fourth parameter that you can use to turn off certain rules. Pass in the following Object

{
  "rules": {
    "color-contrast": { enabled: false }
  }
}

You will then have to perform color contrast analysis using the extension or some other mechanism.

dylanb avatar Jun 22 '17 15:06 dylanb

@dylanb Your help is much appreciated :)

However, the syntax seems to be a little off, so I'll copy/paste the working configuration here in case anyone needs it in the future.

{
  rules: [
    {
      id: 'color-contrast',
      enabled: false,
    },
  ],
};

rkomiyama avatar Jun 22 '17 16:06 rkomiyama