Menu

Menu

On this page

On this page

Menu

Groups of links, actions or tools that a user can interact with.

npm install @vrembem/menu
Copied!
SCSS
@use "@vrembem/menu";
Copied!

Options

Menu is built as a Sass module. Sass options are used to control CSS output, while design token CSS variables control the styling of the component. Below are the available configuration options.

Sass

Menu comes with the following Sass configuration options that can be set using either the config module or Sass with clause methods.

SCSS
@use "@vrembem/menu" with (
  $config: (
    // Toggle for outputting menu--inline modifier breakpoint variants
    // @type boolean
    "inline-breakpoints": true,

    // Toggle for outputting menu--full modifier breakpoint variants
    // @type boolean
    "full-breakpoints": true
  )
);
Copied!

Design tokens

Menu uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.

VariableFallback
--vb-menu-size
Copied!
var(--vb-font-size)
Copied!
--vb-menu-line-height
Copied!
var(--vb-line-height)
Copied!
--vb-menu-padding-y
Copied!
0.5rem
Copied!
--vb-menu-padding-x
Copied!
0.75rem
Copied!
--vb-menu-border-radius
Copied!
var(--vb-border-radius)
Copied!
--vb-menu-gap
Copied!
1px
Copied!
--vb-menu-divider-color
Copied!
var(--vb-border-color)
Copied!
--vb-menu-divider-size
Copied!
1px
Copied!
--vb-menu-divider-spacing
Copied!
0.5rem 0.75rem
Copied!
--vb-menu-label-size
Copied!
var(--vb-font-size-sm)
Copied!
--vb-menu-label-gap
Copied!
0.5rem
Copied!
--vb-menu-label-foreground
Copied!
--vb-menu-action-gap
Copied!
0.5rem
Copied!
--vb-menu-background
Copied!
transparent
Copied!
--vb-menu-background-hover
Copied!
var(--vb-menu-background, color-mix(in oklch, currentcolor 4%, transparent))
Copied!
--vb-menu-background-focus
Copied!
var(--vb-menu-background, transparent)
Copied!
--vb-menu-background-active
Copied!
var(--vb-menu-background, color-mix(in oklch, currentcolor 8%, transparent))
Copied!
--vb-menu-foreground
Copied!
--vb-menu-foreground-hover
Copied!
--vb-menu-foreground-focus
Copied!
--vb-menu-foreground-active
Copied!
--vb-menu-disabled-background
Copied!
transparent
Copied!
--vb-menu-disabled-foreground
Copied!
--vb-menu-active-background
Copied!
transparent
Copied!
--vb-menu-active-foreground
Copied!

Basic usage

The menu component is composed of at minimum three parts: menu, menu__item and menu__action. The menu and menu items should be a <ul> and list items <li> respectively while the menu action can be either an <a> or <button> element. Also available is the optional menu__label and menu__divider elements to help visually group menu items.

HTML
<ul class="menu">
  <li class="menu__label">...</li>
  <li class="menu__item">
    <button class="menu__action">
      ...
    </button>
  </li>
  <li class="menu__divider"></li>
</ul>
Copied!

Use the flex-grow utility class to wrap text inside the menu__action element. Additional elements inside the menu action receive appropriate spacing.

HTML
<ul class="menu">
  <li class="menu__item">
    <button class="menu__action">
      <span>...</span>
      <span class="flex-grow">...</span>
      <span>...</span>
    </button>
  </li>
  ...
</ul>
Copied!

For links that only contain an icon, you can use the menu__action--icon element modifier to create a square link similar to the button--icon modifier.

HTML
<ul class="menu menu--inline">
  <li class="menu__item">
    <button class="menu__action menu__action--icon">
      ...
    </button>
  </li>
  ...
</ul>
Copied!

is-active

Adding the is-active class will provide visual indication that the action is currently in an active state.

HTML
<ul class="menu menu--inline">
  <li class="menu__item">
    <button class="menu__action is-active" disabled>
      ...
    </button>
  </li>
  ...
</ul>
Copied!

disabled

Adding the boolean disabled attribute will provide visual indication that the user should not be able to interact with the action.

HTML
<ul class="menu menu--inline">
  <li class="menu__item">
    <button class="menu__action" disabled>
      ...
    </button>
  </li>
  ...
</ul>
Copied!

Used to apply horizontal menu styles. This is typically used for short menus or toolbars where vertical space can be saved.

HTML
<ul class="menu menu--inline">...</ul>
Copied!

Breakpoint variants

These modifiers come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map. Breakpoint variants output can be toggled using the menu-inline-breakpoints config option (default: true).

Current view-port width: ...

HTML
<ul class="menu lg:menu--inline">...</ul>
Copied!

Available variants

  • xs:menu--inline
  • sm:menu--inline
  • md:menu--inline
  • lg:menu--inline
  • xl:menu--inline

Used to span a horizontal menu to fill the full width of its container. This modifier is meant to be paired with the menu--inline modifier as the default styles of a vertical menu already fill the full width of their container.

HTML
<ul class="menu menu--inline menu--full">...</ul>
Copied!

Breakpoint variants

These modifiers come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map. Breakpoint variants output can be toggled using the menu-full-breakpoints config option (default: true).

Current view-port width: ...

HTML
<ul class="menu menu--inline lg:menu--full">...</ul>
Copied!

Available variants

  • xs:menu--full
  • sm:menu--full
  • md:menu--full
  • lg:menu--full
  • xl:menu--full