Soracom

Design System
  1. Home
  2. Design system
  3. Elements
  4. Menu

Menu

Menu displays a list of menu items

The ds-menu component can be used directly on page, or as part of ds-menubutton.

Options

Basic usage

Basic usage - anchor elements

html
Copy

Basic usage - button elements

html
Copy

Selected menu items

To highlight the currently selected menu item, either add the class ds-menu__item--selected or if you are using ARIA attributes you can use aria-selected="true".

Highlight selected item with class

html
Copy

Highlight selected item with ARIA attribute

html
Copy

Disabled menu items

Any button element with a disabled attribute, or any a element with href="" (empty value), href (with no value) or missing href will be displayed as disabled.

Disabled menu items

html
Copy

Dividers

Adjacent html ul elements will automatically be visually displayed with a divider.

Grouped list dividers

html
Copy

Menu headers can be introduced by using ds-text components.

Menu headers

html
Copy

Collapsible sub menus can be displayed by using html <details> element

Sub menus (click sub menu to view contents)

html
Copy

Width

Narrow, mid, wide

ds-menu at default, narrow, mid and wide sizes

Height

By default the menu will be the height of the menu contents. You can also restrict the overall height of the menu and cause the contents to scroll. If the menu can scroll, a shadow will be added at the bottom/top of the menu to indicate the menu is scrollable.

You can apply these settings to either a ds-menubutton or to a standalone ds-menu component.

There are two ways to restrict the height.

Restrict the height to the viewport

Adding the class --viewport will restrict the height to 100vh - --ds-header-height (usually 100vh - 60px) and force the menu to scroll.

Using viewport height - if the browser height is less than the menu height, the menu will scroll

Restrict the height to a specific size

You can restrict the height by setting the --ds-menu-height or --ds-menu-max-height CSS var (either in a css file, inline style tag or via javascript).

  • --ds-menu-height will force the menu to an exact size, white space will be included below the menu items if there are not enough items to fill the full menu
  • --ds-menu-max-height will be as high as the list of menu items, but will limit the maximum height
let myCustomMenu = document.getElementById("customMenu");
myCustomMenu.style.setProperty("--ds-menu-height", "400px");

Setting a height using inline style tag

Icons can be applied to each menu item using ds-text--icon-*.

If an anchor in a menu item has a target="_blank" attribute, the menu item will automatically display the --icon-external-link icon.

If a button in a menu item has a formtarget="_blank" attribute, the menu item will automatically display the --icon-external-link icon.

Menu icons

html
Copy

Descriptive text can be added to each menu item by including an html span element

Menu items descriptions

html
Copy

Notification indicator

A menu item can display a notification indicator (dot) by adding the class __item --notification.

html
Copy

Additionally, if the menu item has an attribute data-notification-counter set to a non-empty value, that value will be shown in the indicator. If the attribute is set to empty data-notification-counter="" the indicator dot will be hidden.

html
Copy

Styles

Simple style

html
Copy
html
Copy

Compact style

html
Copy

Table of Contents style

html
Copy

Accessibility

When used directly on page, this component is accessible. When used inside ds-menubutton, additional accessibility and keyboard support is required.

Role and ARIA attributes

See above

Keyboard access

When used directly on page this component can be selected using the browsers native tab and shift-tab keyboard command and enter to activate the selected item.

References

Examples

Compact dropdown with scrolling

html
Copy

Manifest

The component manifest describes this component's API — its modifiers, structure, data attributes, CSS custom properties, accessibility notes, and example markup. It is consumed by tooling such as AI assistants and code generators.

Latest version: https://assets.soracom.io/sds/latest/ds-menu/index.mjs

index.mjs
Copy