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

Image and combobox are not being detected by the getByRole. #512

Closed
lakshman0369 opened this issue Jun 14, 2023 · 5 comments · Fixed by #515
Closed

Image and combobox are not being detected by the getByRole. #512

lakshman0369 opened this issue Jun 14, 2023 · 5 comments · Fixed by #515

Comments

@lakshman0369
Copy link

Describe the bug

Image tagged element and combobox are not being detected by the getByRole query.

Aria-query previous working version - 5.1.3
Aria-query upgraded version version - 5.2.1

<img src="/rcore/static/media/AccessDenied_Icon.db53e967.svg" alt="" class="sc-lmJFLr hLGeOl sc-jRBLiq ghkJEk" id="">

Previously before the 'aria-query' upgrade, getByRole query will detect the above element. But after the upgrade this query is not able to detect the above element.

We have many test cases that are breaking due to above issue . This behavior is happening since v5.2.1. Please fix the issue above issue.

@kenny-lu-hl
Copy link

I am also seeing this issue when using react testing library, since it depends on aria-query. Currently have to fix aria-query version to 5.1.3., and prevent it from updating to 5.2.1

@jlp-craigmorten
Copy link
Contributor

jlp-craigmorten commented Jun 15, 2023

R.E. the img role, pertinent spec snippets:

HTML element Implicit ARIA semantics (explicitly assigning these in markup is NOT RECOMMENDED) ARIA role, state and property allowances
img with alt="some text" role=img Roles: button, checkbox, link, menuitem, menuitemcheckbox, menuitemradio, option, progressbar, radio, scrollbar, separator, slider, switch, tab or treeitem. (img is also allowed, but NOT RECOMMENDED.). DPub Role: doc-cover.Global aria-* attributes and any aria-* attributes applicable to the allowed roles.
img with alt="" role=presentation No role other than presentation, which is NOT RECOMMENDED. No aria-* attributes except aria-hidden="true".

REF: https://www.w3.org/TR/html-aria/#docconformance

It is therefore the W3C Recommendation that an img element with an empty alt as given in the issue example has a presentation role - we should expect this lib (and RTL's getByRole by extension) should match that element with getByRole("presentation").

Uncertain what the changes in https://github.com/A11yance/aria-query/pull/447/files#diff-643c621e212a40fbb0863ef49bc5bdfa2a95a406f7bdf2afb4ec3ebd0d16dabf have done to this effect 🤔

@jlp-craigmorten
Copy link
Contributor

See also conversation in testing-library/dom-testing-library#1235

@jlp-craigmorten
Copy link
Contributor

jlp-craigmorten commented Jun 15, 2023

Test cases (with aria-query pinned to 5.2.1):

import "react";
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";

describe("W3C Recommendations: https://www.w3.org/TR/html-aria/#docconformance", () => {
  test("img with no alt has an img role", async () => {
    render(<img src="#" />);

    expect(await screen.queryByRole("img")).not.toBeNull(); // Passes ✅
  });

  test("img with an empty alt has a presentation role", async () => {
    render(<img src="#" alt="" />);

    expect(await screen.queryByRole("presentation")).not.toBeNull(); // Passes ✅
  });

  test("img with a non-empty alt has an img role", async () => {
    render(<img src="#" alt="Alternative Text" />);

    expect(await screen.queryByRole("img")).not.toBeNull(); // Fails ❌
  });
});

@jessebeach
Copy link
Member

@jlp-craigmorten thank you for this report. I'll look into the issue this weekend and get a fix up.

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 a pull request may close this issue.

4 participants