Menu
A floating list of actions or options, opened from a button, a select or a right-click. It floats above the page, sits below its trigger and flips above when there isn't room. Rules: UX Elements & Rules → Menu and MenuItem, and UX-4 for the floating surface.
Add it to a page
Load the pinned file once in your Latitude Site or web page, then use the tag.
<script type="module" src="https://web-components.sites.latd.com/components/lat-menu/0.1.0/lat-menu.js"></script>The file is an ES module. It loads Lit, the design-system tokens and the Roobert stylesheet from this catalog once per page, however many components you use.
| Version | 0.1.0 |
|---|---|
| File | /components/lat-menu/0.1.0/lat-menu.js (3.3 KB gzipped) |
| SHA-256 | afef0e42200a3363b962f61b1d9c8a567466da82ea76ed7de753bc31820d7764 |
Rows are <lat-menu-item>, which this file includes. Icons in rows are <lat-icon>, so load that file too if you use them.
Permutations
From a button
DarkStudy actions
Rename
Duplicate
Share
Delete
LightStudy actions
Rename
Duplicate
Share
Delete
<lat-button>Study actions</lat-button>
<lat-menu onselect="this.parentElement.querySelector('output').value = 'Chose ' + event.detail.value">
<lat-menu-item><lat-icon slot="icon" name="edit" size="20"></lat-icon>Rename</lat-menu-item>
<lat-menu-item shortcut="⌘D"><lat-icon slot="icon" name="copy" size="20"></lat-icon>Duplicate</lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="share" size="20"></lat-icon>Share</lat-menu-item>
<lat-menu-item disabled><lat-icon slot="icon" name="trash-bin" size="20"></lat-icon>Delete</lat-menu-item>
</lat-menu>
<output></output>Open, shown in place
Dark
Rename
Duplicate
Share
List view
Delete
Light
Rename
Duplicate
Share
List view
Delete
<lat-menu inline aria-label="Video actions">
<lat-menu-item group="Video"></lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="edit" size="20"></lat-icon>Rename</lat-menu-item>
<lat-menu-item shortcut="⌘D"><lat-icon slot="icon" name="copy" size="20"></lat-icon>Duplicate</lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="share" size="20"></lat-icon>Share</lat-menu-item>
<lat-menu-item checked selected><lat-icon slot="icon" name="list" size="20"></lat-icon>List view</lat-menu-item>
<lat-menu-item disabled><lat-icon slot="icon" name="trash-bin" size="20"></lat-icon>Delete</lat-menu-item>
</lat-menu>Groups with checkbox and radio rows
DarkView
Grid view
List view
Comments
Captions
LightView
Grid view
List view
Comments
Captions
<lat-button size="sm">View</lat-button>
<lat-menu onselect="this.parentElement.querySelector('output').value = 'Chose ' + event.detail.value">
<lat-menu-item group="Layout"></lat-menu-item>
<lat-menu-item type="radio" value="grid"><lat-icon slot="icon" name="grid" size="20"></lat-icon>Grid view</lat-menu-item>
<lat-menu-item type="radio" value="list" checked><lat-icon slot="icon" name="list" size="20"></lat-icon>List view</lat-menu-item>
<lat-menu-item group="On the video"></lat-menu-item>
<lat-menu-item type="checkbox" value="comments" checked>Comments</lat-menu-item>
<lat-menu-item type="checkbox" value="captions">Captions</lat-menu-item>
</lat-menu>
<output></output>From an icon button, lined up with its end
Dark
Download clip
Copy link
Archive
Light
Download clip
Copy link
Archive
<lat-icon-button label="More actions"><lat-icon name="more-horizontal"></lat-icon></lat-icon-button>
<lat-menu placement="bottom-end" onselect="this.parentElement.querySelector('output').value = 'Chose ' + event.detail.value">
<lat-menu-item><lat-icon slot="icon" name="download" size="20"></lat-icon>Download clip</lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="link" size="20"></lat-icon>Copy link</lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="box-archive" size="20"></lat-icon>Archive</lat-menu-item>
</lat-menu>
<output></output>On right-click
Dark
Right-click here, or focus and press Shift+F10
Play from here
Add comment
Copy link to moment
Light
Right-click here, or focus and press Shift+F10
Play from here
Add comment
Copy link to moment
<div tabindex="0" style="padding: 24px; border: 1px dashed var(--lat-br-prominent); border-radius: 8px; color: var(--lat-fg-secondary)">
Right-click here, or focus and press Shift+F10
<lat-menu context onselect="this.parentElement.querySelector('output').value = 'Chose ' + event.detail.value">
<lat-menu-item><lat-icon slot="icon" name="play" size="20"></lat-icon>Play from here</lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="comments" size="20"></lat-icon>Add comment</lat-menu-item>
<lat-menu-item><lat-icon slot="icon" name="link" size="20"></lat-icon>Copy link to moment</lat-menu-item>
</lat-menu>
<output></output>
</div>Keyboard
| Key | On the trigger | In the menu |
|---|---|---|
| Enter, Space | Opens at the first row | Chooses the row |
| Down, Up | Opens at the first or last row | Next or previous row, wrapping |
| Home, End | First or last row | |
| Letters | The next row starting with what was typed | |
| Escape | Closes and returns focus to the trigger | |
| Tab | Closes and moves to the next control | |
| Shift+F10, context-menu key | Opens a context menu |
A click outside also closes the menu.
Attributes
| Attribute | Values | Notes |
|---|---|---|
for | id | The trigger. Without it, the element just before the menu (with context, the menu's parent). The trigger gets aria-haspopup and aria-expanded. |
context | boolean | Opens on right-click inside the trigger, at the pointer. |
placement | bottom-start (default), bottom-end | Which edge of the trigger the menu lines up with. It flips above when there's no room below. |
open | boolean | Whether the menu is showing. Set it to open or close the menu. |
inline | boolean | Shows the menu in the page instead of floating. |
listbox | boolean | A list of options rather than actions, as <lat-select> uses. |
Events and methods
| Name | Notes |
|---|---|
select event | A row was chosen: event.detail.item and event.detail.value. Cancel it to keep the menu open. Checkbox rows keep it open anyway. |
toggle event | The native popover event, with newState open or closed. |
show(options) | Opens next to options.anchor (default the trigger) or at options.x, options.y. |
hide(), toggle() | Closes, or opens and closes. |