Getting Started
UI
Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Utilities
Forms
Stack
Textarea
Displays a form textarea or a component that looks like a textarea.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-preview',
imports: [HlmTextareaImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<textarea hlmTextarea placeholder="Type your message here."></textarea>
`,
})
export class TextareaPreview {}Installation
ng g @spartan-ng/cli:ui textareanx g @spartan-ng/cli:ui textareaimport { OVERLAY_DEFAULT_CONFIG } from '@angular/cdk/overlay';
import { brnClasses, type BrnClassesOptions } from '@spartan-ng/brain/core';
import { cn, type ClassValue } from 'cn';
import { createCn } from 'cn/config';
import { makeEnvironmentProviders, type EnvironmentProviders } from '@angular/core';
import { provideSpartanHlm } from '@spartan-ng/helm/utils';
/**
* Merges class values and resolves Tailwind CSS conflicts.
*
* To customize the merge (e.g. register custom theme values), create your own instance:
*
* @example
* ```ts
*
*
* export const hlm = createCn({
* extend: { classGroups: { 'font-size': [{ text: ['hero'] }] } },
* });
* ```
*/
export const hlm = cn;
/**
* This function dynamically adds and removes classes for a given element without requiring
* the a class binding (e.g. `[class]="..."`) which may interfere with other class bindings.
* The classes are merged with `hlm`.
*/
export function classes(computed: () => ClassValue[] | string, options: Omit<BrnClassesOptions, 'merge'> = {}) {
brnClasses(computed, { ...options, merge: hlm });
}
/**
* Provides default configuration for Spartan Helm components.
*
* This utility configures the Angular CDK overlay to disable the `usePopover`
* behavior introduced in Angular 21, which causes CDK overlay-based components
* (sheets, dialogs, tooltips, etc.) to render above `position: fixed` elements
* like `<hlm-toaster>`.
*
* @returns {EnvironmentProviders} Environment providers to be added to the application config.
*
* @example
* ```ts
* // app.config.ts
*
*
* export const appConfig: ApplicationConfig = {
* providers: [
* provideSpartanHlm(),
* // ... other providers
* ],
* };
* ```
*/
export function provideSpartanHlm(): EnvironmentProviders {
return makeEnvironmentProviders([
{
provide: OVERLAY_DEFAULT_CONFIG,
useValue: { usePopover: false },
},
]);
}import { BrnFieldControlDescribedBy } from '@spartan-ng/brain/field';
import { BrnTextarea } from '@spartan-ng/brain/textarea';
import { Directive } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
@Directive({
selector: '[hlmTextarea]',
exportAs: 'hlmTextarea',
hostDirectives: [
{ directive: BrnTextarea, inputs: ['id', 'forceInvalid', 'aria-invalid'] },
{ directive: BrnFieldControlDescribedBy, inputs: ['aria-describedby'] },
],
host: { 'data-slot': 'textarea' },
})
export class HlmTextarea {
constructor() {
classes(
() =>
'border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 data-[matches-spartan-invalid=true]:ring-destructive/20 dark:data-[matches-spartan-invalid=true]:ring-destructive/40 data-[matches-spartan-invalid=true]:border-destructive dark:data-[matches-spartan-invalid=true]:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-3 data-[matches-spartan-invalid=true]:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50',
);
}
}
export const HlmTextareaImports = [HlmTextarea] as const;import { BrnFieldControlDescribedBy } from '@spartan-ng/brain/field';
import { BrnTextarea } from '@spartan-ng/brain/textarea';
import { Directive } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
@Directive({
selector: '[hlmTextarea]',
exportAs: 'hlmTextarea',
hostDirectives: [
{ directive: BrnTextarea, inputs: ['id', 'forceInvalid', 'aria-invalid'] },
{ directive: BrnFieldControlDescribedBy, inputs: ['aria-describedby'] },
],
host: { 'data-slot': 'textarea' },
})
export class HlmTextarea {
constructor() {
classes(
() =>
'border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 data-[matches-spartan-invalid=true]:ring-destructive/20 dark:data-[matches-spartan-invalid=true]:ring-destructive/40 data-[matches-spartan-invalid=true]:border-destructive dark:data-[matches-spartan-invalid=true]:border-destructive/50 rounded-md border bg-transparent px-2.5 py-2 text-base shadow-xs transition-[color,box-shadow] focus-visible:ring-3 data-[matches-spartan-invalid=true]:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50',
);
}
}
export const HlmTextareaImports = [HlmTextarea] as const;import { BrnFieldControlDescribedBy } from '@spartan-ng/brain/field';
import { BrnTextarea } from '@spartan-ng/brain/textarea';
import { Directive } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
@Directive({
selector: '[hlmTextarea]',
exportAs: 'hlmTextarea',
hostDirectives: [
{ directive: BrnTextarea, inputs: ['id', 'forceInvalid', 'aria-invalid'] },
{ directive: BrnFieldControlDescribedBy, inputs: ['aria-describedby'] },
],
host: { 'data-slot': 'textarea' },
})
export class HlmTextarea {
constructor() {
classes(
() =>
'border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 data-[matches-spartan-invalid=true]:ring-destructive/20 dark:data-[matches-spartan-invalid=true]:ring-destructive/40 data-[matches-spartan-invalid=true]:border-destructive dark:data-[matches-spartan-invalid=true]:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-none border bg-transparent px-2.5 py-2 text-xs transition-colors focus-visible:ring-1 data-[matches-spartan-invalid=true]:ring-1 md:text-xs placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50',
);
}
}
export const HlmTextareaImports = [HlmTextarea] as const;import { BrnFieldControlDescribedBy } from '@spartan-ng/brain/field';
import { BrnTextarea } from '@spartan-ng/brain/textarea';
import { Directive } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
@Directive({
selector: '[hlmTextarea]',
exportAs: 'hlmTextarea',
hostDirectives: [
{ directive: BrnTextarea, inputs: ['id', 'forceInvalid', 'aria-invalid'] },
{ directive: BrnFieldControlDescribedBy, inputs: ['aria-describedby'] },
],
host: { 'data-slot': 'textarea' },
})
export class HlmTextarea {
constructor() {
classes(
() =>
'border-input bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 data-[matches-spartan-invalid=true]:ring-destructive/20 dark:data-[matches-spartan-invalid=true]:ring-destructive/40 data-[matches-spartan-invalid=true]:border-destructive dark:data-[matches-spartan-invalid=true]:border-destructive/50 resize-none rounded-xl border px-3 py-3 text-base transition-colors focus-visible:ring-3 data-[matches-spartan-invalid=true]:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50',
);
}
}
export const HlmTextareaImports = [HlmTextarea] as const;import { BrnFieldControlDescribedBy } from '@spartan-ng/brain/field';
import { BrnTextarea } from '@spartan-ng/brain/textarea';
import { Directive } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
@Directive({
selector: '[hlmTextarea]',
exportAs: 'hlmTextarea',
hostDirectives: [
{ directive: BrnTextarea, inputs: ['id', 'forceInvalid', 'aria-invalid'] },
{ directive: BrnFieldControlDescribedBy, inputs: ['aria-describedby'] },
],
host: { 'data-slot': 'textarea' },
})
export class HlmTextarea {
constructor() {
classes(
() =>
'border-input bg-input/20 dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/30 data-[matches-spartan-invalid=true]:ring-destructive/20 dark:data-[matches-spartan-invalid=true]:ring-destructive/40 data-[matches-spartan-invalid=true]:border-destructive dark:data-[matches-spartan-invalid=true]:border-destructive/50 resize-none rounded-md border px-2 py-2 text-sm transition-colors focus-visible:ring-2 data-[matches-spartan-invalid=true]:ring-2 md:text-xs/relaxed placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50',
);
}
}
export const HlmTextareaImports = [HlmTextarea] as const;import { BrnFieldControlDescribedBy } from '@spartan-ng/brain/field';
import { BrnTextarea } from '@spartan-ng/brain/textarea';
import { Directive } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
@Directive({
selector: '[hlmTextarea]',
exportAs: 'hlmTextarea',
hostDirectives: [
{ directive: BrnTextarea, inputs: ['id', 'forceInvalid', 'aria-invalid'] },
{ directive: BrnFieldControlDescribedBy, inputs: ['aria-describedby'] },
],
host: { 'data-slot': 'textarea' },
})
export class HlmTextarea {
constructor() {
classes(
() =>
'bg-input/50 focus-visible:border-ring focus-visible:ring-ring/30 data-[matches-spartan-invalid=true]:ring-destructive/20 dark:data-[matches-spartan-invalid=true]:ring-destructive/40 data-[matches-spartan-invalid=true]:border-destructive dark:data-[matches-spartan-invalid=true]:border-destructive/50 resize-none rounded-2xl border border-transparent px-3 py-3 text-base transition-[color,box-shadow,background-color] focus-visible:ring-3 data-[matches-spartan-invalid=true]:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50',
);
}
}
export const HlmTextareaImports = [HlmTextarea] as const;Usage
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';<textarea hlmTextarea placeholder="Type your message here."></textarea>Examples
Field
Use hlm-field , hlmFieldLabel , and hlm-field-description to create a textarea with a label and description.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-field',
imports: [HlmTextareaImports, HlmFieldImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<hlm-field>
<label hlmFieldLabel for="textarea-message">Message</label>
<hlm-field-description>Enter your message below.</hlm-field-description>
<textarea hlmTextarea id="textarea-message" placeholder="Type your message here."></textarea>
</hlm-field>
`,
})
export class TextareaField {}Disabled
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-disabled',
imports: [HlmTextareaImports, HlmFieldImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<hlm-field data-disabled="true">
<label hlmFieldLabel for="textarea-disabled">Message</label>
<textarea hlmTextarea id="textarea-disabled" placeholder="Type your message here." disabled></textarea>
</hlm-field>
`,
})
export class TextareaDisabledPreview {}Invalid
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-invalid',
imports: [HlmTextareaImports, HlmFieldImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<hlm-field forceInvalid>
<label hlmFieldLabel for="textarea-invalid">Message</label>
<textarea hlmTextarea forceInvalid id="textarea-invalid" placeholder="Type your message here."></textarea>
<hlm-field-description>Please enter a valid message.</hlm-field-description>
</hlm-field>
`,
})
export class TextareaInvalid {}Button
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-button',
imports: [HlmTextareaImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<div class="grid w-full gap-2">
<textarea hlmTextarea placeholder="Type your message here."></textarea>
<button hlmBtn>Send message</button>
</div>
`,
})
export class TextareaButtonPreview {}Form
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { form, FormField, FormRoot, required } from '@angular/forms/signals';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-form',
imports: [HlmTextareaImports, HlmLabelImports, HlmButtonImports, HlmFieldImports, FormRoot, FormField],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<form [formRoot]="form">
<hlm-field-group>
<hlm-field>
<label hlmFieldLabel for="username">Bio</label>
<textarea
hlmTextarea
class="w-80"
id="username"
placeholder="Tell us a little bit about yourself"
[formField]="form.bio"
></textarea>
<p hlmFieldDescription>
You can
<span>@mention</span>
other users and organizations.
</p>
</hlm-field>
<hlm-field orientation="horizontal">
<button hlmBtn type="submit">Submit</button>
</hlm-field>
</hlm-field-group>
</form>
`,
})
export class TextareaFormPreview {
protected readonly _model = signal({
bio: '',
});
public readonly form = form(
this._model,
(schemaPath) => {
required(schemaPath.bio, { message: 'Bio is required' });
},
{
submission: {
action: async () => {
const model = this._model();
console.log(model);
},
},
},
);
}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmTextareaImports } from '@spartan-ng/helm/textarea';
@Component({
selector: 'spartan-textarea-rtl',
imports: [HlmTextareaImports, HlmFieldImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'min-w-xs sm:min-w-sm' },
template: `
<hlm-field [dir]="_dir()">
<label hlmFieldLabel for="textarea-message">{{ _t()['label'] }}</label>
<textarea hlmTextarea id="textarea-message" [placeholder]="_t()['placeholder']"></textarea>
<hlm-field-description>{{ _t()['description'] }}</hlm-field-description>
</hlm-field>
`,
})
export class TextareaRtl {
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {
label: 'Feedback',
placeholder: 'Your feedback helps us improve...',
description: 'Share your thoughts about our service.',
},
},
ar: {
dir: 'rtl',
values: {
label: 'التعليقات',
placeholder: 'تعليقاتك تساعدنا على التحسين...',
description: 'شاركنا أفكارك حول خدمتنا.',
},
},
he: {
dir: 'rtl',
values: {
label: 'משוב',
placeholder: 'המשוב שלך עוזר לנו להשתפר...',
description: 'שתף את מחשבותיך על השירות שלנו.',
},
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
}Brain API
BrnTextarea
Selector: [brnTextarea]
ExportAs: brnTextarea
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | undefined | `brn-textarea-${++BrnTextarea._id}` | The id of the textarea. |
| forceInvalid | boolean | false | Whether to force the textarea into an invalid state. |
| aria-invalid | boolean | undefined | undefined | Manual override for aria-invalid, e.g. for server-side validation errors. When not set, it follows the error state matcher (and `forceInvalid`). |
Helm API
HlmTextarea
Selector: [hlmTextarea]
ExportAs: hlmTextarea
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | undefined | `brn-textarea-${++BrnTextarea._id}` | The id of the textarea. |
| forceInvalid | boolean | false | Whether to force the textarea into an invalid state. |
| aria-invalid | boolean | undefined | undefined | Manual override for aria-invalid, e.g. for server-side validation errors. When not set, it follows the error state matcher (and `forceInvalid`). |
| aria-describedby | string | null | null | - |
On This Page
Stop configuring. Start shipping.
Zerops powers spartan.ng and Angular teams worldwide.
One-command deployment. Zero infrastructure headaches.
Deploy with Zerops