import { RovingTabIndexProvider } from "@getoutline/react-roving-tabindex"; import { observer } from "mobx-react"; import * as React from "react"; type Props = Omit, "children"> & { children: () => React.ReactNode; onEscape?: (ev: React.KeyboardEvent) => void; items: unknown[]; ref?: React.Ref; }; function ArrowKeyNavigation({ children, onEscape, items, ref, ...rest }: Props) { const handleKeyDown = React.useCallback( (ev: React.KeyboardEvent) => { if (onEscape) { if (ev.nativeEvent.isComposing) { return; } if (ev.key === "Escape" || ev.key === "Backspace") { ev.preventDefault(); onEscape(ev); } if ( ev.key === "ArrowUp" && // If the first item is focused and the user presses ArrowUp ev.currentTarget.firstElementChild === document.activeElement ) { onEscape(ev); } } }, [onEscape] ); return (
{children()}
); } export default observer(ArrowKeyNavigation);