Documentation

Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Menu Bar

Menu Bar is a horizontal button bar with hierarchical drop-down menus. Menu items can trigger an action, open a menu, or work as a toggle.

Open in a
new tab
Source code
menu-bar-basic.ts
MenuBarBasic.java

Styles

Default Variants

The following variants are available to adjust the appearance of the component:

Open in a
new tab
Source code
menu-bar-styles.ts
MenuBarStyles.java
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 be used only for drop-down button use cases.

Small

Compact variant. Can be combined with Tertiary and Primary.

Tip
Default menu button styles can be customized
The standard Menu Button styles can be adjusted using theme features. These variants should be used only to differentiate special instances of the component.

Alignment

Top-level items are aligned to the start of the Menu Bar, by default. Use the "end-aligned" theme variant to align them to the end, instead.

Open in a
new tab
Source code
menu-bar-right-aligned.ts
MenuBarRightAligned.java

Styling Menu Items

An individual menu item can be styled using a custom variant.

To style a root-level item, create a custom variant for the vaadin-menu-bar-button component.

To style a sub-menu item, create a custom variant for the vaadin-context-menu-item component.

See Vaadin Component Variants for details of how to add style sheets for these components.

Open in a
new tab
Source code
menu-bar-custom-theme.ts
vaadin-context-menu-item.css
vaadin-context-menu-item.css
vaadin-menu-bar-button.css
vaadin-menu-bar-button.css
MenuBarCustomTheme.java
vaadin-context-menu-item.css
vaadin-context-menu-item.css
vaadin-menu-bar-button.css
vaadin-menu-bar-button.css

Overflow

Items that don’t fit into the current width of the menu bar collapse automatically into an overflow menu at the end:

Open in a
new tab
Source code
menu-bar-overflow.ts
MenuBarOverflow.java

Icons

Menu items can have icons in addition to, or instead of text.

Open in a
new tab
Source code
menu-bar-icons.ts
MenuBarIcons.java

Usage recommendations:

  • Use icons sparingly. Most actions are difficult to represent reliably with icons. The benefit of icons in addition to text should be weighed against the visual distractions it may create.

  • Menu items in drop-down menus should always have text labels.

  • Icon-only menu buttons should be used primarily for common recurring actions with highly standardized, universally understood icons, such a cross for "close".

  • Icon-only menu buttons should provide a textual alternative for screen readers using the aria-label attribute or tooltips.

Menu Bars with icon-only top-level items can use the Tertiary Inline style variant to reduce the horizontal padding around the icons.

Open in a
new tab
Source code
menu-bar-icon-only.ts
MenuBarIconOnly.java
Warning
Other components in menu items
While it’s technically possible to put any UI element in a menu item, this can cause problems for accessibility as it may not be possible to focus them, and they may not be interpreted correctly by assistive technologies.

Disabled Items

Menu items can be disabled to show that they are unavailable currently.

Open in a
new tab
Source code
menu-bar-disabled.ts
MenuBarDisabled.java

Checkable Menu Items

Menu items in drop-down menus can be configured as checkable to toggle options on and off.

Open in a
new tab
Source code
menu-bar-checkable.ts
MenuBarCheckable.java
Note
Not a replacement for radio buttons
A Menu Bar with checkable items shouldn’t be used as a replacement for radio buttons in a form.

Dividers

You can use dividers to separate and group related content.

Open in a
new tab
Source code
menu-bar-dividers.ts
MenuBarDividers.java

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 are not 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.

Open in a
new tab
Source code
menu-bar-open-on-hover.ts
MenuBarOpenOnHover.java

Tooltips

Tooltips can be configured on top-level items to provide additional information, especially for icon-only items. When a top-level item is disabled, the corresponding tooltip isn’t shown.

Open in a
new tab
Source code
menu-bar-tooltip.ts
MenuBarTooltip.java

See Tooltips documentation for details on tooltip configuration.

Keyboard Usage

Top-Level Items

Interaction Keyboard Shortcut

Navigate between top-level items.

Left and Right arrow keys

Open top-level menu.

Down / Space / Enter

Trigger top-level item with a menu.

Space / Enter

Interaction Keyboard Shortcut

Navigate between items in a drop-down menu.

Up and Down arrow keys

Open sub-menu.

Right / Space / Enter

Trigger menu item without a sub-menu.

Space / Enter

Return to previous menu.

Left

Close the drop-down menu.

Esc

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.

Open in a
new tab
Source code
menu-bar-drop-down.ts
MenuBarDropDown.java

So-called "combo buttons" can be created in a similar way. For example, they can be created to provide a set of variations on an action.

Open in a
new tab
Source code
menu-bar-combo-buttons.ts
MenuBarComboButtons.java

Internationalization (i18n)

Menu Bar provides an API for localization. Currently, only the accessible label for the overflow menu button can be customized.

Source code
menu-bar-internationalization.ts
MenuBarInternationalization.java

Best Practices

  • Menu Bar shouldn’t be used for navigation. Use tabs to switch between content, or anchor elements for regular navigation.

  • Menu Bar isn’t an input field. Use Select, Combo Box, or Radio Button instead.

Component Usage recommendations

Button

Regular Button component for individual actions.

Select

Drop-down input field.

Tabs

Tabs should be used to split content into sections that the user can switch between.

Context Menu

A generic drop-down menu that can be triggered from any component.

BCC76FD2-FB02-4F71-A6DF-7574CAC1C662