Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Menubar
- Message
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Shared
- Artifact
- Audio Player
- Canvas
- Chain of Thought
- Checkpoint
- Code Block
- Commit
- Connection
- Context
- Controls
- Edge
- Environment Variables
- Mic Selector
- Model Selector
- Node
- Node Toolbar
- Open in Chat
- Panel
- Plan
- Prompt Input
- Queue
- Reasoning
- Sandbox
- Schema Display
- Shimmer
- Snippet
- Sources
- Speech Input
- Stack Trace
- Suggestion
- Tool
- Transcription
- Web Preview
Hooks
Resources
useEnterSubmit
Enter to submit, Shift+Enter for newline.
A React hook for chat-style textareas: pressing Enter submits the form, while Shift+Enter inserts a newline. Ignores keystrokes during IME composition.
Installation
pnpm dlx shadcn@latest add @frontal-labs/use-enter-submit
Usage
import { useEnterSubmit } from "@/hooks/use-enter-submit";
function ChatForm() {
const { formRef, onKeyDown } = useEnterSubmit();
return (
<form
ref={formRef}
onSubmit={(e) => {
e.preventDefault();
// send message
}}
>
<textarea onKeyDown={onKeyDown} placeholder="Type a message…" />
<button type="submit">Send</button>
</form>
);
}onKeyDown calls formRef.current?.requestSubmit(), so native validation and onSubmit still run.
API
function useEnterSubmit(): {
formRef: RefObject<HTMLFormElement>;
onKeyDown: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
};Return value
| Property | Type | Description |
|---|---|---|
formRef | RefObject<HTMLFormElement> | Attach to the <form> to submit. |
onKeyDown | (event) => void | Attach to the <textarea>. Submits on plain Enter, ignores Shift+Enter and IME composition. |
On This Page