Menu Item
<ahi-menu-item> | AhiMenuItem
Menu items provide options for the user to pick from in a menu.
Examples
Prefix and Suffix
Add content to the start and end of menu items using the prefix and suffix slots.
<ahi-menu style="max-width: 200px;">
<ahi-menu-item>
<ahi-icon slot="prefix" name="home"></ahi-icon>
Home
</ahi-menu-item>
<ahi-menu-item>
<ahi-icon slot="prefix" name="mail"></ahi-icon>
Messages
<ahi-badge slot="suffix" status="info">12</ahi-badge>
</ahi-menu-item>
<ahi-divider></ahi-divider>
<ahi-menu-item>
<ahi-icon slot="prefix" name="settings"></ahi-icon>
Settings
</ahi-menu-item>
</ahi-menu>
Disabled
Add the disabled attribute to disable the menu item so it cannot be selected.
<ahi-menu style="max-width: 200px;">
<ahi-menu-item>Option 1</ahi-menu-item>
<ahi-menu-item disabled>Option 2</ahi-menu-item>
<ahi-menu-item>Option 3</ahi-menu-item>
</ahi-menu>
Loading
Use the loading attribute to indicate that a menu item is busy. Like a disabled enu item,
clicks will be suppressed until the loading state is removed.
<ahi-menu style="max-width: 200px;">
<ahi-menu-item>Option 1</ahi-menu-item>
<ahi-menu-item loading>Option 2</ahi-menu-item>
<ahi-menu-item>Option 3</ahi-menu-item>
</ahi-menu>
Checkbox menu items
Set the type attribute to checkbox to create a menu item that will toggle on and
off when selected. You can use the checked attribute to set the initial state.
Checkbox menu items are visually indistinguishable from regular menu items. Their ability to be toggled is primarily inferred from context, much like you’d find in the menu of a native app.
<ahi-menu style="max-width: 200px;">
<ahi-menu-item type="checkbox">Option 1</ahi-menu-item>
<ahi-menu-item type="checkbox" checked>Option 2</ahi-menu-item>
<ahi-menu-item type="checkbox">Option 3</ahi-menu-item>
</ahi-menu>
Value and Selection
The value attribute can be used to assign a hidden value, such as a unique identifier, to a menu item. When
an item is selected, the ahi-select event will be emitted and a reference to the item will be
available at event.detail.item. You can use this reference to access the selected item’s value,
its checked state, and more.
<ahi-menu class="menu-item-selection" style="max-width: 200px;">
<ahi-menu-item value="opt-1">Option 1</ahi-menu-item>
<ahi-menu-item value="opt-2">Option 2</ahi-menu-item>
<ahi-menu-item value="opt-3">Option 3</ahi-menu-item>
<ahi-divider></ahi-divider>
<ahi-menu-item type="checkbox" value="opt-4"> Checkbox 4 </ahi-menu-item>
<ahi-menu-item type="checkbox" value="opt-5"> Checkbox 5 </ahi-menu-item>
<ahi-menu-item type="checkbox" value="opt-6"> Checkbox 6 </ahi-menu-item>
</ahi-menu>
<script>
const menu = document.querySelector('.menu-item-selection');
menu.addEventListener('ahi-select', event => {
const item = event.detail.item;
// Log value
if (item.type === 'checkbox') {
console.log(`Selected value: ${item.value} (${item.checked ? 'checked' : 'unchecked'})`);
} else {
console.log(`Selected value: ${item.value}`);
}
});
</script>
Importing
To import this component using a script tag:
<script type="module" src="/path/to/azalea-kit-ui/dist/components/menu-item/menu-item.js"></script>
To import this component using a bundler:
import '@azaleahealth/azalea-kit-ui/dist/components/menu-item/menu-item.js';
Slots
| Name | Description |
|---|---|
| (default) | The menu item’s label. |
prefix
|
Used to prepend an icon or similar element to the menu item. |
suffix
|
Used to append an icon or similar element to the menu item. |
submenu
|
Used to denote a nested menu. |
Learn more about using slots.
Properties
| Name | Description | Type | Default | |
|---|---|---|---|---|
type
|
The type of menu item to render. To use checked, this value must be set to
checkbox.
|
'normal' | 'checkbox'
|
'normal'
|
|
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
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about properties and attributes.
Methods
| Name | Description | Arguments |
|---|---|---|
getTextLabel() |
Returns a text label based on the contents of the menu item’s default slot. | - |
Learn more about methods.
CSS Parts
| Name | Description |
|---|---|
base |
Deprecated. Use the menu-item part instead. |
menu-item |
The component’s outer wrapper. |
checked-icon |
The checked icon, which is only visible when the menu item is checked. |
prefix |
The prefix container. |
label |
The menu item label. |
suffix |
The suffix container. |
spinner |
The loading spinner, shown when the menu item is loading. |
spinner__base |
The spinner’s base part. |
submenu-icon |
The submenu icon, visible only when the menu item has a submenu. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.
<ahi-icon><ahi-spinner>