react-a11y icon indicating copy to clipboard operation
react-a11y copied to clipboard

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

Open k1sul1 opened this issue 6 years ago • 3 comments

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.

k1sul1 avatar Mar 16 '18 14:03 k1sul1

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.

erin-doyle avatar Sep 26 '18 14:09 erin-doyle

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

JayaKrishnaNamburu avatar Feb 15 '19 08:02 JayaKrishnaNamburu

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~~

jmk-198xtsuga avatar Oct 31 '20 04:10 jmk-198xtsuga