The KendoReact Keyboard Navigation functionality helps you to implement keyboard navigation in a React application.
This is a Free React Keyboard NavigationThe KendoReact Keyboard Navigation is free to use, including in production—no sign-up or license required. Check out all120+ free and premium UI components in the enterprise-grade KendoReact library.With the KendoReact Keyboard Navigation, you no longer have to spend time thinking about events handling and managing the focus in your application.
To enable the basic navigation with the left and right arrow keys:
keydown
event handler to the root element.root
—The ref object of the root DOM element.selectors
—An array of CSS selectors, from which the navigation elements will be queried from the root element (e.g.root.querySelectorAll(selectors.join(','))
). Make sure their order matches the navigation elements order.keyboardEvents
—Add akeydown
object withArrowLeft
andArrowRight
handlers. The handlers' names match thekey
property of theKeyboardEvent.tabIndex
—The tabIndex that the Navigation will use.keydown
event to the root element.The code snippet below shows how to configure basic navigation with the left and right arrows for a set of button components.
const navigation=React.useMemo(()=>newNavigation({ root,selectors:['.k-button-group > button'],keyboardEvents:{keydown:{ArrowRight:(target, nav, ev)=>{ ev.preventDefault(); nav.focusNext(target);},ArrowLeft:(target, nav, ev)=>{ ev.preventDefault(); nav.focusPrevious(target);}}},tabIndex:0}),[]);
The following example demonstrates the above Keyboard Navigation configuration in action.
Use theleft
andright
arrow keys to navigate.
The next example builds upon thebasic configuration by adding the following:
Space
key allows you to expand and collapse the TreeList items.Use theup
anddown
arrow keys to navigate.
To implement the Keyboard Navigation for an HTML table, use additional functions that define which DOM element in the table to focus on every subsequent user action.
Use theup
,down
,left
andright
arrow keys to navigate.
The Keyboard Navigation is part of theKendoReact Common Utilities component library. The procedures for installing, importing, and using the Common Utilities are identical for all components in the package. To learn how to use the Keyboard Navigation and the rest of the Common Utilities, see the
Getting Started with the KendoReact Common Utilities
guide.