reactjs - 将样式化的 span 制作为 Emoji 组件,我收到警告,因为我没有将 emoji 包装在 span 中。这是如何运作的?
问题描述
根据警告,从可访问性的角度来看,我这样做的方式并不理想。但是应该怎么做更好呢,组件里面有一个role,aria-label和span。我该如何做对?
创建警告的组件之一:
<span
type='button'
onClick={() => setShowShoppingList(!showShoppingList)}>
<Emoji ariaLabel="arrow-down">↓</Emoji> Reasons to Celebrate <Emoji ariaLabel="champagne-bottle"></Emoji>
</span>
样式化组件组件:从“styled-components”导入样式
export const Emoji = styled.span.attrs(({ariaLabel}) =>({
role: "img",
"aria-label": ariaLabel,
}))`
font-size: 50px;
`
警告:第 23:74 行:表情符号应包含在 中,具有 role="img",并具有使用 aria-label 或 aria-labelledby jsx-a11y/accessible-emoji 的可访问描述 第 31:13 行:应包含表情符号在 中,具有 role="img",并具有使用 aria-label 或 aria-labelledby jsx-a11y/accessible-emoji 的可访问描述
解决方案
推荐阅读
- r - R - rvest - 从 p 中抓取所有数据(IMDb 页面上的目录)
- c# - 在 C# 中查找第 N 列分隔符之后的数据
- reactjs - 如何创建一个返回承诺以响应惰性的组件?
- python - 如何在没有错误语句的情况下退出 python 程序?
- mysql - Sql 语句在 Maria DB 和 Mysql 上得到不同的结果
- python-3.x - 如何索引我的 x 和 y 变量,以便一次获得一个图?
- android - AAPT:错误:找不到资源 android:attr/android:progressBarStyleSmall
- java - 所有数据结构都有抽象数据类型吗?
- jquery - 如何通过ajax从url重新加载数据
- android - 错误:在您的 PATH 中找不到 native-run。(离子 4)