UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

24 lines (23 loc) 731 B
import { createElemPropsHook } from '@workday/canvas-kit-react/common'; import { useCursorListModel } from './useCursorListModel'; import { keyboardEventToCursorEvents } from './keyUtils'; /** * This elemProps hook is used to attach keyboard events to handle keyboard navigation * * ```ts * const useMyItem = composeHooks( * useListKeyboardHandler, // adds keyboard support support * useListItemRegister * ); ``` */ export const useListKeyboardHandler = createElemPropsHook(useCursorListModel)(model => { return { onKeyDown(event) { const handled = keyboardEventToCursorEvents(event, model); if (handled) { event.preventDefault(); } }, }; });