A menu is a floating panel that displays a list of actions or navigational items.
Menus appear when users interact with a menu activator button. Use menus for secondary actions or options that don't require immediate access.
<button daff-button color="theme" [daffMenuActivator]="menu">
Account
</button>
When to use
When not to use
Import DAFF_MENU_COMPONENTS into your component:
import { DAFF_MENU_COMPONENTS } from '@daffodil/design/menu';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_MENU_COMPONENTS,
],
})
export class CustomComponent {}
Deprecation notice:
DaffMenuModuleis deprecated. Use the standalone component imports instead.
A menu is composed of an activator, a container, and one or more items:
<button [daffMenuActivator]="actionsMenu">
Actions
</button>
<ng-template #actionsMenu>
<daff-menu>
<button daff-menu-item>
<fa-icon [icon]="faEdit" daffPrefix></fa-icon>
Edit
</button>
<button daff-menu-item>
<fa-icon [icon]="faTrash" daffPrefix></fa-icon>
Delete
</button>
<a href="/settings" daff-menu-item>
<fa-icon [icon]="faCog" daffPrefix></fa-icon>
Settings
</a>
</daff-menu>
</ng-template>
[daffMenuActivator]: A directive attached to a button that triggers the menu to open. The selector doubles as an input for the menu content to display.<daff-menu>: The container component that holds all menu items.<daff-menu-item>: A single action or navigation item within the menu. Use with an anchor or button element.[daffPrefix]: Adds a decorative icon before the menu item content.Use the actiavtor's isOpen property to track whether the menu is currently open or closed. Use this to update your UI based on the menu state, such as changing icons or styling.
<button
daff-button
color="theme"
[daffMenuActivator]="menuContent"
#activator="daffMenuActivator"
>
Account
<fa-icon
daffSuffix
size="sm"
[icon]="activator.isOpen() ? faChevronUp : faChevronDown"
></fa-icon>
</button>
Menus generate a unique id automatically. To set your own, add an id to the activator and the menu becomes {id}-menu.
<button
daff-button
color="theme"
[daffMenuActivator]="menu"
id="menu-with-id">
Account
</button>
Menu follows the Menu and Menubar WAI-ARIA design pattern.
role="menu" and role="menuitem" on appropriate elementsaria-expanded on the activator indicating the menu state<button> for actions, <a> for navigation)Keyboard focus is placed on the first item when a menu is opened.
| Key | Action |
|---|---|
Enter / Space |
Opens the menu when focused on the activator, or activates the focused menu item |
Escape |
Closes the menu and returns focus to the menu activator |
Down Arrow |
Moves focus to the next item. If focus is on the last item, focus moves to the first item |
Up Arrow |
Moves focus to the previous item. If focus is on the first item, focus moves to the last item |
Home |
Moves focus to the first item |
End |
Moves focus to the last item |