Skip to content

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.

Release notes composer

Auto-resizing, readonly, and disabled GhostTextarea fields with live word count.

Release v2.14.3 notes

Published to the workspace changelog when deployment completes.

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 ​

States

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 ​

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 ​

Form

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 ​

Submit on Enter

Comment composer where Enter sends and Shift+Enter adds a line, with a visible key hint and read-only while sending.

Enter to send, Shift+Enter for a new line

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 Enter sends. Connect a short visible hint such as "Enter to send, Shift+Enter for a new line" through aria-describedby, as the example does.
  • Read-only while sending. Set readonly while the request is in flight. A read-only textarea ignores Enter, so a second press cannot resend.
  • Typing in other languages. Enter that confirms an input method (IME) candidate never submits, and holding Enter sends only once.
  • Keep Enter for a popup. Your @keydown runs first. Call preventDefault() there (for example @keydown.enter.prevent while 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. Pass enterkeyhint="send" so the key reads "Send", and bind submit-on-enter to a fine-pointer media query if your app needs newlines on touch devices.
  • The textarea must be inside a <form> or GhostForm. Without one, Enter inserts a newline and a development warning (GHOST029) is logged.

For a complete chat view built on this, see GhostChatMessage.

Themed use ​

Themed

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:

PropTypeDefaultDescription
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.

Basic Headless

Labeled native textarea with v-model.

Composable Headless

Same contract as GhostTextarea, applied to a native host.

Component refs ​

Component ref Headless

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.

css
.ghost-textarea[aria-invalid='true'] {
  /* Invalid chrome. Prefer aria-invalid so it still applies when readonly. */
}

API ​

PropTypeDefaultDescription
autoResizebooleanfalseGrow the field with its content after mount. Off by default so native resize and a fixed rows height remain the ordinary path.
defaultValuestring""Initial uncontrolled value. Later changes are ignored.
disabledbooleanfalseNative disabled semantics: not focusable, not editable, omitted from form submit.
invalidbooleanfalseSets aria-invalid=true. Error copy belongs to Field or the surrounding form.
maxRowsnumber—Auto-resize ceiling in rows. Ignored unless autoResize is true. When set below rows, rows wins as both min and max.
modelValuestring—Controlled value. Omit for uncontrolled mode; an empty string is a defined empty value.
readonlybooleanfalseNative readonly semantics: focusable and submitted, but the user agent rejects edits.
requiredbooleanfalseNative required constraint. Validation messaging stays with the form.
rowsnumber2Native rows. Matches the HTML default. Auto-resize uses this as the minimum height.
submitOnEnterbooleanfalseEnter 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.