Smart Textarea
ProA 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.
import { SvSmartTextareaComponent } from '@styloviz-pro/forms/smart-textarea';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
A phrase list, on the device
`svSmartTextareaPhraseCompleter` completes the phrase whose start matches what was just typed — canned replies, snippets, signatures. Nothing is sent.
A model behind your own endpoint
`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
Binds with formControl / formControlName / ngModel and reports `required` and `maxlength`; a suggestion is cut to fit `maxLength`.
Signal Forms
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
| Name | Type | Default | Description |
|---|---|---|---|
| value | string (two-way) | '' | The text. Two-way bindable with `[(value)]`; also a form control. |
| completer | SvSmartTextareaCompleter | null | null | Where suggestions come from: `(request) => Promise<string | null>`. `null` turns completion off — the field is then a plain textarea. |
| enabled | boolean | true | Ask for suggestions at all. Off keeps the completer bound but silent. |
| debounceMs | number | 350 | How long typing must pause before a suggestion is asked for, in ms. |
| minChars | number | 3 | The fewest non-space characters before the caret that make a request. Ctrl/Cmd+Space ignores it. |
| contextLength | number | 2000 | The most characters sent on each side of the caret. `0` sends everything. |
| showHint | boolean | true | Show "Tab to accept · Esc to dismiss" and an Accept button (for touch) under a suggestion. |
| placeholder | string | '' | Placeholder for an empty field. Not an accessible name — set `ariaLabel` or a `<label for>`. |
| rows | number | 4 | Visible lines (the native `rows`); the minimum height with `autosize`. |
| autosize | boolean | false | Grow with the text instead of scrolling. |
| maxRows | number | 0 | With `autosize`, the most lines before it scrolls. `0` grows without limit. |
| ariaLabel | string | '' | Accessible name. Leave empty when a `<label for="inputId">` names the field. |
| ariaDescribedBy | string | '' | Ids of elements that describe the field (a hint, an error), joined to its own keyboard hint. |
| inputId | string | '' | Id for the textarea, so an external `<label for>` can name it. Generated when empty. |
| maxLength | number | 0 | Maximum characters (the native `maxlength`); a suggestion is cut to fit. `0` is unlimited. |
| disabled | boolean | false | Disable the field. A form control's `disable()` does the same. |
| readonly | boolean | false | Read-only: selectable and copyable, never edited or completed. |
| required | boolean | false | Mark the field required (`aria-required`, and a `required` error when bound to a form). |
| invalid | boolean | false | Show the field as invalid (`aria-invalid`, danger border) — bind your form's state. |
| spellcheck | boolean | true | The browser's spellcheck. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| suggestionShown | string | A suggestion appeared. Carries its text. |
| suggestionAccepted | SvSmartTextareaAccepted | All or part of a suggestion was inserted. |
| suggestionDismissed | void | A showing suggestion went away unaccepted — Escape, blur, typing past it, moving the caret. |
| completionFailed | unknown | The completer rejected. Carries the error; the field shows nothing, as a suggestion is optional help. |
| valueChange | string | Emits 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.