Tableau UI for Angular

Radio Groups

A radio group lets the user pick one of a few options, with a value binding or a form control.

Import

Import TableauUiRadioGroupModule from tableau-ui-angular/radio-group. The options and the errors, tab-option and tab-error, come from TableauUiCommonModule in tableau-ui-angular/common.

Value binding

Bind [(value)], and listen to (valueChange) for the user's picks; each one here shows a snack. Each tab-option has a value:

  • text and hint are strings or templates;
  • icon adds an icon, which [iconParams] styles;
  • [disabled] keeps it from being picked.
The value: 1
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { TableauUiRadioGroupModule } from 'tableau-ui-angular/radio-group';
import { SnackService } from 'tableau-ui-angular/snack';

@Component({
  selector: 'app-radio-value-example',
  imports: [TableauUiCommonModule, TableauUiRadioGroupModule],
  templateUrl: './radio-value.example.html',
  styleUrl: './radio-value.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RadioValueExampleComponent {
  private readonly snacks = inject(SnackService);

  protected readonly $plan = signal<number | undefined>(1);

  // valueChange fires on each pick by the user, never when the app sets the value
  protected changed(value: number | undefined) {
    this.snacks.openSnack(`Radio group set to: ${value}`, 3000, 'info');
  }
}

Reactive forms

Bind [formControl] or formControlName. A tab-error in the group shows under its options. The control is touched once an option loses focus, at the second pick or on leaving the group, and each error waits for that; a disabled control disables the group. Each change here shows a snack, an error one while the value is invalid.

Size
The control: no value, invalid, untouched
import { AsyncPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { skip } from 'rxjs';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { FB, TableauUiFormModule } from 'tableau-ui-angular/form';
import { TableauUiRadioGroupModule } from 'tableau-ui-angular/radio-group';
import { SnackService } from 'tableau-ui-angular/snack';

@Component({
  selector: 'app-radio-forms-example',
  imports: [AsyncPipe, ReactiveFormsModule, TableauUiCommonModule, TableauUiFormModule, TableauUiRadioGroupModule],
  templateUrl: './radio-forms.example.html',
  styleUrl: './radio-forms.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RadioFormsExampleComponent {
  private readonly fb = inject(FB);
  private readonly snacks = inject(SnackService);

  // Only 3 is valid: 1 is below the minimum, 2 is disabled, 4 is above the maximum. Each error waits for the control
  // to be touched, as formHasError does: once an option loses focus, at the second pick or on leaving the group
  protected readonly size = this.fb.control<number | null>(null, [Validators.required, Validators.min(2), Validators.max(3)]);

  constructor() {
    // value$ gives the current value first, which it skips; by the time it emits, the meta holds the new validity
    this.size.value$.pipe(skip(1), takeUntilDestroyed()).subscribe(value => {
      this.snacks.openSnack(`Size set to: ${value}`, 3000, this.size.$meta().validity === 'VALID' ? 'info' : 'error');
    });
  }
}

A disabled value

The app can set a disabled option as the value: it shows selected and greyed out.

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { TableauUiRadioGroupModule } from 'tableau-ui-angular/radio-group';

@Component({
  selector: 'app-radio-disabled-example',
  imports: [TableauUiCommonModule, TableauUiRadioGroupModule],
  templateUrl: './radio-disabled.example.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RadioDisabledExampleComponent {}

Accessibility

The group is a radiogroup of native radios; the app names it.

  • Name it with aria-label or aria-labelledby on tab-radio-group, as the samples here do, or put it in a tab-form-field with a tab-label.
  • Its tab-error describes the group while it shows, through aria-describedby, and the group has aria-invalid="true" then. Ids the app puts in the group's own aria-describedby stay.
  • In a tab-form-field, put the tab-error on the field, not in the group: the field counts the group's own error as its own, and shows an empty one.
  • The arrow keys move to the next or previous option and pick it, past disabled ones; Space or Enter picks the focused option.