【发布时间】:2021-07-27 13:30:01
【问题描述】:
可访问性指南是在组件发布之前发明的,所以他们总是说标签用于标识 <input> 或 <textarea> 等表单控件。当我有一个复杂的 Angular / React / .. . 像表单控件一样的组件?
想象一个<custom-select> 呈现输入并将项目添加到列表中。生成的 html 如下所示:
<custom-select ....>
<input ...>
</custom-select>
当我在输入中输入内容并按 Enter 键时,它会将该条目添加到列表中并再次呈现输入,例如:
<custom-select ....>
<span>What I typed</span>
<input ...>
</custom-select>
当然,如果我在输入中输入其他内容并按下回车键,它就会被添加到列表中:
<custom-select ....>
<span>What I typed</span>
<span>Something else</span>
<input ...>
</custom-select>
如果我们想在表单中使用这个自定义组件,我们希望像任何其他表单项一样为其添加标签,p.e:
<label for="foo">Foo</label>
<input id="foo" type="text">
<label for="select">Select a country</label>
<custom-select id="select"></custom-select>
这甚至是有效的 a11y 吗? Wave 工具会抱怨孤儿标签,而 ax 什么也没说。那么,我们可以使用普通的旧label 来标记自定义组件以实现可访问性目的吗?我们需要在此处放置标签以保持一致性,但需要可访问。
如果我能做到这一点,custom-select 也会呈现一个输入。该输入需要自己的标签或 aria-label,对吗?
【问题讨论】:
标签: html reactjs angular accessibility