Buttons
Import
Import TableauUiButtonModule from tableau-ui-angular/button, and TableauUiButtonToggleModule from tableau-ui-angular/button-toggle. Every <button> and <a button> in a template that imports the module is a Tableau button.
Stroked
The default kind. Set color to plain, secondary (the default), primary or error; [loading] shows a spinner and stops clicks, as [disabled] does. Each button here loads for two seconds when clicked.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { SnackService } from 'tableau-ui-angular/snack';
type Color = 'error' | 'plain' | 'primary' | 'secondary';
@Component({
selector: 'app-button-stroked-example',
imports: [TableauUiButtonModule],
templateUrl: './button-stroked.example.html',
styleUrl: './button-stroked.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonStrokedExampleComponent {
private readonly snacks = inject(SnackService);
protected readonly $loading = signal<Record<Color, boolean>>({ plain: false, secondary: false, primary: false, error: false });
// Shows the button loading for two seconds, then a snack
protected async work(color: Color) {
this.$loading.update(loading => ({ ...loading, [color]: true }));
await new Promise(resolve => setTimeout(resolve, 2000));
this.$loading.update(loading => ({ ...loading, [color]: false }));
this.snacks.openSnack(`${color} button clicked`, 2000, color === 'error' ? 'error' : 'info');
}
}Raised
kind="raised" fills the button with its colour.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { SnackService } from 'tableau-ui-angular/snack';
type Color = 'error' | 'plain' | 'primary' | 'secondary';
@Component({
selector: 'app-button-raised-example',
imports: [TableauUiButtonModule],
templateUrl: './button-raised.example.html',
styleUrl: './button-raised.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonRaisedExampleComponent {
private readonly snacks = inject(SnackService);
protected readonly $loading = signal<Record<Color, boolean>>({ plain: false, secondary: false, primary: false, error: false });
// Shows the button loading for two seconds, then a snack
protected async work(color: Color) {
this.$loading.update(loading => ({ ...loading, [color]: true }));
await new Promise(resolve => setTimeout(resolve, 2000));
this.$loading.update(loading => ({ ...loading, [color]: false }));
this.snacks.openSnack(`${color} button clicked`, 2000, color === 'error' ? 'error' : 'info');
}
}Links
<a button> takes the same inputs, for a button that navigates.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { TableauUiCheckboxModule } from 'tableau-ui-angular/checkbox';
@Component({
selector: 'app-button-links-example',
imports: [TableauUiButtonModule, TableauUiCheckboxModule],
templateUrl: './button-links.example.html',
styleUrl: './button-links.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonLinksExampleComponent {
protected readonly repo = 'https://github.com/serionist/tableau-ui-angular';
protected readonly $loading = signal(false);
}Icon buttons
layout="icon" and layout="small-icon" size the button to its icon, for each kind, colour and state.
icon, plainicon, secondaryicon, primaryicon, errorsmall-icon, plainsmall-icon, secondarysmall-icon, primarysmall-icon, errorimport { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { TableauUiIconModule } from 'tableau-ui-angular/icon';
import { SnackService } from 'tableau-ui-angular/snack';
type Color = 'error' | 'plain' | 'primary' | 'secondary';
@Component({
selector: 'app-button-icons-example',
imports: [TableauUiButtonModule, TableauUiIconModule],
templateUrl: './button-icons.example.html',
styleUrl: './button-icons.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonIconsExampleComponent {
private readonly snacks = inject(SnackService);
protected readonly repo = 'https://github.com/serionist/tableau-ui-angular';
protected readonly layouts = ['icon', 'small-icon'] as const;
protected readonly colors: readonly Color[] = ['plain', 'secondary', 'primary', 'error'];
protected readonly $loading = signal<Record<Color, boolean>>({ plain: false, secondary: false, primary: false, error: false });
// Shows the button loading for two seconds, then a snack
protected async work(color: Color) {
this.$loading.update(loading => ({ ...loading, [color]: true }));
await new Promise(resolve => setTimeout(resolve, 2000));
this.$loading.update(loading => ({ ...loading, [color]: false }));
this.snacks.openSnack(`${color} button clicked`, 2000, color === 'error' ? 'error' : 'info');
}
}Button toggle
tab-button-toggle picks one of its tab-options: bind [(selectedValue)]. An option takes an icon, a text or both, and can be disabled, as can the whole toggle. Name the toggle with aria-label, and give an option with only an icon a text hint, its name.
Icons only
Icon and text, the full width
Disabled
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { TableauUiButtonToggleModule } from 'tableau-ui-angular/button-toggle';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { SnackService } from 'tableau-ui-angular/snack';
@Component({
selector: 'app-button-toggle-example',
imports: [TableauUiButtonToggleModule, TableauUiCommonModule],
templateUrl: './button-toggle.example.html',
styleUrl: './button-toggle.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonToggleExampleComponent {
private readonly snacks = inject(SnackService);
// It starts on a disabled option, which the user can't pick again once they leave it
protected readonly $alignment = signal<string | undefined>('left');
protected changed(alignment: string | undefined) {
this.snacks.openSnack(`Button toggle value changed: ${alignment ?? '[undefined]'}`, 2000, 'info');
}
}Accessibility
A button toggle follows the WAI-ARIA radio group pattern: its options take the focus, not the toggle.
- The toggle is a
radiogroup, named by the app'saria-labeloraria-labelledbyontab-button-toggle. - Each option is a
radiothat says whether it is checked or disabled, named by its text. An option with only an icon is named by its texthint, which its tooltip shows when it takes focus from the keyboard; a template hint names nothing. - The toggle is one Tab stop: the checked option, or the first enabled one while none is checked. A disabled toggle is out of the Tab order. Code that focused the toggle focuses its checked option.
| Key, on an option | What it does |
|---|---|
| Right, Down | Checks the next enabled option, past the end to the first, and moves the focus to it |
| Left, Up | Checks the previous enabled option, past the start to the last, and moves the focus to it |
| Space | Checks the option that has focus |