Menu Bar
Menu Bar is a horizontal button bar with hierarchical drop-down menus. Menu items can either trigger an action, open a menu, or work as a toggle.
new tab
@state()
private items = [
{ text: 'View' },
{ text: 'Edit' },
{
text: 'Share',
children: [
{
text: 'On social media',
children: [{ text: 'Facebook' }, { text: 'Twitter' }, { text: 'Instagram' }],
},
{ text: 'By email' },
{ text: 'Get link' },
],
},
{
text: 'Move',
children: [{ text: 'To folder' }, { text: 'To trash' }],
},
{ text: 'Duplicate' },
];
@state()
private selectedItem?: MenuBarItem;
<vaadin-menu-bar
.items="${this.items}"
@item-selected="${this.itemSelected}"
></vaadin-menu-bar>
<div>Clicked item: ${this.selectedItem?.text}</div>
Styles
The following variants are available for adjusting the component’s appearance:
new tab
<vaadin-menu-bar
.items="${[{ text: 'Default', children: [{ text: 'Item' }] }]}"
></vaadin-menu-bar>
<vaadin-menu-bar
theme="tertiary"
.items="${[{ text: 'Tertiary', children: [{ text: 'Item' }] }]}"
></vaadin-menu-bar>
<vaadin-menu-bar
theme="primary"
.items="${[{ text: 'Primary', children: [{ text: 'Item' }] }]}"
></vaadin-menu-bar>
<vaadin-menu-bar
theme="small"
.items="${[{ text: 'Small', children: [{ text: 'Item' }] }]}"
></vaadin-menu-bar>
Variant | Usage recommendations |
---|---|
Tertiary | Corresponds to the tertiary button variant, omitting the background color. |
Primary | Corresponds to the primary button variant. As only one primary action should be presented in the same part of the UI, this should only be used for drop-down button use cases. |
Small | Compact variant. Can be combined with Tertiary and Primary. |
Tip | Default menu button styles can be customized
Note that the standard Menu Button styles can be adjusted using theme features, so these variants should only be used to differentiate special instances of the component.
|
Overflow
Items that don’t fit into the current width of the menu bar automatically collapse into an overflow menu at the end:
new tab
@state()
private items = [
{ text: 'View' },
{ text: 'Edit' },
{
text: 'Share',
children: [
{
text: 'On social media',
children: [{ text: 'Facebook' }, { text: 'Twitter' }, { text: 'Instagram' }],
},
{ text: 'By email' },
{ text: 'Get link' },
],
},
{
text: 'Move',
children: [{ text: 'To folder' }, { text: 'To trash' }],
},
{ text: 'Duplicate' },
];
<vaadin-split-layout>
<vaadin-menu-bar .items="${this.items}"></vaadin-menu-bar>
<div>Move the splitter to see overflow feature</div>
</vaadin-split-layout>
Menu Item Features
Icons
Menu items can have icons in addition to, or instead of text.
new tab
@state()
private items = [
{
component: this.createItem('share', 'Share'),
children: [
{ component: this.createItem('share', 'By email', true) },
{ component: this.createItem('link', 'Get link', true) },
],
},
{
component: this.createItem('copy', ''),
},
];
<vaadin-menu-bar theme="icon" .items="${this.items}"></vaadin-menu-bar>
Usage recommendations:
Use icons sparingly. Most actions are difficult to reliably represent with icons, and the benefit of icons in addition to text should be weighed against the additional visual noise this creates.
Menu items in dropdown menus should always have text labels.
Icon-only menu buttons should be primarily used for extremely common recurring actions with highly standardized, universally understood icons (for example, a cross for close).
Icon-only menu buttons should provide a textual alternative for screen readers using the
aria-label
attribute.
Menu Bars with icon-only top-level items can use the Tertiary Inline style variant to reduce the horizontal padding around the icons.
new tab
@state()
private items = [
{ component: this.createItem('eye', 'View') },
{ component: this.createItem('pencil', 'Edit') },
{
component: this.createItem('share', 'Share'),
children: [
{
text: 'On social media',
children: [{ text: 'Facebook' }, { text: 'Twitter' }, { text: 'Instagram' }],
},
{ text: 'By email' },
{ text: 'Get link' },
],
},
{
component: this.createItem('folder', 'Move'),
children: [{ text: 'To folder' }, { text: 'To trash' }],
},
{ component: this.createItem('copy', 'Duplicate') },
];
<vaadin-menu-bar theme="tertiary-inline" .items="${this.items}"></vaadin-menu-bar>
Warning | Other components in menu items
While it’s technically possible to put any UI element in a menu item, this can be problematic in terms of accessibility, as they cannot be focused and may not be correctly interpreted by assistive technologies.
|
Disabled Items
Menu items can be disabled to indicate that they are currently unavailable.
new tab
@state()
private items = [
{ text: 'View' },
{ text: 'Edit', disabled: true },
{
text: 'Share',
children: [{ text: 'By email', disabled: true }, { text: 'Get link' }],
},
];
Checkable Menu Items
Menu items in drop-down menus can be configured as checkable, for toggling options on and off.
new tab
@state()
private items = [
{
text: 'Options',
children: [{ text: 'Save automatically', checked: true }, { text: 'Notify watchers' }],
},
];
<vaadin-menu-bar
.items="${this.items}"
@item-selected="${this.itemSelected}"
></vaadin-menu-bar>
itemSelected(e: MenuBarItemSelectedEvent) {
const item = e.detail.value;
(item as SubMenuItem).checked = !(item as SubMenuItem).checked;
}
Note | Not a replacement for radio buttons
A Menu Bar with checkable items should not be used as a replacement for radio buttons in a form.
|
Dividers
You can use dividers to separate and group related content.
new tab
@state()
private items = [
{
text: 'Share',
children: [
{ text: 'Facebook' },
{ text: 'Twitter' },
{ text: 'Instagram' },
{ component: 'hr' },
{ text: 'By email' },
{ text: 'Get link' },
{ component: 'hr' },
{ text: 'Set permissions' },
],
},
];
<vaadin-menu-bar .items="${this.items}"></vaadin-menu-bar>
Use dividers sparingly to avoid creating unnecessary visual clutter.
Warning | Content other than menu items not accessible
While it’s technically possible to put any UI element in a drop-down menu, including interactive components, they will not be accessible by keyboard or assistive technologies.
|
Open on Hover
The component can be configured to open drop-down menus on hover instead of on click.
new tab
@state()
private items = [
{ text: 'View' },
{ text: 'Edit' },
{
text: 'Share',
children: [
{
text: 'On social media',
children: [{ text: 'Facebook' }, { text: 'Twitter' }, { text: 'Instagram' }],
},
{ text: 'By email' },
{ text: 'Get link' },
],
},
{
text: 'Move',
children: [{ text: 'To folder' }, { text: 'To trash' }],
},
{ text: 'Duplicate' },
];
<vaadin-menu-bar .items="${this.items}" open-on-hover></vaadin-menu-bar>
Keyboard Usage
Drop-Down and "Combo" Buttons
A Menu Bar with a single top-level item is essentially a drop-down button. This solution provides a better user experience and better accessibility than a regular Button paired with a Context Menu.
new tab
@state()
private items = [
{
text: 'John Smith',
children: [
{ text: 'Profile' },
{ text: 'Account' },
{ text: 'Preferences' },
{ component: 'hr' },
{ text: 'Sign out' },
],
},
];
<vaadin-menu-bar .items="${this.items}"></vaadin-menu-bar>
So-called “combo buttons” can be created in a similar way, for example to provide a set of variations on an action.
new tab
@state()
private items = [
{ text: 'Save' },
{
component: this.createItem(),
children: [{ text: 'Save as draft' }, { text: 'Save as copy' }, { text: 'Save and publish' }],
},
];
<vaadin-menu-bar theme="icon primary" .items="${this.items}"></vaadin-menu-bar>
Best Practices
Menu Bar should not be used for navigation. Use tabs for switching between content, or anchor elements for regular navigation.
Menu Bar is not an input field. Use Select, Combo Box, or Radio Button instead.