使用材料UI的React.js应用程序的键盘快捷键?
我想在React.js项目中实现键盘快捷键,我正在使用材料UI组件。
浏览器支持的默认键是选项卡,移位,输入和箭头键。
我想实现功能键,以导航到我的Web应用程序的特定区域。
I want to implement a keyboard shortcut in react.js project i am using material UI components.
The default keys which browser supports are tab, shift, enter and arrow keys.
I want to implement function keys to navigate into specific area of my web application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请确保您在区域中使用正确的HTML元素,例如
< main>
或< ainge>
or 或< footer> ,并且他们通过
aria-label
或aria-labelleddy
携带可访问的名称。页面上某个区域的咏叹调角色是地标:> aria> aria:landmark在mdn上的角色
aria> aria 然后
,您可以考虑使用 skip links ,允许键盘用户直接通过这些地标导航到这些地标 tab 的of。这也可能使您有机会传达您提供的捷径。
快捷方式
在提供快捷方式时,重要的是不使用用户平台上已经使用的快捷方式。这些仍应按预期工作。
另外,如果您使用的是单个角色快捷方式,则需要提供一种机制来更改这些快捷方式,如果它们在快捷方式中干扰其他捷径:
理解成功标准2.1.4:字符密钥快捷方式
实现快捷方式的一种方法是本机
accesskey 属性,但是浏览器和浏览器和浏览器和在支持下不是很好。
webaim上的accessKey
通常,这些键通常用于交互式元素,而不是用于地标。因此,如果您想集中地标,则需要首先将其集中
在 keydown事件,然后依次将相应的地标聚焦。
由于这仅在DOM上起作用,因此您需要将此处理程序绑定到词根,而不是纪录片,或者呈现应用程序的位置。
Web应用程序和选项卡
如果您在应用程序中实现了组件的箭头密钥导航,则用户可以通过 tab 来达到地标/组件,并实现它可能很快跳过链接或快捷方式可能不太有趣。
First, make sure that you are using the right HTML elements for your areas, like
<main>
or<region>
or<footer>
, and that they carry an accessible name by means ofaria-label
oraria-labelledby
. The ARIA role for an area on a page is landmark:ARIA: landmark role on MDN
Use Skip Links
Then, you might consider using Skip Links that allow keyboard users to navigate to these landmarks directly by means of tab. This might also give you an opportunity to communicate the Shortcuts you are providing.
Shortcuts
When providing shortcuts, it’s important to not use shortcuts that are already in use on the user’s platform. These should still work as expected.
Also, if you are using single character shortcuts, you need to provide a mechanism to change these shortcuts, should they interfere with other AT shortcuts:
Understanding Success Criterion 2.1.4: Character Key Shortcuts
One way to implement shortcuts is the native
accesskey
attribute, but browser and AT support is not great.Accesskey on WebAIM
Usually, these keys are used for interactive elements, not for landmarks. So if you want to focus a landmark, you will need to make it focusable first:
Then you can bind on the keydown event and focus the corresponding landmark in turn.
As this only works on the DOM, you will need to bind this handler either to your root instead of the documentElement, or where you render your application.
Web Applications and tab
If you implemented arrow key navigation for components in your application, it might be pretty fast for users to reach a landmark/component by means of tab, and implementing skip links or shortcuts might be less interesting.