init
This commit is contained in:
commit
a04776256d
56 changed files with 6808 additions and 0 deletions
21
lib/hooks/use-command-enter-submit.tsx
Normal file
21
lib/hooks/use-command-enter-submit.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import type { RefObject } from "react";
|
||||
import { useRef } from "react";
|
||||
import { isModifierPressed } from "./is-modifier-pressed";
|
||||
|
||||
export function useCmdEnterSubmit(): {
|
||||
formRef: RefObject<HTMLFormElement>;
|
||||
onKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
||||
} {
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
|
||||
const handleKeyDown = (
|
||||
event: React.KeyboardEvent<HTMLTextAreaElement>
|
||||
): void => {
|
||||
// Capture `⌘`|Ctrl + Enter
|
||||
if (isModifierPressed(event) && event.key === "Enter") {
|
||||
formRef.current?.requestSubmit();
|
||||
}
|
||||
};
|
||||
|
||||
return { formRef, onKeyDown: handleKeyDown };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue