Skip to content

Commit

Permalink
feat: excludes emoji from a11y container with alt caption
Browse files Browse the repository at this point in the history
  • Loading branch information
Andri Alexandrou committed Aug 23, 2023
1 parent 601b4fd commit 430502e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ function validateImagesWithAnchorParent(parent, image) {
}

function validateImagesWithNonAnchorParent(parent, image) {
const isEmoji = image.classList.contains("emoji");
if (isEmoji) {
return;
}

const hasAltTextAttribute = image.hasAttribute("alt");
const altText = hasAltTextAttribute && image.getAttribute("alt").trim();
if (!hasAltTextAttribute) {
Expand Down
16 changes: 16 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ describe("validateImages", () => {
expect(document.querySelector(".github-a11y-img-invalid-alt")).toBe(null);
});

test("does not flag if image is an emoji", () => {
console.log("am i run");
document.body.innerHTML = `
<p id="cat">
<img class="emoji" alt="Some cat." src="some_cat.png" />
</p>
`;
const parent = document.querySelector("#cat");
const img = document.querySelector("img");
validateImages(parent, img);
const captionContainer = document.querySelector(
".github-a11y-img-container"
);
expect(captionContainer).toBe(null);
});

test("surfaces alt if image has alt", () => {
document.body.innerHTML = `
<p id="cat">
Expand Down

0 comments on commit 430502e

Please sign in to comment.