@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
28 lines (27 loc) • 923 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useListKeyboardHandler = void 0;
const common_1 = require("@workday/canvas-kit-react/common");
const useCursorListModel_1 = require("./useCursorListModel");
const keyUtils_1 = require("./keyUtils");
/**
* This elemProps hook is used to attach keyboard events to handle keyboard navigation
*
* ```ts
* const useMyItem = composeHooks(
* useListKeyboardHandler, // adds keyboard support support
* useListItemRegister
* );
```
*/
exports.useListKeyboardHandler = (0, common_1.createElemPropsHook)(useCursorListModel_1.useCursorListModel)(model => {
const isRTL = (0, common_1.useIsRTL)();
return {
onKeyDown(event) {
const handled = (0, keyUtils_1.keyboardEventToCursorEvents)(event, model, isRTL);
if (handled) {
event.preventDefault();
}
},
};
});
;