Menu
The Menu item list is a component that allows you to display related content grouped together and organized vertically. It can be used in various UI components such as dropdown, drawer, split button and more.
There are two ways to use this component: using children or using items prop
Using Children
You can use children to add menu items and submenu items components inside a menu item list component. This gives you greater control over the layout and content of the menu item list.
Single level menu
<QtmMenuItemList>
<QtmMenuItem id="menu1">
<QtmMenuItemLabel>
<QtmIcon icon="account_circle"></QtmIcon>
<QtmTypography>Menu Item</QtmTypography>
</QtmMenuItemLabel>
</QtmMenuItem>
<QtmMenuItem id="menu2">
<QtmMenuItemLabel>
<QtmIcon icon="account_circle"></QtmIcon>
<QtmTypography>Menu Item</QtmTypography>
</QtmMenuItemLabel>
</QtmMenuItem>
<QtmMenuItem id="menu3">
<QtmMenuItemLabel>
<QtmIcon icon="account_circle"></QtmIcon>
<QtmTypography>Menu Item</QtmTypography>
</QtmMenuItemLabel>
</QtmMenuItem>
</QtmMenuItemList>
Multi-level menu
For menu item with submenu items, a collapsed icon should also be displayed on the right side of menu item label. To select a suitable icon, please refer to the Icon documentation.
<QtmMenuItemList>
<QtmMenuItem id="menu1">
<QtmMenuItemLabel>
<QtmIcon icon="account_circle"></QtmIcon>
<QtmTypography>Menu Item</QtmTypography>
</QtmMenuItemLabel>
</QtmMenuItem>
<QtmMenuItem id="menu2">
<QtmMenuItemLabel>
<QtmIcon icon="account_circle"></QtmIcon>
<QtmTypography>Menu Item</QtmTypography>
</QtmMenuItemLabel>
</QtmMenuItem>
<QtmMenuItem id="menu3">
<QtmMenuItemLabel>
<QtmIcon icon="account_circle"></QtmIcon>
<QtmTypography>Menu Item</QtmTypography>
<QtmIcon icon="keyboard_arrow_up"></QtmIcon>
</QtmMenuItemLabel>
<QtmSubmenuItemList>
<QtmSubmenuItem id="submenu1">Submenu Item</QtmSubmenuItem>
<QtmSubmenuItem id="submenu2">Submenu Item</QtmSubmenuItem>
<QtmSubmenuItem id="submenu3">Submenu Item</QtmSubmenuItem>
</QtmSubmenuItemList>
</QtmMenuItem>
</QtmMenuItemList>
Using items prop
You can also use the items prop to generate the menu item list dynamically. This prop has the following format:
type MenuItemItemType = {
label: string,
id: string,
icon?: string | IconType,
children?: [
{
label: string,
id: string,
}
],
};
Single level menu
const items=[
{ label: 'Menu item', id: 'menu1', icon: 'account_circle' },
{ label: 'Menu item', id: 'menu2', icon: 'account_circle' },
{ label: 'Menu item', id: 'menu3', icon: 'account_circle' },
]
<QtmMenuItemList items={items}></QtmMenuItemList>
Multi-level menu
For menu items that contain submenu items, a collapsed icon will be automatically displayed on the right side of the menu label. When a menu item with a submenu is clicked, the icon will dynamically expand or collapse.
const items=[
{label: "Menu item", id: "menu1", icon: "account_circle"},
{label: "Menu item", id: "menu2", icon: "account_circle"},
{
label: "Menu item", id: "menu3", icon: "account_circle",
children: [
{ label: 'Submenu item', id: 'submenu1' },
{ label: 'Submenu item', id: 'submenu2' },
{ label: 'Submenu item', id: 'submenu3' },
],
},
]
<QtmMenuItemList items={items}></QtmMenuItemList>
Multi-level menu with custom icon
To select an appropriate icon, please consult the Icon component documentation.
You can include an icon in the items prop by adding either the icon name or an icon object with the following format:
type IconType = {
icon: string,
classes?: string,
lib?: IconLibType,
size?: IconSizeType,
variant?: IconVariantType,
};
const items=[
{label: "Menu item", id: "menu1", icon: {icon: 'applied_settings', lib:"business"}},
{label: "Menu item", id: "menu2", icon: {icon: 'applied_settings', lib:"business"}},
{
label: "Menu item", id: "menu3",
icon: { icon: 'applied_settings', lib:"business"}
children: [
{ label: 'Submenu item', id: 'submenu1' },
{ label: 'Submenu item', id: 'submenu2' },
{ label: 'Submenu item', id: 'submenu3' },
],
},
]
<QtmMenuItemList items={items}></QtmMenuItemList>
Properties
All the properties listed below can be applied directly to the menu item list tag. This means that they are applicable to the menu item list generated by using either the slot or the items prop method.
NOTE: All menu item element and submenu item element must have an id attribute for the features to work properly.
Active
enableAutoActive
Setting the enableAutoActive
prop to true will automatically activate the active state of both menu items and submenu items when they are clicked or when the activeId prop value is changed.
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList items={itemsProp} enableAutoActive></QtmMenuItemList>
activeId
Set the activeId
value to the active menu or submenu item ID by default
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList items={items} activeId={["menu2"]} enableAutoActive></QtmMenuItemList>
disabledIds
Set the disabledIds
value to a list of ids of disabled menu items or disabled submenu items
<QtmMenuItemList
items={itemsProp}
disabledIds={['menu1', 'submenu2']}
enableAutoActive
></QtmMenuItemList>
collapsedIds
Set the collapsedIds
value to a list of menu items that does not show their own nested submenu items by default
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList items={items} collapsedIds={['menu3']}></QtmMenuItemList>
size
The menu item lists come in three size: small
, medium
and large
. By default, they are displayed in the medium
size.
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList size="small" items={items}></QtmMenuItemList>
<QtmMenuItemList size="medium" items={items}></QtmMenuItemList>
<QtmMenuItemList size="large" items={items}></QtmMenuItemList>
Scrolling
scrollable
If there are more menu items than can be displayed at once, you can make the menu item list scrollable by adding the scrollable
attribute to this component. By default, the scrollable menu item list displays the first five menu items and half of the sixth one.
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList items={items} scrollable></QtmMenuItemList>
nbVisibleItems
If you want to change the number of visible items when the menu item list is scrollable, you can change value of nbVisibleItems
attribute.
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList items={items} scrollable nbVisibleItems={2}></QtmMenuItemList>
classes
Add your own classes in the classes
attribute. This way you will be able to override or extend the styles applied to the component (you can use available utility classes by importing @qtm/css/dist/utilities.css).
const items=[{label: "Menu item", id: "menu1", icon: "account_circle"},...]
<QtmMenuItemList items={items} classes="bg-primary-100"></QtmMenuItemList>
API
QtmMenuItemList
Property | Type | Default | Description |
---|---|---|---|
activeId | string | The item whose id is activeId will activate when enableAutoActive is set to true | |
classes | string | list of classes to override or extend the styles applied to the component. You can use available utility classes by importing | |
collapsedIds | string[] | [] | The list of collapsed menu-item ids, only if they have submenu-items |
disabledIds | string[] | [] | The list of disabled menu-item ids and disabled submenu items ids |
enableAutoActive | boolean | false | If true, the menu item list activates automatically the active state of menu item and submenu item. The elements in list must have id attribute |
items | MenuItemItemType[] | List of items to be generated as children nodes, ex: [{ label: 'label1', icon: 'person', id: 'id1', children: [ { label: 'subLabel'; id: 'subId1'; }, ... ] | |
nbVisibleItems | number | the number of visible items when the menu item list is scrollable | |
scrollable | boolean | false | if true, the menu item list is scrollable |
size | "large" | "medium" | "small" | The size of child elements( menu-item, menu-item-label, submenu-item) in menu-item-list |
Event | Type | Description |
---|---|---|
onActiveIdChanged | CustomEvent<string> | Callback fired when the activeId is modified |
onClickItem | CustomEvent<string> | Callback fired when a menu item or submenu item is clicked |
onCollapsedIdsChanged | CustomEvent<string[]> | Callback fired when collapsed id list change |
QtmMenuItem
Property | Type | Default | Description |
---|---|---|---|
active | boolean | false | If true, the menu item or submenu item is active |
classes | string | list of classes to override or extend the styles applied to the component. You can use available utility classes by importing | |
collapsed | boolean | false | If true, the submenu item list is collapsed |
disabled | boolean | false | If true, the component is disabled. |
id | string | The id of menu item | |
item | { label: string; icon?: string | IconType; id: string; children?: [{ label: string; id: string; }]; } |
Event | Type | Description |
---|---|---|
onClickedMenuItem | CustomEvent<string> | Callback fired when the menu item is clicked or when its submenu-item is clicked |
QtmMenuItemLabel
Property | Type | Default | Description |
---|---|---|---|
classes | string | list of classes to override or extend the styles applied to the component. You can use available utility classes by importing |
Event | Type | Description |
---|---|---|
onClickEvent | CustomEvent<void> | callback fired when a menu item label is clicked |
QtmSubmenuItemList
Property | Type | Default | Description |
---|---|---|---|
classes | string |
QtmSubmenuItem
Property | Type | Default | Description |
---|---|---|---|
active | boolean | If true, the menu item or submenu item is active | |
classes | string | list of classes to override or extend the styles applied to the component. You can use available utility classes by importing | |
disabled | boolean | false | If true, the component is disabled. |
id | string | The id of submenu item |
Event | Type | Description |
---|---|---|
onClickedSubmenuItem | CustomEvent<string> | Callback fired when when its submenu-item is clicked |