Replies: 2 comments
-
|
I have this feature but not with conform, I use a classic form. Anyway, the form element triggers the submit event, so you could give it a try : const formRef = React.useRef<HTMLFormElement | null>(null);
<form ... ref={formRef} />
React.useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (
event.shiftKey &&
event.key === "Enter" &&
document.activeElement?.nodeName === "TEXTAREA"
) {
formRef.current?.dispatchEvent(
new Event("submit", { cancelable: true, bubbles: true }),
);
}
};
document.addEventListener("keydown", handleKeyDown);
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
}, []);You may want to change the "TEXTAREA" nodeName to fit your needs. Let me know if this helps you. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
There are a few ways to trigger a form submit on the dom.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Never though I would ask this question, but seems like every React version and library combo has it's quirks 😁
So I have a form like
I want to submit form when input is focused and command + Enter pressed. Tried to listen
onKeyDownand then triggerform.onSubmitbut it throws error that it expects form event, not submit...Beta Was this translation helpful? Give feedback.
All reactions