Menu
A <role-menu> is intended to behave like a system menu. Menus can be used as submenus within a <role-menu-item>.
Menus follow the APG recommendation of “focus follows hover”, they also implement “safe triangles”.
Examples
API Reference
Imports
<!-- Auto registers as <role-menu> -->
<script type="module" src="https://cdn.jsdelivr.net/npm/role-components/exports/components/menu/menu-register.js"></script>
<script type="module">
// Auto registers as <role-menu>
import "https://cdn.jsdelivr.net/npm/role-components/exports/components/menu/menu-register.js"
// Manual Register
import RoleMenu from "https://cdn.jsdelivr.net/npm/role-components/exports/components/menu/menu.js"
RoleMenu.define()
// => Registers as <role-menu>
</script>
// Auto registers as <role-menu>
import "role-components/exports/components/menu/menu-register.js"
// Manual Register
import RoleMenu "role-components/exports/components/menu/menu.js"
RoleMenu.define()
// => Registers as <role-menu>
Slots
| Name | Description |
|---|---|
|
The default slot. |
trigger
|
the text to go within the button |
trigger-icon
|
the icon to indicate either the submenu or menu |
Attributes
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
[Attribute + Property]
placement
|
The preferred placement of the popover. Note that the actual placement will vary as configured to keep the panel inside of the viewport. |
|
'top'
| 'top-start'
| 'top-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'right'
| 'right-start'
| 'right-end'
| 'left'
| 'left-start'
| 'left-end'
|
-
|
[Attribute + Property]
current-placement
|
The |
|
'top'
| 'top-start'
| 'top-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'right'
| 'right-start'
| 'right-end'
| 'left'
| 'left-start'
| 'left-end'
| null
|
-
|
[Attribute + Property]
strategy
|
Determines how the popover is positioned. Because you native “popover” API uses a fixed strategy, we use it as the default. |
|
Strategy
|
-
|
[Attribute + Property]
distance
|
The distance in pixels from which to offset along the “main axis”. Usually its equivalent to offsetY |
|
number
|
-
|
[Attribute + Property]
skidding
|
The distance in pixels from which to offset along the “cross axis”. Usually its equivalent to offsetX. |
|
number
|
-
|
[Attribute + Property]
arrow
|
Attaches an arrow to the popover. The arrow’s size and color can be customized using the |
|
boolean
|
-
|
[Attribute + Property]
arrow-placement
|
The placement of the arrow. The default is |
|
'start' | 'end' | 'center' | 'anchor'
|
-
|
[Attribute + Property]
arrow-padding
|
The amount of padding between the arrow and the edges of the popover. If the popover has a border-radius, for example, this will prevent it from overflowing the corners. |
|
number
|
-
|
[Attribute + Property]
flip
|
When set, placement of the popover will flip to the opposite site to keep it in view. You can use
|
|
boolean
|
-
|
[Attribute + Property]
flip-fallback-placements
|
If the preferred placement doesn’t fit, popover will be tested in these fallback placements until one fits. Must be a string of any number of placements separated by a space, e.g. “top bottom left”. If no placement fits, the flip fallback strategy will be used instead. |
|
string
|
-
|
[Attribute + Property]
flip-fallback-strategy
|
When neither the preferred placement nor the fallback placements fit, this value will be used to determine whether the popover should be positioned using the best available fit based on available space or as it was initially preferred. |
|
'best-fit' | 'initial'
|
-
|
[Attribute + Property]
flip-padding
|
The amount of padding, in pixels, to exceed before the flip behavior will occur. |
|
number
|
-
|
[Attribute + Property]
shift
|
Moves the popover along the axis to keep it in view when clipped. |
|
boolean
|
-
|
[Attribute + Property]
shift-padding
|
The amount of padding, in pixels, to exceed before the shift behavior will occur. |
|
number
|
-
|
[Attribute + Property]
auto-size
|
When set, this will cause the popover to automatically resize itself to prevent it from overflowing. |
|
null | 'horizontal' | 'vertical' | 'both'
|
-
|
[Attribute + Property]
sync
|
Syncs the popover’s width or height to that of the anchor element. |
|
null | 'width' | 'height' | 'both'
|
-
|
[Attribute + Property]
auto-size-padding
|
The amount of padding, in pixels, to exceed before the auto-size behavior will occur. |
|
number
|
-
|
[Attribute + Property]
hover-bridge
|
When a gap exists between the anchor and the popover element, this option will add a “hover bridge” that fills the
gap using an invisible element. This makes listening for events such as |
|
boolean
|
-
|
Events
| Name | Description |
|---|---|
role-menu-item-selected
|
Fires when a menu item is selected and will close the menu. Called |
Functions
| Name | Description | Parameters |
|---|---|---|
handleMenuItemSelected()
|
-
|
e: RoleMenuItemSelectedEvent
|
handleOutsideClick()
|
-
|
e: Event
|
handleKeydown()
|
-
|
e: KeyboardEvent
|
focusAtIndex()
|
-
|
index: number
|
focus()
|
-
|
options: FocusOptions
|
focusTrigger()
|
-
|
options: FocusOptions
|
focusMenuItem()
|
-
|
menuItem: default
|
getOrAssignId()
|
Assign a random UUID with a prefix if no id is found. Will return the “id” of the element if its already assigned. |
prefix: string, force: boolean
|
getTextDirection()
|
-
|
-
|
debounce()
|
-
|
callback: (...args: any[]) => any, options: { key: any, wait: number }
|
setAria()
|
-
|
key: T, value: ARIAMixin[T]
|
Parts
| Name | Description |
|---|---|
base
|
The component’s base wrapper. |
trigger
|
the button that triggers the menu or submenu. |
anchored-region
|
The anchored region element |
popover
|
the popover within the anchored region |
popover--active
|
if the popover is active |
popover--fixed
|
if the popover is fixed |
popover--has-arrow
|
if the popover has an arrow |
arrow
|
the arrow element |
hover-bridge
|
the hover bridge element |
hover-bridge--visible
|
if the hover bridge is visible |