Latitude ComponentsLibrary 0.1.0

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.

Version0.1.0
File/components/lat-menu/0.1.0/lat-menu.js (3.3 KB gzipped)
SHA-256afef0e42200a3363b962f61b1d9c8a567466da82ea76ed7de753bc31820d7764

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

Dark
Study actions Rename Duplicate Share Delete
Light
Study 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

Dark
View Grid view List view Comments Captions
Light
View 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

KeyOn the triggerIn the menu
Enter, SpaceOpens at the first rowChooses the row
Down, UpOpens at the first or last rowNext or previous row, wrapping
Home, EndFirst or last row
LettersThe next row starting with what was typed
EscapeCloses and returns focus to the trigger
TabCloses and moves to the next control
Shift+F10, context-menu keyOpens a context menu

A click outside also closes the menu.

Attributes

AttributeValuesNotes
foridThe trigger. Without it, the element just before the menu (with context, the menu's parent). The trigger gets aria-haspopup and aria-expanded.
contextbooleanOpens on right-click inside the trigger, at the pointer.
placementbottom-start (default), bottom-endWhich edge of the trigger the menu lines up with. It flips above when there's no room below.
openbooleanWhether the menu is showing. Set it to open or close the menu.
inlinebooleanShows the menu in the page instead of floating.
listboxbooleanA list of options rather than actions, as <lat-select> uses.

Events and methods

NameNotes
select eventA row was chosen: event.detail.item and event.detail.value. Cancel it to keep the menu open. Checkbox rows keep it open anyway.
toggle eventThe 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.