Component
Toggle
A two-state button that stays pressed. Use it on its own with a two-way pressed state, an icon, a variant and size; or wrap several in a toggle group for single or multiple selection, connected or spaced, with roving keyboard focus and form-control support.
Standalone toggle
bold: false · last change: —
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { phosphorBell, phosphorStar, phosphorTextB } from '@ng-icons/phosphor-icons/regular';
import { HbToggleImports } from '@herbst/ui';
@Component({
selector: 'hb-demo-toggle-basic',
imports: [HbToggleImports],
viewProviders: [provideIcons({ phosphorTextB, phosphorStar, phosphorBell })],
template: `
<div class="flex flex-wrap items-center gap-3">
<hb-toggle [(hbPressed)]="bold" hbIcon="phosphorTextB" (hbChange)="last.set($event)">
Bold
</hb-toggle>
<hb-toggle hbVariant="outline" hbIcon="phosphorStar" hbSize="lg">Star</hb-toggle>
<hb-toggle hbVariant="outline" hbSize="sm" [hbPressed]="true">Subscribed</hb-toggle>
<hb-toggle hbIcon="phosphorBell" hbDisabled>Muted</hb-toggle>
</div>
<p class="mt-3 font-mono text-[12px] text-muted-foreground">
bold: {{ bold() }} · last change: {{ last() }}
</p>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HbDemoToggleBasicComponent {
protected readonly bold = signal(false);
protected readonly last = signal<boolean | string>('—');
}
Single group
align: left · view: grid
Multiple group
marks: [bold, italic]
API reference
hb-toggle
| Property | Description | Type | Default |
|---|---|---|---|
| [(hbPressed)] | The pressed state, two-way bound. Ignored when inside a toggle group (the group owns selection). | boolean | false |
| [hbValue] | Identifies the toggle within a group — matched against the group value. | unknown | null |
| [hbVariant] / [hbSize] | Override the look per toggle; otherwise inherited from the group (or the defaults). | 'default' | 'outline' / 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'default' / 'md' |
| [hbIcon] | Leading icon rendered before the projected label. | string | '' |
| [hbDisabled] | Disable this toggle (the group can also disable all of them). | boolean | false |
| (hbChange) | Emits the new pressed state when the toggle is activated. | boolean | — |
hb-toggle-group
| Property | Description | Type | Default |
|---|---|---|---|
| [hbType] | Single selection (a value, or null) or multiple selection (an array). | 'single' | 'multiple' | 'single' |
| [(hbValue)] | The selected value(s), two-way bound. Also works as a form control (NG_VALUE_ACCESSOR). | unknown | unknown[] | null |
| [hbVariant] / [hbSize] | The look applied to every toggle in the group. | 'default' | 'outline' / 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'default' / 'md' |
| [hbConnected] | Join the toggles into a seamless segmented control; false spaces them with a gap. | boolean | true |
| [hbRollable] | Single mode only — allow clicking the active toggle again to clear the selection. | boolean | true |
| [hbDisabled] / [hbAriaLabel] | Disable the whole group, and label it for assistive technology. | boolean / string | false / "" |
| (hbChange) | Emits the new selection whenever it changes. | unknown | — |