简体   繁体   English

在反应中对元素使用 aria 属性

[英]Using aria attributes on elements in react

I have the following render method:我有以下渲染方法:

render: function () {
  return (
    React.createElement('div', {className: 'modal', id: 'errorModal', tabIndex: '-1', role: 'dialog', ariaHidden: 'true', dataBackdrop: 'false', style: {marginTop: '30px'}}, 'text')
  )
}

That gives me error:这给了我错误:

react.js:20541 Warning: Unknown props ariaHidden , dataBackdrop on tag. react.js:20541 警告:未知道具ariaHiddendataBackdrop上的dataBackdrop Remove these props from the element.从元素中删除这些道具。 For details, see in div (created by Constructor) in Constructor详情见Constructor中的div(由Constructor创建)

How could I solve this?我怎么能解决这个问题? Documentation says that I can use these attributes.文档说我可以使用这些属性。 Lowercase does not work either.小写也不起作用。 I don't want to use jsx.我不想使用 jsx。

Instead of camel case, use hyphens to define aria attributes as described in React's docs :使用连字符来定义aria属性,而不是驼峰式大小写,如React 文档中所述

render: function () {
  return (
    React.createElement('div', {className: 'modal', id: 'errorModal', tabIndex: '-1', role: 'dialog', 'aria-hidden': 'true', dataBackdrop: 'false', style: {marginTop: '30px'}}, 'text')
  )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 aria-expanded 和 aria-haspopup 属性是否适用于<select />元素? - Does the aria-expanded and aria-haspopup attributes apply to <select /> elements? Aria属性不会添加到结果中 - Aria attributes not be added to results 如何使用jQuery选择具有特定ARIA值的所有元素? - How to select all elements with particular ARIA value using jQuery? React-bootstrap选项卡:警告:在`的上下文中 <TabContainer> `,` <NavItem> 赋予s生成的id和aria-controls属性 - React-bootstrap tabs: Warning: In the context of a `<TabContainer>`, `<NavItem>`s are given generated `id` and `aria-controls` attributes 使用 React Hooks 设置 aria-expanded 的布尔值 - Setting the boolean value of aria-expanded using React Hooks 查找所有display:none属性,并使用JavaScript添加aria-hidden属性 - Find all display:none attributes and add in aria-hidden attribute using JavaScript 第三方滑块添加具有“类”等属性的动态元素。 我正在使用反应 - third party slider adding dynamic elements with attributes like 'class'. I am using react 我应该使用JavaScript更新aria- *属性吗? - Should I be updating aria-* attributes with JavaScript? 使用JS添加WAI-ARIA属性 - Adding WAI-ARIA attributes with JS 如何将aria属性设置为highcharts工具提示 - How to set aria attributes to highcharts tooltips
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM