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
Radio Group
A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmRadioGroupImports } from '@spartan-ng/helm/radio-group';
@Component({
selector: 'spartan-radio-group-preview',
imports: [FormsModule, HlmRadioGroupImports, HlmLabelImports],
template: `
<hlm-radio-group [(ngModel)]="spacing">
<div class="flex items-center gap-3">
<hlm-radio value="default" inputId="r1" disabled>
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="r1">Default</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="comfortable" inputId="r2">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="r2">Comfortable</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="compact" inputId="r3">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="r3">Compact</label>
</div>
</hlm-radio-group>
`,
})
export class RadioGroupPreview {
public spacing = 'comfortable';
}Installation
ng g @spartan-ng/cli:ui radio-groupnx g @spartan-ng/cli:ui radio-groupUsage
import { HlmRadioGroupImports } from '@spartan-ng/helm/radio-group';<hlm-radio-group>
<div class="flex items-center gap-3">
<hlm-radio value="option-one" inputId="option-one">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="option-one"> option-one</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="option-two" inputId="option-two">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="option-two"> option-two</label>
</div>
</hlm-radio-group>Examples
Card Layout
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideCreditCard } from '@ng-icons/lucide';
import { remixAppleFill, remixPaypalFill } from '@ng-icons/remixicon';
import { HlmRadioGroupImports } from '@spartan-ng/helm/radio-group';
import { hlm } from '@spartan-ng/helm/utils';
@Component({
selector: 'spartan-radio-card-preview',
imports: [FormsModule, HlmRadioGroupImports, NgIcon],
providers: [provideIcons({ lucideCreditCard, remixPaypalFill, remixAppleFill })],
template: `
<hlm-radio-group class="grid grid-cols-3 gap-4" [(ngModel)]="payment">
<label class="flex items-center" hlmLabel [class]="cardClass">
<hlm-radio value="card">
<ng-icon name="lucideCreditCard" class="mb-3" />
</hlm-radio>
Card
</label>
<label class="flex items-center" hlmLabel [class]="cardClass">
<hlm-radio value="paypal">
<ng-icon name="remixPaypalFill" class="mb-3" />
</hlm-radio>
PayPal
</label>
<label class="flex items-center" hlmLabel [class]="cardClass">
<hlm-radio value="apple">
<ng-icon name="remixAppleFill" class="mb-3" />
</hlm-radio>
Apple
</label>
</hlm-radio-group>
`,
})
export class RadioGroupCard {
public payment = 'card';
public readonly cardClass = hlm(
'relative block space-x-0',
// base card styles
'border-border flex flex-col items-center justify-center rounded-lg border-2 px-4 py-8',
// hover and background styles
'bg-background hover:bg-accent/10 cursor-pointer transition-colors',
// spacing for the icon and text
'[&>span]:mt-4',
// target the checked state properly
'[&:has([data-checked=true])]:border-primary [&:has([data-checked=true])]:border-2',
);
}Form
import { Component, signal } from '@angular/core';
import { form, FormField, FormRoot, required } from '@angular/forms/signals';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmRadioGroupImports } from '@spartan-ng/helm/radio-group';
@Component({
selector: 'spartan-radio-group-form',
imports: [HlmRadioGroupImports, HlmLabelImports, HlmButtonImports, FormRoot, FormField],
template: `
<form class="space-y-6" [formRoot]="form">
<div class="flex flex-col gap-3">
<label hlmLabel>Subscription Plan</label>
<hlm-radio-group [formField]="form.plan">
<div class="flex items-center gap-3">
<hlm-radio value="monthly" inputId="monthly">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="monthly">Monthly ($9.99/month)</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="yearly" inputId="yearly">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="yearly">Yearly ($99.99/year)</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="lifetime" inputId="lifetime">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="lifetime">Lifetime ($299.99)</label>
</div>
</hlm-radio-group>
</div>
<button hlmBtn type="submit">Submit</button>
</form>
`,
})
export class RadioGroupFormPreview {
protected readonly _model = signal({
plan: 'monthly',
});
public readonly form = form(
this._model,
(schemaPath) => {
required(schemaPath.plan, { message: 'Please select a plan' });
},
{
submission: {
action: async () => {
const model = this._model();
console.log(model);
},
},
},
);
}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { Directionality } from '@angular/cdk/bidi';
import { Component, computed, effect, inject, untracked } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmRadioGroupImports } from '@spartan-ng/helm/radio-group';
@Component({
selector: 'spartan-radio-group-rtl-preview',
imports: [FormsModule, HlmRadioGroupImports, HlmLabelImports],
providers: [Directionality],
host: {
class: 'grid w-full max-w-sm gap-3',
'[dir]': '_dir()',
},
template: `
<label hlmLabel>{{ _t()['label'] }}</label>
<hlm-radio-group [(ngModel)]="_value">
<div class="flex items-center gap-3">
<hlm-radio value="default" inputId="rtl-r1">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="rtl-r1">{{ _t()['default'] }}</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="comfortable" inputId="rtl-r2">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="rtl-r2">{{ _t()['comfortable'] }}</label>
</div>
<div class="flex items-center gap-3">
<hlm-radio value="compact" inputId="rtl-r3">
<hlm-radio-indicator indicator />
</hlm-radio>
<label hlmLabel for="rtl-r3">{{ _t()['compact'] }}</label>
</div>
</hlm-radio-group>
`,
})
export class RadioGroupRtlPreview {
private readonly _directionality = inject(Directionality);
private readonly _language = inject(TranslateService).language;
protected _value = 'comfortable';
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: { label: 'Spacing', default: 'Default', comfortable: 'Comfortable', compact: 'Compact' },
},
ar: {
dir: 'rtl',
values: { label: 'التباعد', default: 'افتراضي', comfortable: 'مريح', compact: 'مضغوط' },
},
he: {
dir: 'rtl',
values: { label: 'מרווח', default: 'ברירת מחדל', comfortable: 'נוח', compact: 'קומפקטי' },
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Brain API
BrnRadioGroup
Selector: [brnRadioGroup]
ExportAs: brnRadioGroup
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | `brn-radio-group-${++BrnRadioGroup._nextUniqueId}` | - |
| value | T | undefined | The value of the selected radio button. |
| disabled | boolean | false | Whether the radio group is disabled. |
| required | boolean | false | Whether the radio group should be required. |
| 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. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| valueChange | T | - | Emits when the value changes. |
| change | BrnRadioChange<T> | - | Event emitted when the group value changes. |
BrnRadio
Selector: brn-radio
ExportAs: brnRadio
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the radio button is disabled. |
| id | string | undefined | undefined | The unique ID for the radio button input. If none is supplied, it will be auto-generated. |
| aria-label | string | undefined | undefined | - |
| aria-labelledby | string | undefined | undefined | - |
| aria-describedby | string | undefined | undefined | - |
| value* (required) | T | - | The value this radio button represents. |
| inputStyles | string | 'position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;' | Styles applied to the visually hidden native input element. Bound via `[style]` so they apply through the CSSOM and are not blocked by a strict Content-Security-Policy. |
| required | boolean | false | Whether the radio button is required. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| change | BrnRadioChange<T> | - | Event emitted when the checked state of this radio button changes. |
Helm API
HlmRadioGroup
Selector: [hlmRadioGroup],hlm-radio-group
ExportAs: hlmRadioGroup
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | ClassValue | '' | - |
| name | string | `brn-radio-group-${++BrnRadioGroup._nextUniqueId}` | - |
| value | T | undefined | The value of the selected radio button. |
| disabled | boolean | false | Whether the radio group is disabled. |
| required | boolean | false | Whether the radio group should be required. |
| 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. |
| aria-describedby | string | null | null | - |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| valueChange | T | - | Emits when the value changes. |
HlmRadioIndicator
Selector: hlm-radio-indicator
ExportAs: hlmRadioIndicator
HlmRadio
Selector: hlm-radio
ExportAs: hlmRadio
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | ClassValue | '' | - |
| inputId | string | undefined | undefined | Used to set the id on the underlying brn element. |
| aria-label | string | undefined | undefined | Used to set the aria-label attribute on the underlying brn element. |
| aria-labelledby | string | undefined | undefined | Used to set the aria-labelledby attribute on the underlying brn element. |
| aria-describedby | string | undefined | undefined | Used to set the aria-describedby attribute on the underlying brn element. |
| value* (required) | T | - | The value this radio button represents. |
| required | boolean | false | Whether the checkbox is required. |
| disabled | boolean | false | Whether the checkbox is disabled. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| change | BrnRadioChange<T> | - | Event emitted when the checked state of this radio button changes. |
On This Page
Stop configuring. Start shipping.
Zerops powers spartan.ng and Angular teams worldwide.
One-command deployment. Zero infrastructure headaches.
Deploy with Zerops