PrimeFaces 使禁用的单选按钮可选项卡化
我们对 SelectOneRadio 元素使用修改后的渲染器。此呈现器不会在底层 上为禁用的 selectItem 设置
disabled
属性。 这是由于可访问性要求。每个元素(以及禁用的单选按钮)都必须可通过键盘突出显示和选项卡。
问题:单击项目标签时,表单参数将更新为禁用选项的值。禁用的元素也可以通过键盘进行检查。
知道如何在 上设置
disabled
属性,同时保持元素可选项吗?
We use a modified renderer for SelectOneRadio elements. This renderer does not set the disabled
attribute on the underlying <input />
for disabled selectItems.
This is due to an accessibility requirement. Every element (also the disabled radio buttons) must highlightable and tabbable via keyboard.
Problem: when the items label is clicked, the form parameter is updated to the value of the disabled option. The disabled element is also checkable via keyboard.
Any idea how I can set the disabled
attribute on the <input />
while keeping the elements tabbable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恐怕仅仅改变渲染器是不行的。与键盘导航相关的大部分功能都可以在
SelectOneRadio
组件的小部件代码中找到:https://github.com/primefaces/primefaces/blob/master/primefaces/src/main/resources/META-INF/resources/primefaces/forms/forms.selectoneradio.js
您可能需要重写那里的很多功能。
Simply changing the renderer won't do I'm afraid. Much of the functionality related to keyboard navigation can be found in the widget code of the
SelectOneRadio
component:https://github.com/primefaces/primefaces/blob/master/primefaces/src/main/resources/META-INF/resources/primefaces/forms/forms.selectoneradio.js
You will probably need to override a lot of functions there.
从定义上来说,这是一个无法满足的矛盾要求。禁用的元素不可聚焦,这是完全正常的。两者总是在一起。
所以基本上没有什么好的解决办法,因为需求是错误的。
然而,这里有一个有趣的事实:
onclick 事件也会在聚焦单选按钮时触发。您可以使用
event.preventDefault()
,这将阻止选择单选按钮。使用箭头键时无线电保持可聚焦。
当单选按钮通过箭头键聚焦时,它不会被选中。
然而,它不再可以使用选项卡进行聚焦,更糟糕的是,选项卡导航似乎完全被破坏了。甚至不再可能从“一”到“三”或返回。
因此,我不会推荐它,但是,错误的要求,错误的解决方案。
Windows 10 下的 Chrome、Firefox 和 Internet Explorer 似乎都同意相同的行为,太难了!
This is by definition a contradicting requirement that can't be satisfied. A disabled element isn't focusable and it's perfectly normal. Both always go together.
So there is basicly no good solution, as the requirement is wrong.
However, here's a little fun fact:
The onclick event is triggered upon focusing the radio button, too. You may use
event.preventDefault()
and this will prevent the radio button from being selected.The radio stays focusable when using arrow keys.
When the radio button is focused with arrow keys, then it doesn't become selected.
However, it iss no longer focusable using tab, and worse, tab navigation seem to be completely broken. It is even no longer possible to go from "One" two "Three" or back.
I would therefore not recommand it, but well, wrong requirement, wrong solution.
Chrome, Firefox and Internet Explorer under Windows 10 seem to all agree on that same behavior, tough !