Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onKeyDown = (event: KeyboardEvent) => {
if (event.metaKey || event.altKey || event.shiftKey || event.ctrlKey) {
return;
}
const target = event.target as HTMLElement;
const role = target.getAttribute("role");
const targetIsMenu = target === menu;
const targetIsMenuItem =
role &&
role.indexOf("menuitem") >= 0 &&
closest(target, "[role=menu],[role=menubar]") === menu;
if (!targetIsMenu && !targetIsMenuItem) return;
if (/^[a-z0-9_-]$/i.test(event.key)) {
event.stopPropagation();
event.preventDefault();
setKeys(k => `${k}${event.key}`);
}
};
React.useEffect(() => {
const dialog = dialogRef.current;
if (!dialog || !options.visible) return;
portalRef.current = closest(dialog, Portal.__selector) as HTMLElement;
}, [dialogRef, options.visible]);