GhostTextarea
GhostTextarea is an unstyled native multiline text control with Vue v-model, form participation, and optional auto-resize. Import it from @ghostvue/vue for headless use, or from @ghostvue/themes for the default field treatment.
Auto-resizing, readonly, and disabled GhostTextarea fields with live word count.
The release notes composer pairs themed GhostTextarea with GhostField: the summary auto-resizes as you type and validates on publish, the deployment checklist stays focusable as readonly, and the deprecation notice is disabled.
Basic use
Give each textarea a label with <label for> and a matching id. Use GhostField to connect the label, hint, and validation message around a themed textarea.
Disabled, readonly, invalid, and required
Disabled, readonly, invalid, and required fields.
Disabled removes the field from tab order and form submit. Readonly keeps it focusable. Invalid is consumer-owned and does not render error copy.
Auto-resize
Grows with content until maxRows.
Measurement runs after mount, on input, and when the field's width changes. Server HTML keeps the rows height and never writes an inline height, so hydration stays aligned. maxRows caps growth; leftover lines scroll.
Native forms
Native form submission of the textarea value.
The control is a real <textarea>. Enter inserts a newline and does not submit. Use a separate submit button, or opt in to submit on Enter.
Submit on Enter
Comment composer where Enter sends and Shift+Enter adds a line, with a visible key hint and read-only while sending.
Set submit-on-enter for chat composers and comment boxes. Enter submits the textarea's form with requestSubmit(), which runs constraint validation and fires the form's submit event (or GhostForm's submit emit), exactly as the submit button does. Shift+Enter still inserts a newline. The textarea keeps focus. There is no extra event: handle the send in the form's submit handler, and ignore an empty draft there.
- Show the keys. A screen-reader user cannot see that
Entersends. Connect a short visible hint such as "Enter to send, Shift+Enter for a new line" througharia-describedby, as the example does. - Read-only while sending. Set
readonlywhile the request is in flight. A read-only textarea ignoresEnter, so a second press cannot resend. - Typing in other languages.
Enterthat confirms an input method (IME) candidate never submits, and holdingEntersends only once. - Keep
Enterfor a popup. Your@keydownruns first. CallpreventDefault()there (for example@keydown.enter.preventwhile a mention list is open) and the textarea does not submit. - Touch keyboards. Most virtual keyboards have no
Shift+Enter, so touch users cannot add a newline. Passenterkeyhint="send"so the key reads "Send", and bindsubmit-on-enterto a fine-pointer media query if your app needs newlines on touch devices. - The textarea must be inside a
<form>orGhostForm. Without one,Enterinserts a newline and a development warning (GHOST029) is logged.
For a complete chat view built on this, see GhostChatMessage.
Themed use
Visual size on the @ghostvue/themes wrapper.
Importing the themed component loads the default stylesheet. Visual props exist only on this wrapper:
@ghostvue/themes adds these to the headless GhostTextarea API, which it forwards:
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | "md" | Control size. The default omits data-size so CSS can treat a missing hook as md. |
You can also import the stylesheet and wrap unstyled textareas in .ghost-theme when you want a region of headless components to pick up the defaults. See the default theme guide.
Customize with headless controls
Import from @ghostvue/vue to provide your own styles, or bind the composable to a native element.
Labeled native textarea with v-model.
Same contract as GhostTextarea, applied to a native host.
Component refs
Template refs expose element, focus, and blur.
The ref exposes element, focus(options?), and blur(). Before mount and after unmount, element is null and the methods are safe no-ops.
Styling
The unstyled component renders one native <textarea> with class ghost-textarea, data-part="root", optional data-state (disabled, readonly, or invalid), and data-auto-resize when auto-resize is on.
.ghost-textarea[aria-invalid='true'] {
/* Invalid chrome. Prefer aria-invalid so it still applies when readonly. */
}API
| Prop | Type | Default | Description |
|---|---|---|---|
autoResize | boolean | false | Grow the field with its content after mount. Off by default so native resize and a fixed rows height remain the ordinary path. |
defaultValue | string | "" | Initial uncontrolled value. Later changes are ignored. |
disabled | boolean | false | Native disabled semantics: not focusable, not editable, omitted from form submit. |
invalid | boolean | false | Sets aria-invalid=true. Error copy belongs to Field or the surrounding form. |
maxRows | number | — | Auto-resize ceiling in rows. Ignored unless autoResize is true. When set below rows, rows wins as both min and max. |
modelValue | string | — | Controlled value. Omit for uncontrolled mode; an empty string is a defined empty value. |
readonly | boolean | false | Native readonly semantics: focusable and submitted, but the user agent rejects edits. |
required | boolean | false | Native required constraint. Validation messaging stays with the form. |
rows | number | 2 | Native rows. Matches the HTML default. Auto-resize uses this as the minimum height. |
submitOnEnter | boolean | false | Enter submits the textarea's form owner with requestSubmit() instead of inserting a newline; Shift+Enter still inserts one. Ignored during IME composition, while read-only, and for held-key repeats. Without a form owner, Enter stays native and a development warning (GHOST029) is logged once. |
v-model is a string (modelValue / update:modelValue). Native textarea attributes and listeners fall through to the root, including id, name, placeholder, maxlength, and Field-ready aria-describedby / aria-errormessage. The component does not generate ids.
Accessibility and environment behavior
The root is a native textarea. Keyboard behavior is platform-native: printable keys insert text, Enter inserts a newline (or submits the form with submitOnEnter), Shift+Enter always inserts a newline, and Tab leaves the field. Disabled fields are not in sequential tab order; readonly fields are.
SSR markup is deterministic from props and the current value. Auto-resize does not read browser globals during setup.
See the GhostTextarea specification for the complete behavior and compatibility contract.