javascript - 如何在 TypeScript 中设置 ariaLabel 值
问题描述
我有一个打字稿反应应用程序,我正在尝试动态设置 ariaLabel 值,ESLint 正在抱怨Property 'ariaLabel' does not exist on type 'HTMLButtonElement'
。
我尝试了多种类型,但没有一个具有 ariaLabel 属性,我不想使用<any>
const ref = useRef<HTMLButtonElement>(null);
const buttonRef = ref.current.querySelector<HTMLButtonElement>(`[aria-label="${buttonAriaLabel}"]`);
buttonRef.ariaLabel = eventLabel; // here is the error
解决方案
aria-label 是一个属性,因此您可以更改代码
buttonRef.setAttribute("aria-label", eventLabel);
推荐阅读
- android - 我无法通过 taskSnapshot.getStorage().getDownloadUrl().toString() 方法加载我的图像,请告诉我是否有任何建议
- splunk-query - 我可以使用什么正则表达式命令在 splunk 中创建一个字段
- axios - 使用 axios GET 请求到端口 81(甚至是 js 本机 fetch)
- javascript - 比较 userInput JavaScript
- javascript - DataTable 不显示 AJAX JSON 数据
- vim - Vim 自动完成功能无法使用组合键
- python - 如何修复 ValueError?
- c++ - noexcept + declval 在 MSVC 下编译失败
- c - 检查 sqlite3 表列是否已填充
- flutter - 如何在同步融合条形图中放置自定义形状的条形图,颤动?