@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
47 lines • 2.26 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { getIsRtl } from '@awsui/component-toolkit/internal';
import { KeyCode } from '../keycode';
import { isHTMLElement, isSVGElement } from './dom';
export function isEventLike(event) {
return isHTMLElement(event.currentTarget) || isSVGElement(event.currentTarget);
}
export default function handleKey(event, { onActivate, onBlockEnd, onBlockStart, onDefault, onEnd, onEscape, onHome, onInlineEnd, onInlineStart, onPageDown, onPageUp, }) {
switch (event.keyCode) {
case KeyCode.down:
onBlockEnd === null || onBlockEnd === void 0 ? void 0 : onBlockEnd();
break;
case KeyCode.end:
onEnd === null || onEnd === void 0 ? void 0 : onEnd();
break;
case KeyCode.enter:
case KeyCode.space:
onActivate === null || onActivate === void 0 ? void 0 : onActivate();
break;
case KeyCode.escape:
onEscape === null || onEscape === void 0 ? void 0 : onEscape();
break;
case KeyCode.home:
onHome === null || onHome === void 0 ? void 0 : onHome();
break;
case KeyCode.left:
getIsRtl(event.currentTarget) ? onInlineEnd === null || onInlineEnd === void 0 ? void 0 : onInlineEnd() : onInlineStart === null || onInlineStart === void 0 ? void 0 : onInlineStart();
break;
case KeyCode.pageDown:
onPageDown === null || onPageDown === void 0 ? void 0 : onPageDown();
break;
case KeyCode.pageUp:
onPageUp === null || onPageUp === void 0 ? void 0 : onPageUp();
break;
case KeyCode.right:
getIsRtl(event.currentTarget) ? onInlineStart === null || onInlineStart === void 0 ? void 0 : onInlineStart() : onInlineEnd === null || onInlineEnd === void 0 ? void 0 : onInlineEnd();
break;
case KeyCode.up:
onBlockStart === null || onBlockStart === void 0 ? void 0 : onBlockStart();
break;
default:
onDefault === null || onDefault === void 0 ? void 0 : onDefault();
break;
}
}
//# sourceMappingURL=handle-key.js.map