Skip to content

alt attribute can't be empty #1313

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

Closed
Tasiobg opened this issue May 31, 2024 · 1 comment
Closed

alt attribute can't be empty #1313

Tasiobg opened this issue May 31, 2024 · 1 comment

Comments

@Tasiobg
Copy link

Tasiobg commented May 31, 2024

Since this update #1241 the alt attribute for the img role can't be empty.
My understanding is that the alt attribute should be present but in some cases like decorative images it should be empty, some info here

Is this an issue or an intended change?

Works

it(`testcase`, async () => {
    render(
      <div>
        <img src="url" alt="alt text" />
      </div>,
    );

    expect(screen.getByRole('img')).toBeInTheDocument();
  });

Fail

it(`testcase`, async () => {
    render(
      <div>
        <img src="url" alt="" />
      </div>,
    );

    expect(screen.getByRole('img')).toBeInTheDocument();
  });
@MatanBobi
Copy link
Member

Hi @Tasiobg :)
An image with an empty alt attribute has a role of none or presentation (based on the ARIA spec):
image

So this works as expected.
Thanks for the report.

@testing-library testing-library deleted a comment from github-actions bot May 31, 2024
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

No branches or pull requests

2 participants