Examples API

Attributes and Properties #

Property Attribute Type Default Description
dir dir 'ltr' | 'rtl' 'ltr'
label label string ''
selects selects undefined | 'inherit' | 'single' | 'multiple' whether the element has a specific selection algorithm that it applies to its item descendants. `single` allows only one descendent to be selected at a time. `multiple` allows many descendants to be selected. `inherit` will be applied dynamically when an ancestor of this element is actively managing the selection of its descendents. When the `selects` attribute is not present a `value` will not be maintained and the Menu Item children of this Menu will not have their `selected` state managed.
value value string ''
valueSeparator value-separator string ','

Slots #

Name Description
header headline of the menu group
default slot menu items to be listed in the group

Events #

Name Type Description
change Event Announces that the `value` of the element has changed
close Event

Overview #

An <sp-menu-group> will gather a collection of <sp-menu-item> elements into a group as part of the content delivered in an <sp-menu> element. Supplying content to the header slot will allow it label the group both visually and for screen readers. Like <sp-menu>, an <sp-menu-group> element can maintain a selection as outlined by the value or absence of its selects attribute.

Usage #

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/menu

Import the side effectful registration of <sp-menu-group> as follows:

import '@spectrum-web-components/menu/sp-menu-group.js';

When looking to leverage the MenuGroup base class as a type and/or for extension purposes, do so via:

import { MenuGroup } from '@spectrum-web-components/menu';

Example #

An <sp-menu-group> can be used to organize <sp-menu-item>s in an <sp-memu> in to collections with a shared header. Use an element addressed to the slot="header to pass the content of that header.

Your favorite park in New York is: <span id="group-1-value"></span>
Your favorite park in San Fransisco is: <span id="group-2-value"></span>
<sp-popover open style="position: relative">
label="What are your favorite parks?"
style="width: 200px"
.textContent = arguments[0].target.value


<span slot="header">New York</span>
Central Park
Flushing Meadows Corona Park
Prospect Park

<span slot="header">San Fransisco</span>
Golden Gate Park
John McLaren Park
Lake Merced Park