最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using aria attributes on elements in react - Stack Overflow

programmeradmin3浏览0评论

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. Remove these props from the element. For details, see in div (created by Constructor) in 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.

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. Remove these props from the element. For details, see in div (created by Constructor) in 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.

Share Improve this question edited Mar 22, 2018 at 6:10 Rizvan 5511 gold badge7 silver badges20 bronze badges asked Aug 17, 2016 at 14:06 user99999user99999 2,0245 gold badges27 silver badges50 bronze badges 3
  • 3 try 'aria-hidden' instead of ariaHidden – Karol Klepacki Commented Aug 17, 2016 at 14:12
  • Likewise use data-backdrop instead of dataBackdrop. Data attributes have to start with the data- prefix for React to pass them through. – Ross Allen Commented Aug 17, 2016 at 16:54
  • 2 It seems perverse for React to issue warnings against hyphenated prop names, and in other cases warn against camel-cased prop names! Why not be consistent and require ariaHidden etc? – pwray Commented Oct 24, 2017 at 3:54
Add a ment  | 

1 Answer 1

Reset to default 11

Instead of camel case, use hyphens to define aria attributes as described in React's docs:

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

评论列表(0)

  1. 暂无评论