我开始在我的 react 模式组件上收到此警告:
Warning: Failed propType: Required prop
contentLabel
was not specified inModal
.
它不会阻止模态正常工作,我只是在开发工具控制台中看到警告。我可以通过指定一些随机字符串来传递这个 Prop ,但我不明白它的实际用途,以及为什么需要它。
最佳答案
contentLabel
提高了可访问性。您可能没有注意到它,但在某些情况下,此 prop
可以帮助您的用户了解模式的含义。来自 their repository :
The Modal object has two required props:
isOpen
to render its children.contentLabel
to improve a11y, sincev1.6.0
.
contentLabel
的值设置为 aria-label
在模态元素上。这有帮助assistive technology ,就像屏幕阅读器一样,为原本匿名的元素添加标签。例如,有视力障碍的人在添加后可以更理解您的模式。
关于reactjs - 为什么react-modal需要prop contentLabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41345442/