"The `alt` prop cannot be empty string if role="presentation" is not set" when it is
Opened this issue · 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.
And there's nothing in remaining
that would overwrite role
or alt
.
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.
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
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