Skip to content

Don't warn for accessible-emoji when the emoji are a11y hidden #30

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

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

### Changed

- When emojis are hidden from the a11y tree, don't warn with the `accessible-emoji` rule.

## [0.3.0] - 2020-07-03

### Changed
Expand Down
4 changes: 3 additions & 1 deletion src/rules/__tests__/accessible-emoji.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ makeRuleTester("accessible-emoji", rule, {
"<div />",
"<span />",
"<span role='img' aria-label='Panda face'>😰</span>",
"<span role='img' aria-label='Snowman'>&#9731;</span>"
"<span role='img' aria-label='Snowman'>&#9731;</span>",
"<span aria-hidden>😰</span>",
"<div aria-hidden><span>😰</span></div>"
],
invalid: [
"<span>😰</span>",
Expand Down
16 changes: 13 additions & 3 deletions src/rules/accessible-emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ const {
getElementAttributeValue,
getElementType,
hasAriaLabel,
isHiddenFromScreenReader,
makeDocsURL
} = require("../utils");

const isAriaHidden = (node) => {
if (!node || node.type !== "VElement") {
return false;
}

return isHiddenFromScreenReader(node) || isAriaHidden(node.parent);
};

module.exports = {
meta: {
docs: {
Expand All @@ -25,9 +34,10 @@ module.exports = {
const element = node.parent;

if (
!hasAriaLabel(element) ||
getElementType(element) !== "span" ||
getElementAttributeValue(element, "role") !== "img"
!isAriaHidden(element) &&
(!hasAriaLabel(element) ||
getElementType(element) !== "span" ||
getElementAttributeValue(element, "role") !== "img")
) {
context.report({ node, messageId: "default" });
}
Expand Down