Skip to main content
2.0.56
Light Dark System
Compact Comfortable

Menu Item

<zn-menu-item> ZnMenuItem
Since 1.0 experimental

Short summary of the component’s intended use.

Menu item
<zn-menu-item>Menu item</zn-menu-item>

Examples

Colors Example

Menu item Menu item Menu item Menu item Menu item Menu item Menu item Menu item
<zn-menu-item>Menu item</zn-menu-item>
<zn-menu-item color="primary">Menu item</zn-menu-item>
<zn-menu-item color="secondary">Menu item</zn-menu-item>
<zn-menu-item color="transparent">Menu item</zn-menu-item>
<zn-menu-item color="error">Menu item</zn-menu-item>
<zn-menu-item color="info">Menu item</zn-menu-item>
<zn-menu-item color="success">Menu item</zn-menu-item>
<zn-menu-item color="warning">Menu item</zn-menu-item>

Count

Set count to show a count as a pill at the end of the item, as a navbar tab shows one. A count of 0 is drawn muted.

Support Unassigned Billing
<zn-menu style="max-width: 260px">
  <zn-menu-item count="3">Support</zn-menu-item>
  <zn-menu-item count="74">Unassigned</zn-menu-item>
  <zn-menu-item count="0">Billing</zn-menu-item>
</zn-menu>

Keeping the Dropdown Open

A menu item inside a zn-dropdown closes it on select. keep-open exempts a single item, for rows that change how the panel behaves rather than committing a choice — an operator picker above a list of values, say. stay-open-on-select on the dropdown itself still covers every item at once.

Sort Ascending Descending Name Created
<zn-dropdown>
  <zn-button slot="trigger" icon="chevron-down@lu" icon-position="right">Sort</zn-button>
  <zn-menu>
    <zn-menu-item type="checkbox" keep-open checked>Ascending</zn-menu-item>
    <zn-menu-item type="checkbox" keep-open>Descending</zn-menu-item>
    <zn-menu-item value="name">Name</zn-menu-item>
    <zn-menu-item value="created">Created</zn-menu-item>
  </zn-menu>
</zn-dropdown>

Choosing One of Several

type="radio" is a choice of one: choosing an item ticks it and unticks the menu’s other radio items, and screen readers announce it as one of a set.

Sort Newest first Oldest first
<zn-dropdown>
  <zn-button slot="trigger" icon="chevron-down@lu" icon-position="right">Sort</zn-button>
  <zn-menu>
    <zn-menu-item type="radio" value="newest" checked>Newest first</zn-menu-item>
    <zn-menu-item type="radio" value="oldest">Oldest first</zn-menu-item>
  </zn-menu>
</zn-dropdown>

Submitting a Form

Set form to the id of a <form> to submit it when the item is chosen, so a menu can run the same action as a button elsewhere on the page.

Archive
<form id="menu-item-archive" action="/archive" method="post" onsubmit="event.preventDefault()"></form>
<zn-menu>
  <zn-menu-item form="menu-item-archive">Archive</zn-menu-item>
</zn-menu>

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/@kubex/zinc@2.0.56/dist/components/menu-item/menu-item.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.jsdelivr.net/npm/@kubex/zinc@2.0.56/dist/components/menu-item/menu-item.js';

To import this component using a bundler:

import '@kubex/zinc/dist/components/menu-item/menu-item.js';

Slots

Name Description
(default) The default slot.
example An example slot.

Learn more about using slots.

Properties

Name Description Reflects Type Default
type The type of menu item to render. To use checked, this value must be checkbox, or radio for one choice of several, where choosing it unchecks the menu’s other radio items. 'normal' | 'checkbox' | 'radio' 'normal'
variant The item’s visual style. A standalone item defaults to navigation styling; a parent zn-menu sets this to dropdown or shell automatically. navigation is an app sidebar’s row, which a zn-menu-group sets on its rows; it collapses with the shell’s sidebar (see setNavigationCollapsed). 'default' | 'dropdown' | 'shell' | 'navigation' 'default'
collapsed Draws a navigation item as an icon tile with its label in a tooltip, following the shell’s sidebar. boolean false
checked Draws the item in a checked state. boolean false
value A unique value to store in the menu item. This can be used as a way to identify menu items when selected. string ''
loading Draws the menu item in a loading state. boolean false
disabled Draws the menu item in a disabled state, preventing selection. boolean false
keepOpen
keep-open
Leaves a containing dropdown open when this item is selected, whatever the dropdown’s own setting. boolean false
flush Removes all padding from the menu item. boolean false
flushX
flush-x
Removes horizontal (left/right) padding only. Ignored if flush is set. boolean false
flushY
flush-y
Removes vertical (top/bottom) padding only. Ignored if flush is set. boolean false
noBorder
no-border
Removes the border from the menu item. boolean false
active Marks the menu item as currently active/selected. boolean false
shortcut A keyboard shortcut shown as a key cap at the end of the item, such as E or ⌘K. string -
count A count shown as a pill at the end of the item, as a navbar tab shows one; a count of 0 is drawn muted. string -
form The id of a <form> in the same document or shadow root to submit when the item is chosen. string -
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
zn-event-name Emitted as an example. -

Learn more about events.

Methods

Name Description Arguments
getTextLabel() Returns a text label based on the contents of the menu item’s default slot. -

Learn more about methods.

Custom Properties

Name Description Default
--example An example CSS custom property.

Learn more about customizing CSS custom properties.

Parts

Name Description
base The component’s base wrapper.
shortcut The key cap showing the item’s shortcut.
count The pill showing the item’s count.

Learn more about customizing CSS parts.

Dependencies

This component automatically imports the following dependencies.

  • <zn-example>