Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/key-handler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type KeyboardEventHandler = (event: KeyboardEvent) => void;

interface LeafProp {
handler: KeyboardEventHandler;
preventDefault?: boolean;
}

interface NodeProp {
Expand All @@ -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() {
Expand All @@ -44,6 +46,10 @@ export function KeyHandler(props: KeyHandlerProps) {
};
}
const wrappedHandler = (e: KeyboardEvent) => {
if (preventDefault) {
e.preventDefault();
}

if (handler) {
handler(e);
focusedStack.tearDown();
Expand Down