reactjs/react-a11y

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

Open

#144 建立於 2018年3月16日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)JavaScript (147 fork)batch import
Hacktoberfestbug

倉庫指標

Star
 (2,334 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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.

貢獻者指南