Textarea
The <smart-textarea> component renders a multi-line text input with two-way value binding, optional placeholder, disabled state, label, action buttons, avatar/toolbar/preview/footer slots, and a structured actionClick output. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract TextareaBaseComponent defines the shared API — value (two-way ModelSignal<string>), placeholder, disabled, optional ITextareaOptions, cssClass (alias class), and the actionClick output. TextareaStandardComponent is a barebones placeholder using a native <textarea> element. TextareaPresetComponent is the styled Tailwind variation that honours every option, including variant and autoFocus. TextareaComponent is the public wrapper that renders TextareaStandardComponent by default and accepts a custom replacement (such as the preset) via TEXTAREA_STANDARD_COMPONENT_TOKEN.
Usage
<smart-textarea
[options]="options"
[(value)]="comment"
placeholder="Write a comment..."
(actionClick)="onActionClick($event)"
/>
@if (lastSubmitted() !== null) {
<p>Posted: {{ lastSubmitted() }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
TextareaComponent (<smart-textarea>)
Main wrapper. Delegates to TextareaStandardComponent by default. When TEXTAREA_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and hands it value, placeholder, disabled, options and class. Re-emits actionClick and forwards two-way value of whichever implementation renders (the standard, the preset or a custom one).
TextareaStandardComponent (<smart-textarea-standard>)
Barebones placeholder using a native <textarea>. Renders an outer wrapper with cssClass around a .textarea block: an optional <label> (when options.label is set; it is not linked to the field, so give the field options.ariaLabel for an accessible name), optional .avatar and .toolbar slots, the <textarea> (value written back on input, disabled, rows default 3, maxlength, placeholder, name, aria-label and required from the options), and an optional .actions row with one <button class="action variant-{variant}"> per options.actions entry (variant default secondary; iconTpl and label inside). A click emits { actionId, value } through actionClick, never while disabled. Optional .preview (previewTpl) and .footer (footerTpl) slots render below the actions row. The standard ignores options.variant and options.autoFocus and adds no styles: the class hooks are for your CSS.
TextareaPresetComponent (<smart-textarea-preset>)
Styled variation that extends TextareaBaseComponent and is a drop-in replacement for TextareaStandardComponent. See Preset.
TextareaBaseComponent (abstract)
Abstract base directive. Exposes:
value: ModelSignal<string>(default'')placeholder: InputSignal<string>(default'')disabled: InputSignal<boolean>(defaultfalse)options: InputSignal<ITextareaOptions | undefined>cssClass: InputSignal<string>(aliasclass)actionClick: OutputEmitterRef<ITextareaActionClick>
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
value | ModelSignal<string> | '' | Two-way bindable textarea value |
placeholder | InputSignal<string> | '' | Placeholder text |
disabled | InputSignal<boolean> | false | Disables the field and the action buttons |
options | InputSignal<ITextareaOptions | undefined> | - | Optional configuration |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
Outputs
| Output | Type | Description |
|---|---|---|
actionClick | OutputEmitterRef<ITextareaActionClick> | Emitted when an action button is clicked, with the current text; never while disabled. |
ITextareaOptions
| Field | Type | Default | Description |
|---|---|---|---|
rows | number | 3 | Visible text rows. |
maxLength | number | - | maxlength of the field; the preset also shows a count/max counter. |
variant | SmartTextareaVariant | 'simple' | Preset only: the layout (see the preset section). The standard ignores it. |
label | string | - | Label above the field (the preset links it to the field; the standard does not). |
name | string | - | name attribute of the field. |
required | boolean | false | Sets required on the field; the preset also shows a red * in the label. |
autoFocus | boolean | false | Preset only: focuses the field after the first render. The standard ignores it. |
ariaLabel | string | - | aria-label of the field. |
actions | ITextareaAction[] | [] | Buttons below (or, in some preset variants, inside) the field. |
avatarTpl | TemplateRef<unknown> | - | Avatar slot (the preset renders it in a column left of the field). |
toolbarTpl | TemplateRef<unknown> | - | Toolbar slot (e.g. attach / mention buttons). |
previewTpl | TemplateRef<unknown> | - | Preview content; the preset's with-preview variant shows it on the Preview tab. |
footerTpl | TemplateRef<unknown> | - | Footer slot below everything else. |
SmartTextareaVariant is 'simple' | 'with-avatar-actions' | 'with-underline' | 'with-pill-actions' | 'with-preview'.
ITextareaAction
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as actionId in actionClick. |
label | string | - | Button text (the preset uses the id as aria-label of a button without one). |
iconTpl | TemplateRef<unknown> | - | Icon before the label. |
variant | 'primary' | 'secondary' | 'ghost' | 'secondary' | Look of the button (variant-{variant} class in the standard). |
ITextareaActionClick
| Field | Type | Default | Description |
|---|---|---|---|
actionId | string | required | The id of the clicked action. |
value | string | required | The text of the field at the time of click. |
Preset
TextareaPresetComponent (selector smart-textarea-preset) renders the Tailwind UI comment-form look: white / gray-900-friendly surfaces (bg-white, dark:bg-white/5), gray-300 / white/10 outlines with a blue focus ring, gray-900 / white text, gray-400 / gray-500 placeholders and rounded-lg fields. Every class is smart:-prefixed with an explicit dark: variant; the class recipes are internal to the preset and not exported.
It renders everything the standard component renders (label, avatar, toolbar, field, actions, preview, footer) and additionally honours the options the standard ignores.
variantpicks the layout (default'simple', exposed asdata-varianton the root):Variant Look simpleOutlined, rounded field; toolbar (left) and actions (right) in a row below it with-avatar-actionsBorderless field inside an outlined box whose focus ring follows the field; toolbar + actions inside it with-underlineBorderless field on a bottom border that thickens to blue on focus; toolbar + actions below with-pill-actionsOutlined box with a divided ( border-t) bar inside; action buttons arerounded-fullpillswith-previewWrite / Preview tabs above the field; the Preview tab swaps the field for previewTplOutside
with-preview, apreviewTplrenders as agray-50/white/5block below the field.autoFocusfocuses the field after the first render (and sets theautofocusattribute).maxLengthis applied asmaxlengthand also shows acount/maxcounter under the field.requiredsetsrequiredon the field and a red*in the label; the label is linked to the field withfor/id.avatarTplrenders in a column to the left of the body in every variant.Actions are styled per
action.variant:primary(solid blue),secondary(default: white with agray-300ring,white/10in dark mode),ghost(text only, gray hover). They are disabled with the field, and clicking one emitsactionClickwith{ actionId, value }(never while disabled).
Register it on TEXTAREA_STANDARD_COMPONENT_TOKEN to restyle every <smart-textarea>, or register every preset at once with provideSmartPresets().
TextareaPresetComponentdeclarescssClassasinput<string>('')without theclassalias. Bind it as[cssClass]when using the<smart-textarea-preset>selector directly, or just passclasson<smart-textarea>(the wrapper forwards it). With the preset registered through the token,[(value)]and(actionClick)on<smart-textarea>work as with the standard.
TEXTAREA_STANDARD_COMPONENT_TOKEN
Provide a component class extending TextareaBaseComponent under TEXTAREA_STANDARD_COMPONENT_TOKEN; every <smart-textarea> below that injector renders it.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
ITextareaOptions,
TEXTAREA_STANDARD_COMPONENT_TOKEN,
TextareaBaseComponent,
TextareaComponent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-textarea',
template: `
<div [class]="containerClasses()">
@if (options()?.label) {
<label
class="docs-textarea__label"
[attr.for]="options()?.name ?? null"
>
{{ options()!.label }}
@if (options()?.required) {
<span class="docs-textarea__required">*</span>
}
</label>
}
<textarea
class="docs-textarea__field"
[attr.id]="options()?.name ?? null"
[attr.name]="options()?.name ?? null"
[attr.placeholder]="placeholder() || null"
[attr.maxlength]="options()?.maxLength ?? null"
[rows]="options()?.rows ?? 3"
[disabled]="disabled()"
[value]="value()"
(input)="onInput($event)"
></textarea>
@if ((options()?.actions ?? []).length > 0) {
<div class="docs-textarea__actions">
@for (action of options()!.actions!; track action.id) {
<button
type="button"
class="docs-textarea__action"
[attr.data-variant]="action.variant ?? 'secondary'"
[disabled]="disabled()"
(click)="onActionClick(action.id)"
>
{{ action.label ?? action.id }}
</button>
}
</div>
}
</div>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomTextareaComponent extends TextareaBaseComponent {
containerClasses = computed(() =>
[
'docs-textarea',
`docs-textarea--${this.options()?.variant ?? 'simple'}`,
this.cssClass(),
]
.filter(Boolean)
.join(' '),
);
// `value` is a model on the base: the wrapper passes it in and writes the
// typed text back to `<smart-textarea [(value)]="...">`.
protected onInput(event: Event): void {
this.value.set((event.target as HTMLTextAreaElement).value);
}
protected onActionClick(actionId: string): void {
if (this.disabled()) return;
this.actionClick.emit({ actionId, value: this.value() });
}
}
@Component({
selector: 'docs-textarea-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [TextareaComponent],
// The token swaps the standard textarea for the custom one everywhere below
// this component, so consumers keep writing `<smart-textarea>`.
providers: [
{
provide: TEXTAREA_STANDARD_COMPONENT_TOKEN,
useValue: CustomTextareaComponent,
},
],
// The wrapper forwards `value` both ways and re-emits `actionClick` of the
// custom component.
template: `
<smart-textarea
[(value)]="comment"
placeholder="Add your comment..."
[options]="options"
(actionClick)="lastAction.set($event.actionId + ': ' + $event.value)"
/>
@if (lastAction()) {
<p>Last action: {{ lastAction() }}</p>
}
`,
})
export class TextareaCustomExampleComponent {
readonly comment = signal('Looks good to me.');
readonly lastAction = signal<string | null>(null);
options: ITextareaOptions = {
label: 'Comment',
name: 'comment',
rows: 4,
maxLength: 280,
required: true,
variant: 'with-pill-actions',
actions: [
{ id: 'cancel', label: 'Cancel', variant: 'ghost' },
{ id: 'submit', label: 'Send', variant: 'primary' },
],
};
}
Source
The component lives in packages/shared/angular/src/lib/components/textarea and is documented for Claude Code by the angular-components-textarea skill.
SmartTextarea is a multi-line text field shaped for comment and message boxes: a label, the <textarea>, and a bar of actions (e.g. Post, Attach) reported through onActionClick({ actionId, value }) with the current text, plus slots for an avatar, a toolbar, a preview and a footer. The text is controlled (value + onValueChange) or kept inside (defaultValue). SmartTextareaPreset adds five variants (including Write / Preview tabs), focuses on mount with autoFocus and shows a character counter for maxLength.
Usage
import { useState } from 'react';
import {
ITextareaActionClick,
ITextareaOptions,
SmartTextarea,
} from '@smartsoft001/react';
const options: ITextareaOptions = {
label: 'Add your comment',
name: 'comment',
rows: 4,
maxLength: 500,
required: true,
actions: [{ id: 'post', label: 'Post', variant: 'primary' }],
};
export function TextareaUsageExample() {
const [comment, setComment] = useState('');
const [lastSubmitted, setLastSubmitted] = useState<string | null>(null);
const onActionClick = ({ value }: ITextareaActionClick) =>
setLastSubmitted(value);
return (
<>
<SmartTextarea
options={options}
value={comment}
onValueChange={setComment}
placeholder="Write a comment..."
onActionClick={onActionClick}
/>
{lastSubmitted !== null && <p>Posted: {lastSubmitted}</p>}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartTextarea | component | Renders the implementation registered as components.textarea on SmartProvider, SmartTextareaStandard by default. |
SmartTextareaPreset | component | Styled textarea variation (preset). |
SmartTextareaStandard | component | The default, unstyled textarea. |
useTextarea | hook | The behaviour every textarea variant shares: the value, controlled through value / onValueChange or kept internally from defaultValue, and actionClick(), which reports an action with the current text unless disabled. |
The preset's class helpers (textareaFieldClasses, textareaFrameClasses, textareaBarClasses, textareaBarInside, textareaActionClasses, textareaTabClasses, TEXTAREA_ROOT, TEXTAREA_AVATAR, TEXTAREA_BODY, TEXTAREA_LABEL, TEXTAREA_REQUIRED, TEXTAREA_TOOLBAR, TEXTAREA_ACTIONS, TEXTAREA_TABS, TEXTAREA_PREVIEW_PANE, TEXTAREA_PREVIEW_BELOW, TEXTAREA_COUNTER, TEXTAREA_FOOTER) are exported too, with the type SmartTextareaPresetVariant (the variant argument of the helpers), for a custom implementation that wants the preset look.
Props and Types
SmartTextareaProps
| Prop | Type | Default | Description |
|---|---|---|---|
value? | string | — | The text. Leave it undefined for an uncontrolled textarea that starts from defaultValue. |
defaultValue? | string | '' | Initial text of an uncontrolled textarea. |
onValueChange? | (value: string) => void | — | Called with the edited text. |
placeholder? | string | '' | Placeholder of the field. |
disabled? | boolean | false | Disables the field; action clicks are ignored. |
options? | ITextareaOptions | — | Field attributes, actions and slots. |
className? | string | — | Classes on the root element. |
onActionClick? | (event: ITextareaActionClick) => void | — | An action was clicked; reported with the current text. |
ITextareaOptions
| Field | Type | Default | Description |
|---|---|---|---|
rows? | number | 3 | Visible rows. |
maxLength? | number | — | Maximum length (a counter in the preset). |
variant? | SmartTextareaVariant | 'simple' | Preset look; the standard ignores it. |
label? | string | — | Label of the field. |
name? | string | — | name attribute. |
required? | boolean | — | required attribute. |
autoFocus? | boolean | — | Preset: focuses the field on mount. |
ariaLabel? | string | — | Accessible name when there is no label. |
actions? | ITextareaAction[] | [] | Buttons of the action bar. |
avatarTpl? | ReactNode | — | Avatar beside the field. |
toolbarTpl? | ReactNode | — | Toolbar (formatting, attachments). |
previewTpl? | ReactNode | — | Preview content (the preset's with-preview variant shows it on the Preview tab). |
footerTpl? | ReactNode | — | A slot below. |
ITextareaActionClick
Payload of onActionClick.
| Field | Type | Default | Description |
|---|---|---|---|
actionId | string | required | The id of the clicked action. |
value | string | required | The text at the time of the click. |
ITextareaAction
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as actionId. |
label? | string | — | Button text. |
iconTpl? | ReactNode | — | Icon of the button. |
variant? | 'primary' | 'secondary' | 'ghost' | 'secondary' | primary, secondary or ghost look. |
Related types
SmartTextareaVariant:'simple' \| 'with-avatar-actions' \| 'with-underline' \| 'with-pill-actions' \| 'with-preview'
Replacing the Implementation
SmartTextarea renders the component registered under the 'textarea' key of SmartProvider's components, and SmartTextareaStandard when nothing is registered there. Every SmartTextarea below the provider then renders the registered component, which receives the same props.
SmartTextareaPreset is the styled (preset) implementation: register it under the 'textarea' key of SmartProvider's components, render it directly in place of SmartTextarea, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useTextarea hook
The behaviour every textarea variant shares: the value, controlled through value / onValueChange or kept internally from defaultValue, and actionClick(), which reports an action with the current text unless disabled.
| Returns | Type | Description |
|---|---|---|
value | string | The text (controlled or internal). |
setValue | (next: string) => void | Sets the text and calls onValueChange. |
actionClick | (actionId: string) => void | Reports an action with the current text; ignored while disabled. |
import { useState } from 'react';
import {
ITextareaOptions,
SmartProvider,
SmartTextarea,
SmartTextareaProps,
useTextarea,
} from '@smartsoft001/react';
export function CustomTextarea(props: SmartTextareaProps) {
const { placeholder, disabled = false, options, className } = props;
// useTextarea keeps the text (controlled or internal), reports edits through
// onValueChange and actions through onActionClick, ignoring them while
// disabled.
const { value, setValue, actionClick } = useTextarea(props);
const actions = options?.actions ?? [];
const containerClasses = [
'docs-textarea',
`docs-textarea--${options?.variant ?? 'simple'}`,
className,
]
.filter(Boolean)
.join(' ');
return (
<div className={containerClasses}>
{options?.label && (
<label className="docs-textarea__label" htmlFor={options.name}>
{options.label}
{options.required && (
<span className="docs-textarea__required">*</span>
)}
</label>
)}
<textarea
className="docs-textarea__field"
id={options?.name}
name={options?.name}
placeholder={placeholder || undefined}
maxLength={options?.maxLength}
rows={options?.rows ?? 3}
disabled={disabled}
value={value}
onChange={(event) => setValue(event.target.value)}
/>
{actions.length > 0 && (
<div className="docs-textarea__actions">
{actions.map((action) => (
<button
key={action.id}
type="button"
className="docs-textarea__action"
data-variant={action.variant ?? 'secondary'}
disabled={disabled}
onClick={() => actionClick(action.id)}
>
{action.label ?? action.id}
</button>
))}
</div>
)}
</div>
);
}
// A module constant: a new object on every render would change the context.
const components = { textarea: CustomTextarea };
const options: ITextareaOptions = {
label: 'Comment',
name: 'comment',
rows: 4,
maxLength: 280,
required: true,
variant: 'with-pill-actions',
actions: [
{ id: 'cancel', label: 'Cancel', variant: 'ghost' },
{ id: 'submit', label: 'Send', variant: 'primary' },
],
};
// Every <SmartTextarea> below the provider renders CustomTextarea. Without
// value the text lives in the implementation and starts at defaultValue.
export function TextareaCustomExample() {
const [lastAction, setLastAction] = useState<string | null>(null);
return (
<SmartProvider components={components}>
<SmartTextarea
defaultValue="Looks good to me."
placeholder="Add your comment..."
options={options}
onActionClick={({ actionId, value }) =>
setLastAction(`${actionId}: ${value}`)
}
/>
{lastAction && <p>Last action: {lastAction}</p>}
</SmartProvider>
);
}
Styling
- The standard textarea is unstyled; the preset renders the comment-form looks with
smart:dark:variants.
Source
The component lives in packages/shared/react/src/lib/components/textarea and is documented for Claude Code by the react-components-textarea skill.