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

"The alt prop cannot be empty string if role="presentation" is not set" when it is #144

Open
k1sul1 opened this issue Mar 16, 2018 · 3 comments

Comments

@k1sul1
Copy link

k1sul1 commented Mar 16, 2018

With the following code, I get the error presented in the title. Not sure if this is a bug or what, but it sure is annoying.

// rest of it isn't relevant
const image = getImageData(data, size)
const { src, alt } = image

const a11yProps = { alt }

if (alt.length === 0) {
  a11yProps.alt = ''
  a11yProps.role = 'presentation'
}

// eslint-disable-next-line jsx-a11y/alt-text
return <img src={src} {...a11yProps} {...remaining} />

If I remove the alt from the props object entirely, more errors appear. I'm pretty sure I could work around this with two returns, but I'd rather not do that.

image

And there's nothing in remaining that would overwrite role or alt.

@erin-doyle
Copy link
Collaborator

Yes this does look like a bug. It looks like the "The img does not have an alt prop..." rule is not checking for role="presentation". We can look into this.

@JayaKrishnaNamburu
Copy link

Hi, I tried replicating the same but the rule is working fine when we just specify the role and alt like below
<img src={logo} className="App-logo" alt="" role="Testing bug" /> throwing this warning in terminal
Elements with ARIA roles must use a valid, non-abstract ARIA role jsx-a11y/aria-role

But when we pass the props using an object as below
let allyProps = {}; allyProps.alt = ''; allyProps.role = 'dsfkdsf';

<img src={logo} className="App-logo" {...allyProps} /> then it throws the following warning

img elements must have an alt prop, either with meaningful text, or an empty string for decorative images jsx-a11y/alt-text

But the DOM elements looks same in both the scenarios

screenshot 2019-02-15 at 2 21 55 pm

@jmk-198xtsuga
Copy link

jmk-198xtsuga commented Oct 31, 2020

EDIT: I just looked back over to the Readme for react-a11y to see the deprecation notice, will not pursue this issue.
I'm down to explore this issue, I'll test it out to see if it still exists, and if so, get digging on why the warning is getting thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants