Vivid API

Menu

The Menu is an interactive element that appears in response to user actions. It typically presents a list of Menu Items (actions) relevant to the current context.

Usage

import { registerMenu, registerMenuItem } from '@vonage/vivid-api';
registerMenu('your-prefix');
registerMenuItem('your-prefix');

Trigger

The trigger attribute controls whether the Menu opens and closes itself automatically.

  • auto (default) - The menu opens and closes automatically when the anchor is clicked. It also closes itself when the user selects a menu item with a role different from menuitemcheckbox.
  • legacy - The menu opens automatically when the anchor is clicked. This value is not recommended and only exists for backwards compatibility.
  • off - The menu does not open or close automatically.

Auto Dismiss

The auto-dismiss attribute sets it to automatically close when focus is moved away from it, i.e. by clicking outside the menu.

Position Strategy

The position-strategy attribute sets the position strategy. It can be set to fixed (default) or absolute.

In vivid version 4.12.0, popover attribute was added to menu, using the power of top-layer, eliminating the effect of change in the containing block.

We will remove the position-strategy in a future major version of Vivid to make this the default behaviour.

Anchor

It is recommended use the anchor slot to set the anchor.

The anchor attribute should be set to the id value of the anchor element or pass the anchor element itself.

Pay attention to the source order the components to ensure they can be operated logically using only a keyboard.

Slots

Default Slot

Place menu items and dividers between them in the default slot.

Only Menu Item, Divider and HTML elements with role of menuitem or separator are allowed. They must be direct descendants of the Menu, and cannot be nested inside other elements.

Anchor Slot

The Menu positions itself relative to an anchor element. Place it inside the anchor slot. It is recommended to use the Button component as the anchor element.

Header Slot

Use the header slot to add additional content to the top of the menu.

Action Items Slot

The action-items slot allows the addition of action items (in this case, a Button) to the bottom of the Menu.

CSS Variables

Maximum Inline Size

Use the --menu-max-inline-size variable to set the maximum inline size.

  • Default: max-content

When setting a value to the max-inline-size - make sure the Menu is OK in small resolutions as well.

In mobile, the max-inline-size is 300px by default, but can be changed with the css-variable.

Minimum Inline Size

Use the --menu-min-inline-size variable to set th minimum inline size.

  • Default: auto

Use the --menu-block-size variable to set the block size.

  • Default: 408px

API Reference

menu

Properties

PropertyTypeDefaultDescription
anchorstring | HTMLElementID or direct reference to the component's anchor element.
autoDismissbooleanSets the Menu to close when focus is lost
offsetnumberAdds offset to the popup
openbooleanSets the open state of the Menu
placement'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-end' | 'left-start' | 'right-end' | 'right-start'Sets the desired position of the Menu relative to it's anchor element
positionStrategy'fixed' | 'absolute'Sets the position strategy
trigger'off' | 'auto' | 'legacy'Sets trigger method of Menu
PropertyTypeDefaultDescription
anchorstring | HTMLElementID or direct reference to the component's anchor element.
auto-dismissbooleanSets the Menu to close when focus is lost
offsetnumberAdds offset to the popup
openbooleanSets the open state of the Menu
placement'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-end' | 'left-start' | 'right-end' | 'right-start'Sets the desired position of the Menu relative to it's anchor element
position-strategy'fixed' | 'absolute'Sets the position strategy
trigger'off' | 'auto' | 'legacy'Sets trigger method of Menu

Slots

NameDescription
action-itemsUsed to add action items to the bottom of the menu.
anchorUsed to set the anchor element for the menu.
defaultDefault slot.
headerUsed to add additional content to the top of the menu.
NameDescription
action-itemsUsed to add action items to the bottom of the menu.
anchorUsed to set the anchor element for the menu.
defaultDefault slot.
headerUsed to add additional content to the top of the menu.

Events

NameTypeDescription
closeCustomEvent<undefined>Fired when the menu is closed
openCustomEvent<undefined>Fired when the menu is opened
NameTypeDescription
closeCustomEvent<undefined>Fired when the menu is closed
openCustomEvent<undefined>Fired when the menu is opened

Methods

NameParamsReturnsDescription
collapseExpandedItemvoidCollapses any expanded Menu Items.
focusvoidMoves focus into the Menu. If there is a child with the `autofocus` attribute, it will be focused. Otherwise, the first Menu Item will be focused.
openChanged
_: boolean
newValue: boolean
void

menu-item

Properties

PropertyTypeDefaultDescription
checkedAppearance'normal' | 'tick-only'Controls the appearance of the check indicator.
checkTrailingbooleanSets the check element to appear at the end of the Menu Item
checked
(modelValue)
booleanSets the checked state
connotation'accent' | 'cta'Sets the connotation that appears when checked
controlType'checkbox' | 'radio'Whether the menu item should behave as a checkbox or radio button.
disabledbooleanSets the disabled state
expandedbooleanSets the expanded state
textstringText content
textSecondarystringGive more context to the text
PropertyTypeDefaultDescription
check-appearance'normal' | 'tick-only'Controls the appearance of the check indicator.
check-trailingbooleanSets the check element to appear at the end of the Menu Item
checkedbooleanSets the checked state
connotation'accent' | 'cta'Sets the connotation that appears when checked
control-type'checkbox' | 'radio'Whether the menu item should behave as a checkbox or radio button.
disabledbooleanSets the disabled state
expandedbooleanSets the expanded state
textstringText content
text-secondarystringGive more context to the text

Slots

NameDescription
metaAssign nodes to the `meta` slot to set a badge or an additional icon.
submenuAssign a Menu to the `submenu` slot to add a submenu.
trailing-metaAssign nodes to the `meta` slot to set a badge or an additional icon.
NameDescription
metaAssign nodes to the `meta` slot to set a badge or an additional icon.
submenuAssign a Menu to the `submenu` slot to add a submenu.
trailing-metaAssign nodes to the `meta` slot to set a badge or an additional icon.

Events

NameTypeDescription
changeCustomEvent<undefined>Fired when the item is triggered. Does not fire when a submenu is collapsed or expanded.
expanded-changeCustomEvent<HTMLElement>Fired when the expanded state changes.
NameTypeDescription
changeCustomEvent<undefined>Fired when the item is triggered. Does not fire when a submenu is collapsed or expanded.
expanded-changeCustomEvent<HTMLElement>Fired when the expanded state changes.