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(color-contrast): correctly apply page background color #3207

Merged
merged 9 commits into from
Oct 13, 2021

Conversation

straker
Copy link
Contributor

@straker straker commented Oct 13, 2021

As requested, spitting #3203 into two separate prs.

I modified how the body bgColor is added to the get-background-color element stack. How body and html affect the background is a bit complex, so it was better to not add body any time (get-background-stack.js => sortPageBackground) was missing but to instead grab either the html or body colors as they correctly applied. It turns out that defining a bg color to the html element allowed negative z-index elements to go behind the body, so I also took that into account.

For some examples!

Using the following code:

<html>
  <body>
    <div id="target">Some Text</div>
  </body>
</html>
  1. body background = red

image

  1. document background = lightblue

image

  1. document background = lightblue & body background = red

image

  1. document background = lightblue & body background = red & #target is outside body

image

  1. document background = lightblue & body background = red & #target is inside body

image

  1. body background = red & #target has z-index=-1

image

  1. document background = lightblue & body background = red & #target has z-index=-1

image

I added new tests for all these cases so we should accurately get the background color (and apply z-index correctly).

Closes issue: #2218

@straker straker requested a review from a team as a code owner October 13, 2021 16:47
@straker straker changed the title Body html background fix(color-contrast): correctly apply page background color Oct 13, 2021
@straker straker merged commit fbc581d into develop Oct 13, 2021
@straker straker deleted the body-html-background branch October 13, 2021 19:36
straker added a commit that referenced this pull request Oct 18, 2021
* fixes

* finalize

* sort

* test

* fix tests

* Update lib/commons/color/get-background-stack.js

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>

* fixes

* fix(color-contrast): correctly apply page background color

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
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.

2 participants