Tableau UI for Angular

Menu

A menu opens from an element on a click: any content, or a list of items with submenus.

Import

Import TableauUiMenuModule from tableau-ui-angular/menu, and for a list of items TableauUiMenuButtonModule from tableau-ui-angular/menu-button.

A menu

A template marked menu holds the content, and [attachedMenu] opens it from an element on a click. The element says whether the menu is open, through aria-expanded.

Input or outputWhat it does
menuLocationbottom, the default, top, left or right; the menu moves to the other side when it would leave the window
width, minWidth, maxWidthCSS widths, or parentWidth for the element's width
height, minHeight, maxHeightCSS heights
closeOnBackdropClick, closeOnEscapeClose the menu on a click outside it, and on Escape; both on by default
(opened), (closed)Emitted as the menu opens and closes; open() and close() do it from code
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { TableauUiMenuModule } from 'tableau-ui-angular/menu';

@Component({
  selector: 'app-menu-simple-example',
  imports: [TableauUiButtonModule, TableauUiMenuModule],
  templateUrl: './menu-simple.example.html',
  styleUrl: './menu-simple.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MenuSimpleExampleComponent {}

Menu items

A template marked buttonMenu holds a tab-menu-button-group of tab-menu-button items. An item that holds items opens them as a submenu; any other emits (clicked) and closes the menu. The arrow keys move through the items, and Enter or Space runs one.

  • color is secondary, the default, plain, primary or error.
  • [disabled] and [loading] keep an item from running.
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { TableauUiMenuModule } from 'tableau-ui-angular/menu';
import { TableauUiMenuButtonModule } from 'tableau-ui-angular/menu-button';
import { SnackService } from 'tableau-ui-angular/snack';

@Component({
  selector: 'app-menu-buttons-example',
  imports: [TableauUiButtonModule, TableauUiMenuModule, TableauUiMenuButtonModule],
  templateUrl: './menu-buttons.example.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MenuButtonsExampleComponent {
  private readonly snacks = inject(SnackService);

  // An item without items of its own emits clicked, and the menu closes
  protected run(action: string) {
    this.snacks.openSnack(`${action} clicked`, 3000, 'info');
  }
}

Width

A buttonMenu is at least as wide as its element, as its minWidth is parentWidth by default. Another minWidth, such as fit-content, lets it fit its items.

import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { TableauUiButtonModule } from 'tableau-ui-angular/button';
import { TableauUiMenuModule } from 'tableau-ui-angular/menu';
import { TableauUiMenuButtonModule } from 'tableau-ui-angular/menu-button';
import { SnackService } from 'tableau-ui-angular/snack';

@Component({
  selector: 'app-menu-width-example',
  imports: [TableauUiButtonModule, TableauUiMenuModule, TableauUiMenuButtonModule],
  templateUrl: './menu-width.example.html',
  styleUrl: './menu-width.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MenuWidthExampleComponent {
  private readonly snacks = inject(SnackService);

  protected sort(by: string) {
    this.snacks.openSnack(`Sorted by ${by}`, 3000, 'info');
  }
}