Skip to main content

Dropdown menu

The dropdown menu component enables you to create nested menus with menu items.

Use cases:

  • creating a menu for configuring options

Example

The example below shows the component in action. Click on Dropdown Menu to display the menu.

  • Menu item 1 includes an icon.
  • Menu item 3 displays a submenu with one single item: Menu item 5
  • When you click on items 1 and 5, it generates an alert.
  • Menu item 4 is disabled.
  • Cunningly, there is no Menu item 2 - just to make sure you haven't fallen asleep.

Declaration

<rapid-dropdown-menu></rapid-dropdown-menu>

Usage

import { DropdownMenuItem } from '@genesislcap/web-core';

@customElement({
name: 'my-element',
template: html`
<rapid-dropdown-menu :items=${(x) => x.setOfItems}></rapid-dropdown-menu>
`,
})
export class MyElement extends GenesisElement {
setOfItems: DropdownMenuItem[] = [
{
name: 'Menu item 1',
callback: () => alert('Menu item 1 clicked'),
icon: {
name: 'glasses',
},
},
{
name: 'Menu item 3',
callback: () => alert('Menu item 3 clicked'),
submenu: [
{
name: 'Menu item 5',
callback: () => alert('Menu item 5 clicked'),
color: 'red',
icon: {
name: 'address-card',
},
},
]
},
{
name: 'Menu item 4',
callback: () => logger.debug('Menu item 4 clicked'),
isDisabled: () => true,
},
];
}

API

Configuration Type

The configuration of the dropdown menu is described by this typescript type.

export type DropdownMenuItem = {
name: string;
icon?: {
variant?: IconStyle;
name: string;
size?: FaSize;
};
color?: string;
submenu?: DropdownMenuItem[];
callback?: (params?: any) => void | any;
isDisabled?: (params?: any) => boolean;
};

Attributes

AttributeTypeDescriptionExample
auto-closebooleanControls whether the dropdown closes automatically (Default: true)
<rapid-dropdown-menu auto-close>
disable-buttonbooleanDisables the dropdown button (Default: false)
<rapid-dropdown-menu disable-button>
namestringThe name of the dropdown menu (Default: 'Dropdown Menu')
<rapid-dropdown-menu name="Dropdown Menu">
openbooleanControls if the dropdown is open (Default: false)
<rapid-dropdown-menu open>
buttonAppearancestringSets the appearance style of the button (Default: none)
<rapid-dropdown-menu buttonAppearance="primary">

Properties

PropertyTypeDescriptionExample
itemsDropdownMenuItem[]Configure the items to be in the dropdown menu.
<rapid-dropdown-menu :items=${x => x.menuItems}>

Slots

SlotDescription
DefaultThe text that appears on the root dropdown menu button.

Parts

PartDescription
actions-containerThe main container element that wraps up the button and the dropdown menu.
actions-openerThe button that opens the dropdown.
actions-menuThe dropdown menu.

Events fired

This component doesn't fire any events.

Events listened to

This component doesn't listen to any events.