Skip to content

fix(color-contrast): add special case for new sr-only technique#2985

Merged
WilcoFiers merged 4 commits intodevelopfrom
2962-color-contrast-sr-only
Jun 15, 2021
Merged

fix(color-contrast): add special case for new sr-only technique#2985
WilcoFiers merged 4 commits intodevelopfrom
2962-color-contrast-sr-only

Conversation

@clottman
Copy link
Copy Markdown
Contributor

@clottman clottman commented Jun 10, 2021

The minimum CSS that makes the element from the example visually hidden is a combination of:

overflow: hidden;
position: absolute;
height: 1px;

So if the user is doing that, they are probably trying to hide the element visually and axe-core should recognize that.

Note that the repro case will not fail in Firefox even without this code.

Closes #2962

@clottman clottman requested a review from a team as a code owner June 10, 2021 17:10
Copy link
Copy Markdown
Contributor

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add and/or update a test to go with this?

@clottman
Copy link
Copy Markdown
Contributor Author

Score +1 for proper testing; in firefox the false positive described in the ticket doesn't show up at all due to differences in the bounding rect calculations, leading me to think my code fixed the issue.

Pushed a better fix that adds a new special case to the sr-only detection, and added a test for it.

@clottman clottman changed the title bump up height requirement for sr-only determination to 1px fix(color-contrast): add special case for new sr-only technique Jun 10, 2021
@clottman clottman requested a review from WilcoFiers June 10, 2021 21:05
(isClipped(style) ||
style.getPropertyValue('opacity') === '0' ||
(getScroll(el) && parseInt(style.getPropertyValue('height')) === 0))
(getScroll(el) && elHeight === 0) ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you left this at 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, turns out it wasn't relevant to the case I was trying to address so I left it alone. Would you rather it be bumped up too?

Comment on lines +164 to +167
(getScroll(el) && elHeight === 0) ||
(style.getPropertyValue('position') === 'absolute' &&
elHeight <= 1 &&
style.getPropertyValue('overflow') === 'hidden'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 line if statement's a bit much. Can you isolate some of the logic on this?

clottman and others added 2 commits June 14, 2021 11:21
Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
@WilcoFiers WilcoFiers merged commit d6a72f9 into develop Jun 15, 2021
@WilcoFiers WilcoFiers deleted the 2962-color-contrast-sr-only branch June 15, 2021 08:41
WilcoFiers added a commit that referenced this pull request Jun 17, 2021
* bump up height requirement for sr-only to 1px

* add special case for sr-only method

* use less than 2

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

* make if smaller

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
clottman added a commit that referenced this pull request Jun 17, 2021
* bump up height requirement for sr-only to 1px

* add special case for sr-only method

* use less than 2

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

* make if smaller

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
straker pushed a commit that referenced this pull request Jun 22, 2021
* bump up height requirement for sr-only to 1px

* add special case for sr-only method

* use less than 2

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

* make if smaller

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.

color-contrast false positive on element styled as screen-reader-only

2 participants