Smart Textarea

Pro

A native textarea with inline completion: a suggestion appears in grey after the caret, Tab takes it, Ctrl/Cmd+→ takes a word, Escape dismisses it. Your completer supplies the text — a phrase list on the device, or a model behind your own endpoint — with requests debounced and aborted as the user types on. A ControlValueAccessor and validator with `required` and a character limit.

</>sv-smart-textarea smart textareaaiautocompletecompletionghost textcopilottextareasuggestioncanned replyllm
import { SvSmartTextareaComponent } from '@styloviz-pro/forms/smart-textarea';

Demo & usage

Basic usage

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

A phrase list, on the device

Pro

`svSmartTextareaPhraseCompleter` completes the phrase whose start matches what was just typed — canned replies, snippets, signatures. Nothing is sent.

A model behind your own endpoint

Pro

`svSmartTextareaFetchCompleter` POSTs `{ before, after }` and reads `{ completion }`; the request is aborted the moment the answer cannot be shown. Rejections go to `(completionFailed)` and nothing is shown.

Reactive forms

Pro

Binds with formControl / formControlName / ngModel and reports `required` and `maxlength`; a suggestion is cut to fit `maxLength`.

Signal Forms

Pro

Bind it with `[formField]` from `@angular/forms/signals` — the control is a ControlValueAccessor, which Signal Forms drives on Angular 21 and 22 alike.

When to use

  • Replies, notes and descriptions that repeat — support answers, ticket summaries, release notes — where finishing the sentence saves real typing.
  • You have a completion model and want it in a field that still behaves exactly like a textarea.
  • For picking people or tags after `@` or `#`, use Mention instead.

Compare with

  • Mention Input — Mention offers a list of people or tags after a trigger character. Smart Textarea offers the rest of the sentence, inline, with no list.
  • Markdown Editor — Markdown Editor formats Markdown with a toolbar and preview. Smart Textarea is a plain textarea that suggests what comes next.
  • Smart Paste — Smart Paste reads text someone already has and turns it into field values. Smart Textarea helps write new text.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Inputs

NameTypeDefaultDescription
valuestring (two-way)''The text. Two-way bindable with `[(value)]`; also a form control.
completerSvSmartTextareaCompleter | nullnullWhere suggestions come from: `(request) => Promise<string | null>`. `null` turns completion off — the field is then a plain textarea.
enabledbooleantrueAsk for suggestions at all. Off keeps the completer bound but silent.
debounceMsnumber350How long typing must pause before a suggestion is asked for, in ms.
minCharsnumber3The fewest non-space characters before the caret that make a request. Ctrl/Cmd+Space ignores it.
contextLengthnumber2000The most characters sent on each side of the caret. `0` sends everything.
showHintbooleantrueShow "Tab to accept · Esc to dismiss" and an Accept button (for touch) under a suggestion.
placeholderstring''Placeholder for an empty field. Not an accessible name — set `ariaLabel` or a `<label for>`.
rowsnumber4Visible lines (the native `rows`); the minimum height with `autosize`.
autosizebooleanfalseGrow with the text instead of scrolling.
maxRowsnumber0With `autosize`, the most lines before it scrolls. `0` grows without limit.
ariaLabelstring''Accessible name. Leave empty when a `<label for="inputId">` names the field.
ariaDescribedBystring''Ids of elements that describe the field (a hint, an error), joined to its own keyboard hint.
inputIdstring''Id for the textarea, so an external `<label for>` can name it. Generated when empty.
maxLengthnumber0Maximum characters (the native `maxlength`); a suggestion is cut to fit. `0` is unlimited.
disabledbooleanfalseDisable the field. A form control's `disable()` does the same.
readonlybooleanfalseRead-only: selectable and copyable, never edited or completed.
requiredbooleanfalseMark the field required (`aria-required`, and a `required` error when bound to a form).
invalidbooleanfalseShow the field as invalid (`aria-invalid`, danger border) — bind your form's state.
spellcheckbooleantrueThe browser's spellcheck.

Outputs

EventPayload typeDescription
suggestionShownstringA suggestion appeared. Carries its text.
suggestionAcceptedSvSmartTextareaAcceptedAll or part of a suggestion was inserted.
suggestionDismissedvoidA showing suggestion went away unaccepted — Escape, blur, typing past it, moving the caret.
completionFailedunknownThe completer rejected. Carries the error; the field shows nothing, as a suggestion is optional help.
valueChangestringEmits the new `value` whenever it changes — the output half of `[(value)]`.

Customization & theming

  • `value` is a two-way model; `completer`, `enabled`, `debounceMs` (350), `minChars` (3), `contextLength` (2000), `showHint` (the hint line and touch Accept button).
  • `placeholder`, `rows`, `autosize` + `maxRows`, `maxLength`, `required`, `invalid`, `disabled`, `readonly`, `spellcheck`, `inputId`, `ariaLabel`, `ariaDescribedBy`.
  • Outputs: `suggestionShown`, `suggestionAccepted` (`{ text, partial }`), `suggestionDismissed`, `completionFailed`. Methods: `focus()`, `requestSuggestion()`, `acceptSuggestion()`, `dismiss()`.
  • Strings are `smartTextarea…` labels in the `formsPro` namespace, in 12 language packs.

Forms integration

  • sv-smart-textarea — ControlValueAccessor.[formControl], formControlName, [(ngModel)] and Signal Forms [formField] all work.

Best practices

  • Do: Name the field: `ariaLabel`, or a `<label for>` with `inputId`. The keyboard hint is joined to your own `ariaDescribedBy`.
  • Do: Pass the request’s `signal` to `fetch` in a completer of your own, so typing on cancels the round trip.
  • Don't: Don’t call a model with its key from the browser — put it behind your endpoint and use `svSmartTextareaFetchCompleter`.
  • Tip: Keep `contextLength` small for a fast endpoint; `0` sends the whole text.

Accessibility

  • A native `<textarea>` with `aria-autocomplete="inline"` while completion is on, and a described-by hint naming the keys: Tab accepts, Escape dismisses, Ctrl/Cmd+Space asks.
  • Tab accepts only while a suggestion shows; otherwise it moves focus as usual, so the field never traps the keyboard.
  • Each suggestion is announced once through the live announcer; the ghost text itself is `aria-hidden`.
  • An Accept button under the suggestion does what Tab does on a touchscreen. IME composition never triggers or accepts a suggestion.

Feedback on Smart Textarea

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.