Toggle button
vig-toggle-button
import { ToggleButton } from '@vigdx/ui/toggle-button';Basic
[(value)] to a boolean signal. onLabel is shown while pressed and offLabel while not pressed; the pressed style uses the primary colour.
Following: false · Subscribed: true
Single label
offLabel the button keeps the onLabel text in both states and only its style and aria-pressed change. This suits filter chips and layer switches.
Accessible name
ariaLabel sets the accessible name. It is also the hook for translating that name.
Disabled
disabled keeps the current state visible but removes the button from the tab order; use hint to say why it cannot be changed.
Only owners can change this.
Reactive Forms
VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .
Signal Forms
vig-toggle-button implements FormValueControl<boolean> , so [formField] binds each button to a boolean field of the model.
Visible layers: traffic
Styling hooks
Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="toggle-button"][data-part="control"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.
Scope: [data-scope="toggle-button"]
| Part | Element | data-state |
|---|---|---|
control | <button> ( aria-pressed ). | on, off |
hint | vig-hint (a display: contents host; style its text part). | — |
disabled-reason | vig-hint with the disabled reason ( display: contents ). | — |
error | vig-field-error (a display: contents host; style its message part). | — |
Accessibility
- A native
<button>witharia-pressed, following the APG toggle button pattern; Enter and Space toggle it. - With a single label (or a fixed
ariaLabel) the name stays constant andaria-pressedcarries the state. WhenonLabelandoffLabeldiffer, the changing label is the state, soaria-pressedis left off rather than contradicting it. - Wrap related buttons in an element with
role="group"and anaria-labelso the set has a name. - Hint, disabled reason and error are linked through
aria-describedby; a touched, invalid button setsaria-invalid="true".readonlykeeps the button focusable but inert witharia-disabled="true"(aria-readonlyis not valid on buttons).
API
ToggleButton
vig-toggle-buttonA pressed-state button for a boolean choice that reads as an action
(PrimeNG p-togglebutton territory). With one label (or an ariaLabel)
the name stays fixed and aria-pressed carries the state; when
onLabel/offLabel differ the changing label is the state, so
aria-pressed is left off (announcing both would contradict). Readonly
keeps the button focusable but inert (aria-disabled).
| Name | Type | Default | Description |
|---|---|---|---|
ariaLabel | string | undefined | undefined | — |
dirty | boolean | false | — |
disabled | boolean | false | — |
disabledReasons | readonly WithOptionalFieldTree<DisabledReason>[] | [] | — |
errorMessages | Record<string, string> | — | — |
errors | readonly ValidationError.WithOptionalFieldTree[] | [] | — |
hidden | boolean | false | — |
hint | string | undefined | undefined | — |
invalid | boolean | false | — |
name | string | '' | — |
offLabel | string | undefined | undefined | — |
onLabel | string | — | Label while pressed; also the fallback when |
pending | boolean | false | — |
readonly | boolean | false | — |
required | boolean | false | — |
touched | boolean | false | — |
value | boolean | false | — |
| Name | Payload | Description |
|---|---|---|
touch | void | — |
valueChange | boolean | — |
| Signature | Description |
|---|---|
focus(options?: FocusOptions): void | Moves focus to the control's interactive element (the input, or the
trigger of a popup control). Signal Forms calls it through
|
reset(): void | Returns the control to its pristine look: drops in-progress text, closes
an open popup, clears errors the component raised itself and the
submitted state of |
VigValueAccessor
Bridges the vigdx form fields to Reactive Forms (formControl,
formControlName) and template-driven forms (ngModel). Import it next to
the component; Signal Forms ([formField]) need no accessor.
| Signature | Description |
|---|---|
registerOnChange(fn: (value: unknown) => void): void | — |
registerOnTouched(fn: () => void): void | — |
setDisabledState(disabled: boolean): void | — |
writeValue(value: unknown): void | — |