You can also provide custom content inside the sbb-menu
:
<!-- Trigger element -->
<sbb-button id="menu-trigger">Menu trigger</sbb-button>
<!-- Menu component with custom content and menu actions -->
<sbb-menu trigger="menu-trigger">
<div>Christina Müller</div>
<span>UIS9057</span>
<sbb-link href="https://www.sbb.ch/en" negative size="xs" variant="block">Profile</sbb-link>
<sbb-divider />
<sbb-menu-action icon="link-small" href="https://www.sbb.ch/en">View</sbb-menu-action>
<sbb-menu-action icon="pen-small">Edit</sbb-menu-action>
<sbb-menu-action icon="swisspass-small" amount="123">Details</sbb-menu-action>
<sbb-divider />
<sbb-menu-action icon="cross-small">Cancel</sbb-menu-action>
</sbb-menu>
The default z-index
of the component is set to 1000
; to specify a custom stack order, the z-index
can be changed by defining the CSS variable --sbb-menu-z-index
.
Clicking in the backdrop or pressing the ESC
key closes the menu.
As the menu opens, the focus will automatically be set to the first focusable item within the component.
When using the sbb-menu
as a select (e.g. language selection) it's recommended to use the aria-pressed
attribute to identify which actions are active and which are not.
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
disableAnimation | disable-animation | Whether the animation is enabled. | boolean | false |
listAccessibilityLabel | list-accessibility-label | This will be forwarded as aria-label to the inner list. Used only if the menu automatically renders the actions inside as a list. | string | undefined |
trigger | trigger | The element that will trigger the menu dialog. Accepts both a string (id of an element) or an HTML element. | HTMLElement | string | undefined |
Event | Description | Type |
---|---|---|
did-close | Emits whenever the menu is closed. | CustomEvent<void> |
did-open | Emits whenever the menu is opened. | CustomEvent<void> |
will-close | Emits whenever the menu begins the closing transition. | CustomEvent<void> |
will-open | Emits whenever the menu starts the opening transition. | CustomEvent<void> |
close() => Promise<void>
Closes the menu.
Type: Promise<void>
open() => Promise<void>
Opens the menu on trigger click.
Type: Promise<void>
Slot | Description |
---|---|
"unnamed" | Use this slot to project any content inside the dialog. |