Message edit
Inline editing of a user message. It grows with the text, warns how many replies saving will replace, and never saves in the middle of IME composition.
On this page
Editing warns how many replies it replaces.
Installation
Usage
import { MessageEdit } from "@/components/ui/chatcn/message-edit"
<Message from="user">
{editing ? (
<MessageEdit
defaultValue={text}
replies={repliesAfter(message.id)}
onSave={(next) => editMessage(message.id, next)}
onCancel={() => setEditing(false)}
/>
) : (
<MessageContent>{text}</MessageContent>
)}
</Message>Props
| Prop | Type | Notes |
|---|---|---|
defaultValue | string | The text to start from |
onSave | (text) => void | Trimmed text. Saving unchanged text cancels |
onCancel | () => void | |
replies | number | Replies that saving replaces. Shows the warning above 0 |
maxHeight | number | Grow limit in px. Defaults to 40% of the viewport |
Keyboard
| Key | Action |
|---|---|
Enter | Save, unless an IME is composing |
Shift Enter | New line |
Esc | Cancel |
Accessibility
- The field is focused on open with the caret at the end.
- The replaces-replies warning is linked to the field with
aria-describedby. - Enter checks
isComposingand key code 229, so Japanese, Chinese and Korean input work in every browser.
Motion
None. The field resizes directly as you type; an animated height would lag behind the caret.