import { RovingTabIndexProvider } from "@getoutline/react-roving-tabindex"; import { observer } from "mobx-react"; import * as React from "react"; type Props = React.HTMLAttributes & { children: () => React.ReactNode; onEscape?: (ev: React.KeyboardEvent) => void; items: unknown[]; }; function ArrowKeyNavigation( { children, onEscape, items, ...rest }: Props, ref: React.RefObject ) { const handleKeyDown = React.useCallback( (ev: React.KeyboardEvent) => { if (onEscape) { if (ev.nativeEvent.isComposing) { return; } if (ev.key === "Escape") { 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(React.forwardRef(ArrowKeyNavigation));