diff --git a/src/key-handler/index.tsx b/src/key-handler/index.tsx index 3bf074e..f814c07 100644 --- a/src/key-handler/index.tsx +++ b/src/key-handler/index.tsx @@ -20,6 +20,7 @@ type KeyboardEventHandler = (event: KeyboardEvent) => void; interface LeafProp { handler: KeyboardEventHandler; + preventDefault?: boolean; } interface NodeProp { @@ -35,6 +36,7 @@ export function KeyHandler(props: KeyHandlerProps) { const [shouldRenderChildren, setShouldRenderChildren] = useState(false); const handler = "handler" in rest ? rest.handler : null; const children = "children" in rest ? rest.children : null; + const preventDefault = "preventDefault" in rest ? rest.preventDefault : false; useLayoutEffect( function handlerLifecycle() { @@ -44,6 +46,10 @@ export function KeyHandler(props: KeyHandlerProps) { }; } const wrappedHandler = (e: KeyboardEvent) => { + if (preventDefault) { + e.preventDefault(); + } + if (handler) { handler(e); focusedStack.tearDown();