sp-action-group

Examples API

Attributes and Properties #

Property Attribute Type Default Description
compact compact boolean false
emphasized emphasized boolean false
justified justified boolean false
label label string ''
quiet quiet boolean false
selected selected string[]
selects selects undefined | 'single' | 'multiple'
vertical vertical boolean false

Slots #

Name Description
default slot the sp-action-button elements that make up the group

CSS Custom Properties #

Name Default
--spectrum-actionbutton-m-texticon-border-radius var(--spectrum-alias-component-border-radius)
--spectrum-actionbutton-m-texticon-border-size var(--spectrum-alias-border-size-thin)
--spectrum-actiongroup-button-gap-x var(--spectrum-global-dimension-size-100)
--spectrum-actiongroup-button-gap-y var(--spectrum-global-dimension-size-100)

Description #

sp-action-group delivers a set of action buttons in horizontal or vertical orientation while ensuring the appropriate spacing between those buttons. The compact attribute merges these buttons so that they are visually joined to clarify their relationship to each other and their distance from other buttons/groups.

Usage #

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

yarn add @spectrum-web-components/action-group

Import the side effectful registration of <sp-action-group> via:

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

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

import { ActionGroup } from '@spectrum-web-components/action-group';

Example #

<sp-action-group>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>

Selects #

An <sp-action-group selects="single|multiple"> will manage a selected property that consists on an array of the <sp-action-button> children that are currently selected. A change event is dispatched from the <sp-action-group> element when the value of selected is updated. This event can be canceled via event.preventDefault(), after which the value of selected will be returned to what it was previously.

When a selection can be made, it is a good idea to supply the group of options with accessible text that names the group of buttons. This can be done in a non-visual way via the label attribute of the <sp-action-group> element. You can also associate the <sp-action-group> to a second, visible DOM element via the aria-labelledby attribute or, when available, via the for attribute on the second element to make the association in the other direction.

Single #

An <sp-action-group selects="single"> will manage its <sp-action-button> children as "radio buttons" allowing the user to select a single one of the buttons presented. The <sp-action-button> children will only be able to turn their selected value on while maintaining a single selection after an intial selection is made.

<sp-action-group
selects="single"
emphasized
label="Single Selection Demo Group"
>

<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button selected>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>

Multiple #

An <sp-action-group selects="multiple"> will manage its <sp-action-button> children as "chekboxes" allowing the user to select a multiple of the buttons presented. The <sp-action-button> children will toggle their selected value on and off when clicked sucessively.

<sp-action-group
selects="multiple"
emphasized
label="Multiple Selection Demo Group"
>

<sp-action-button selected>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button selected>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>

Horizontal #

By default, an <sp-action-group> will organize its child buttons horizontally and the delivery of those buttons can be modified with the compact, emphasized, or quiet attributes.

<sp-action-group>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>
<br />
<sp-action-group compact>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>
<br />
<sp-action-group quiet>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
</sp-action-group>
<br />
<sp-action-group compact emphasized>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
</sp-action-group>

Vertical #

The use of the vertical attribute instructs the <sp-action-group> element to organize its child buttons vertically, while accepting the same compact, emphasized, and quiet attributes as modifiers.

<div style="display: flex; justify-content: space-around;">
<sp-action-group vertical>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>
<sp-action-group vertical compact>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>
<sp-action-group vertical quiet>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
</sp-action-group>
<sp-action-group compact vertical>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
</sp-action-group>
</div>

Justified #

The justified attribute will cause the <sp-action-group> element to fill the available horizontal space and evenly distribute that space across its child button elements.

<sp-action-group justified>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>
<br />
<sp-action-group justified compact>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Button 1
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Longer Button 2
</sp-action-button>
<sp-action-button>
<sp-icon-magnify slot="icon"></sp-icon-magnify>
Short 3
</sp-action-button>
</sp-action-group>
<br />
<sp-action-group justified quiet>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
</sp-action-group>
<br />
<sp-action-group compact justified>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
<sp-action-button label="Zoom in">
<sp-icon-magnify slot="icon"></sp-icon-magnify>
</sp-action-button>
</sp-action-group>