Select button

A segmented control for picking one of two to five short options, such as a time period or a view mode. It is single-choice; for several values use a multi select.

  • vig-select-button
  • ng-template[vigSelectOption]
Import
import { SelectButton } from '@vigdx/ui/select-button';
import { SelectOptionTemplate } from '@vigdx/ui/select';

Basic

Pass options as SelectOption objects and bind [(value)] . Clicking a segment selects it; as the segments are native radios, the arrow keys move and select in one step, following the visual order in right-to-left layouts.

Period

Showing totals per week.

Icons and custom content

icon names a registered icon shown before the label. For other content, an <ng-template vigSelectOption let-option> replaces the icon and label of each segment.

Status

Sort

Allow empty

With allowEmpty , clicking the selected segment again clears the value to null . Useful for optional filters.

Priority

Click the selected priority again to clear the filter.

Filter: high

Without a visible label

In a toolbar the context often names the control. Leave out label and set ariaLabel , which names the group for screen readers.

Orders

Disabled, read-only and error

An option with disabled: true is skipped by the arrow keys. disabled disables every segment, readonly keeps them focusable but ignores selection, and errors show once the field is touched and invalid .

Disabled option

Disabled

Read-only

Delivery

Choose a delivery option.

Reactive Forms

Import VigValueAccessor next to the component to use formControlName , [formControl] or ngModel . The field counts as touched once focus leaves the whole group.

Size

{
  "size": null
}

Signal Forms

vig-select-button implements FormValueControl<T | null> , so [formField] binds value and validation.

Theme

Theme: system

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="select-button"][data-part="label"] { … }: 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="select-button"]

SelectButton styling hooks
Part Element data-state
label The visible group label. —
group The role="radiogroup" segment bar. —
option One segment <label> . checked, unchecked
input The visually hidden radio of a segment. —
hint The vig-hint (a display: contents host; style its text part). —
disabled-reason The vig-hint with the disabled reason ( display: contents ). —
error The vig-field-error (a display: contents host; style its message part). —

Accessibility

  • Each segment is a <label> around a visually hidden native <input type="radio"> in a role="radiogroup", like vig-radio-group: the single tab stop, the arrow keys (which move and select) and right-to-left order come from the browser.
  • The selected segment has a primary border besides its raised background, and switches to the system Highlight colors in forced-colors mode; the focus ring is drawn on the segment.
  • Give the group a name: a visible label, or ariaLabel when there is none.
  • required, readonly and an invalid state set aria-required, aria-readonly and aria-invalid on the group; hint and error are linked through aria-describedby.
  • Segment labels are the accessible names, so keep them short but self-explanatory; icons are decorative.

API

SelectButton

vig-select-button component

Segmented control for a small exclusive choice (PrimeNG p-selectbutton territory). Each segment is a <label> around a visually hidden native <input type="radio"> sharing one name, so the single tab stop, arrow keys (which move and select) and form semantics come from the browser — like vig-radio-group, with a segmented look. Deliberately single-select; multi-pick lists belong to vig-multi-select.

SelectButton props
Name Type Default Description
allowEmptybooleanfalse

Clicking the selected segment deselects it (value becomes null).

ariaLabelstring | undefinedundefined
—
dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
hiddenbooleanfalse
—
hintstring | undefinedundefined
—
invalidbooleanfalse
—
labelstring''

Visible group label; omit for toolbar use and pass ariaLabel instead.

namestring''
—
optionsreadonly SelectOption<T>[][]
—
pendingbooleanfalse
—
readonlybooleanfalse
—
requiredbooleanfalse
—
touchedbooleanfalse
—
value model T | nullnull
—

SelectOptionTemplate

ng-template[vigSelectOption] directive

Custom rendering for options of vig-select, vig-multi-select, vig-listbox and vig-select-button, replacing the default icon + label. vig-select also uses it for the selected value shown in the trigger.

Bind the same options to vigSelectOptionOf (like ngForOf) to type let-option in the template; without it the option value is unknown.

Example :
<vig-select label="Status" [options]="statuses">
  <ng-template vigSelectOption [vigSelectOptionOf]="statuses" let-option>
    <i [class]="option.value" aria-hidden="true"></i> {{ option.label }}
  </ng-template>
</vig-select>
SelectOptionTemplate props
Name Type Default Description
vigSelectOptionOfreadonly SelectOption<T>[] | null | undefinedundefined

Type-only: the options the template renders, so the template type checker infers the option value type. Not read at runtime.

VigValueAccessor

directive

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.

VigValueAccessor methods
Signature Description
registerOnChange(fn: (value: unknown) => void): void
—
registerOnTouched(fn: () => void): void
—
setDisabledState(disabled: boolean): void
—
writeValue(value: unknown): void
—

Are you sure?