Use Selection Set...
- As a form input that presents separate options that can be selected.
- As a set of Radio Buttons or Checkboxes with labels and spacing included.
Don't use Selection Set...
- For navigation. Use a Covering Link instead, over another component such as a Card or a Standard Tile.
The preview has been updated.
<SelectionSet variant="single-select"><SelectionSetInput value="Option1"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet>
<div class="swan-selection-set"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option1"id="auto-id-nvav3bf3y-674"name="auto-id-nvav3bf3y-677"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-674">Option 1</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option2"id="auto-id-nvav3bf3y-675"name="auto-id-nvav3bf3y-677"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-675">Option 2</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option3"id="auto-id-nvav3bf3y-676"name="auto-id-nvav3bf3y-677"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-676">Option 3</label></div>
Variant
Use variant
to change the behaviour of a Selection Set.
Single select
Use variant="single-select"
when only one value may be selected at a time. Selection Set will act as a Radio Button set.
The preview has been updated.
<SelectionSet variant="single-select" defaultSelectedValue="Option1"><SelectionSetInput value="Option1"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet>
<div class="swan-selection-set"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option1"checked=""id="auto-id-nvav3bf3y-674"name="auto-id-nvav3bf3y-677"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-674">Option 1</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option2"id="auto-id-nvav3bf3y-675"name="auto-id-nvav3bf3y-677"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-675">Option 2</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option3"id="auto-id-nvav3bf3y-676"name="auto-id-nvav3bf3y-677"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-676">Option 3</label></div>
Multi-select
Use variant="multi-select"
when multiple values may be selected at a time. Selection Set will act as a Checkbox set.
The preview has been updated.
<SelectionSetvariant="multi-select"defaultSelectedValues={{ Option1: true, Option2: true, Option3: false }}><SelectionSetInput value="Option1"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet>
<div class="swan-selection-set"><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option1"checked=""id="auto-id-nvav3bf3y-678"name="auto-id-nvav3bf3y-681"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-678">Option 1</label><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option2"checked=""id="auto-id-nvav3bf3y-679"name="auto-id-nvav3bf3y-681"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-679">Option 2</label><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option3"id="auto-id-nvav3bf3y-680"name="auto-id-nvav3bf3y-681"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-680">Option 3</label></div>
Skin
Use skin
to change the appearance of a Selection Set.
Simple Column
Use skin="simple-column"
for a Radio Button or Checkbox style Selection Set. This adds labels and the correct spacing to Radio Button and Checkbox and is the intended way for these components to be used most of the time.
The preview has been updated.
<SelectionSet variant="single-select" skin="simple-column"><SelectionSetInput value="Option1"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet>
<divclass="swan-selection-set swan-selection-set-skin-simple-column swan-selection-set-show-inputs"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option1"id="auto-id-nvav3bf3y-697"name="auto-id-nvav3bf3y-700"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-697">Option 1</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option2"id="auto-id-nvav3bf3y-698"name="auto-id-nvav3bf3y-700"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-698">Option 2</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option3"id="auto-id-nvav3bf3y-699"name="auto-id-nvav3bf3y-700"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-699">Option 3</label></div>
The preview has been updated.
<SelectionSet variant="multi-select" skin="simple-column"><SelectionSetInput value="Option1"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet>
<divclass="swan-selection-set swan-selection-set-skin-simple-column swan-selection-set-show-inputs"><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option1"id="auto-id-nvav3bf3y-697"name="auto-id-nvav3bf3y-700"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-697">Option 1</label><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option2"id="auto-id-nvav3bf3y-698"name="auto-id-nvav3bf3y-700"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-698">Option 2</label><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option3"id="auto-id-nvav3bf3y-699"name="auto-id-nvav3bf3y-700"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-699">Option 3</label></div>
Use skin="simple-column"
for a single Checkbox with a label and the correct spacing.
The preview has been updated.
<SelectionSet skin="simple-column" variant="multi-select"><SelectionSetInput value="emails"><SelectionSetLabel>{"Don't uncheck to opt out of no emails"}</SelectionSetLabel></SelectionSetInput></SelectionSet>
<divclass="swan-selection-set swan-selection-set-skin-simple-column swan-selection-set-show-inputs"><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="emails"id="auto-id-nvav3bf3y-701"name="auto-id-nvav3bf3y-702"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-701">Don't uncheck to opt out of no emails</label></div>
Buttons
Use skin="buttons"
for a button style Selection Set.
The preview has been updated.
<SelectionSet variant="single-select" skin="buttons"><SelectionSetInput value="Option1"><SelectionSetLabel mb={0}>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput></SelectionSet>
<divrole="radiogroup"class="swan-selection-set swan-selection-set-skin-buttons"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option1"id="auto-id-gwvwulasv-297"name="auto-id-gwvwulasv-299"/><labelclass="swan-selection-set-label swan-mb-0"for="auto-id-gwvwulasv-297">Option 1</label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option2"id="auto-id-gwvwulasv-298"name="auto-id-gwvwulasv-299"/><label class="swan-selection-set-label" for="auto-id-gwvwulasv-298">Option 2</label></div>
Tiles horizontal
Use skin="tiles-horizontal"
for a tile-based Selection Set with horizontally-positioned content. The images are wrapped in a SelectionSetTileImageContainer
element and must be a FluidImage
component.
The preview has been updated.
<SelectionSet skin="tiles-horizontal" variant="multi-select"><SelectionSetInput value="Option1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 1</SelectionSetTileName><SelectionSetTileDescription>some description</SelectionSetTileDescription><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 2</SelectionSetTileName><SelectionSetTileDescription>some description</SelectionSetTileDescription><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3" disabled><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=3"alt="placeholder"/></SelectionSetTileImageContainer><Callout variant="overlay" skin="error">Out of stock</Callout><SelectionSetTileContents><SelectionSetTileName>Option 3</SelectionSetTileName><SelectionSetTileDescription>disabled selection</SelectionSetTileDescription><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet>
<div class="swan-selection-set swan-selection-set-skin-tiles-horizontal"><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option1"id="auto-id-nvav3bf3y-703"name="auto-id-nvav3bf3y-706"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-703"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 1</p><p class="swan-selection-set-tile-description">some description</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="Option2"id="auto-id-nvav3bf3y-704"name="auto-id-nvav3bf3y-706"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-704"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 2</p><p class="swan-selection-set-tile-description">some description</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="checkbox"disabled=""class="swan-selection-set-input swan-checkbox"value="Option3"id="auto-id-nvav3bf3y-705"name="auto-id-nvav3bf3y-706"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-705"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=3"alt="placeholder"class="swan-fluid-image"/></div><span class="swan-callout swan-callout-skin-error swan-callout-overlay">Out of stock</span><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 3</p><p class="swan-selection-set-tile-description">disabled selection</p><div class="swan-selection-set-tile-price">$price</div></div></label></div>
Tiles vertical
Use skin="tiles-vertical"
for a tile based Selection Set with vertically positioned content. The images are wrapped in a SelectionSetTileImageContainer
element and must be a FluidImage
component.
The preview has been updated.
<SelectionSet skin="tiles-vertical" variant="multi-select"><SelectionSetInput value="Option1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 1</SelectionSetTileName><SelectionSetTileDescription>some description</SelectionSetTileDescription><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 2</SelectionSetTileName><SelectionSetTileDescription>some description</SelectionSetTileDescription><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3" disabled><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=3"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 3</SelectionSetTileName><SelectionSetTileDescription>disabled selection</SelectionSetTileDescription><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet>
<div class="swan-selection-set swan-selection-set-skin-tiles-vertical"><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="A"id="auto-id-nvav3bf3y-707"name="auto-id-nvav3bf3y-710"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-707"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 1</p><p class="swan-selection-set-tile-description">some description</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="checkbox"class="swan-selection-set-input swan-checkbox"value="B"id="auto-id-nvav3bf3y-708"name="auto-id-nvav3bf3y-710"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-708"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 2</p><p class="swan-selection-set-tile-description">some description</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="checkbox"disabled=""class="swan-selection-set-input swan-checkbox"value="C"id="auto-id-nvav3bf3y-709"name="auto-id-nvav3bf3y-710"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-709"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=3"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 3</p><p class="swan-selection-set-tile-description">disabled selection</p><div class="swan-selection-set-tile-price">$price</div></div></label></div>
Tiles mini
Use skin="tiles-mini"
for a tile based Selection Set that is more visually compact. The images are wrapped in a SelectionSetTileImageContainer element and must be a FluidImage component.
The preview has been updated.
<SelectionSet skin="tiles-mini"><SelectionSetInput value="Option1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 1</SelectionSetTileName><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 2</SelectionSetTileName><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3" disabled><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=3"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Option 3</SelectionSetTileName><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option4"><SelectionSetLabel><SelectionSetTileContents><SelectionSetTileName>Option 4 (no image)</SelectionSetTileName><SelectionSetTilePrice>$price</SelectionSetTilePrice></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet>
<div class="swan-selection-set swan-selection-set-skin-tiles-mini"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option1"id="auto-id-nvav3bf3y-711"name="auto-id-nvav3bf3y-715"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-711"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 1</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option2"id="auto-id-nvav3bf3y-712"name="auto-id-nvav3bf3y-715"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-712"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 2</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="radio"disabled=""class="swan-selection-set-input swan-radio"value="Option3"id="auto-id-nvav3bf3y-713"name="auto-id-nvav3bf3y-715"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-713"><div class="swan-selection-set-tile-image-container"><imgsrc="https://picsum.photos/100/100?ssm=3"alt="placeholder"class="swan-fluid-image"/></div><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 3</p><div class="swan-selection-set-tile-price">$price</div></div></label><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option4"id="auto-id-nvav3bf3y-714"name="auto-id-nvav3bf3y-715"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-714"><div class="swan-selection-set-tile-contents"><p class="swan-selection-set-tile-name">Option 4 (no image)</p><div class="swan-selection-set-tile-price">$price</div></div></label></div>
Tile Mini has some other optional features that can be used to adjust its presentation.
- Use
imageWidth="proportional"
to make the width of the image proportional to the tile. The image will be about a 33% as wide as the tile, with a max of 200px. - Use
imageVerticalAlignment="center"
to make the image vertically centered instead of filling the image area. The image will not be cropped and will resize the height of the tile if necessary. - Use
tileContentsPadding="tight"
to create less padding around the text content. - Use
tileImagePadding="wide"
to add padding around the image.
The preview has been updated.
<><SelectionSet skin="tiles-mini" imageWidth="proportional"><SelectionSetInput value="IW1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Image width proportional</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="IW2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Image width proportional</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet><SelectionSet skin="tiles-mini" imageVerticalAlignment="center"><SelectionSetInput value="IVA1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Image vertical alignment center<br />and here is some more text<br />to show the vertical centering</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="IVA2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Image vertical alignment center</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet><SelectionSet skin="tiles-mini" tileContentsPadding="tight"><SelectionSetInput value="TCP1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Tile contents padding tight</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="TCP2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Tile contents padding tight</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet><SelectionSet skin="tiles-mini" tileImagePadding="wide"><SelectionSetInput value="TIP1"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=1"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Tile image padding wide</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput><SelectionSetInput value="TIP2"><SelectionSetLabel><SelectionSetTileImageContainer><FluidImagesrc="https://picsum.photos/100/100?ssm=2"alt="placeholder"/></SelectionSetTileImageContainer><SelectionSetTileContents><SelectionSetTileName>Tile image padding wide</SelectionSetTileName></SelectionSetTileContents></SelectionSetLabel></SelectionSetInput></SelectionSet></>
Nesting components
Non-interactive components can be nested inside SelectionSetLabel
because they are neutral containers. See an example below using Standard Tiles.
When a nested component inside SelectionSetLabel
has a block
root element such as Standard Tile, render it and its sub-components as span
inline elements. This is because semantically, label
shouldn't nest block level elements.
The preview has been updated.
<SelectionSet variant="single-select" defaultSelectedValue="B"><GridContainer><Row><Column span={4}><SelectionSetInput value="Option1"><SelectionSetLabel><StandardTile as="span"><StandardTileImage as="span"><BasicResponsiveImageaspectRatio={1}src="https://picsum.photos/400/400"/></StandardTileImage><StandardTileContents as="span"><StandardTileName as="span">Option 1</StandardTileName><StandardTileDescription as="span">Description</StandardTileDescription></StandardTileContents></StandardTile></SelectionSetLabel></SelectionSetInput></Column><Column span={4}><SelectionSetInput value="Option2"><SelectionSetLabel><StandardTile as="span"><StandardTileImage as="span"><BasicResponsiveImageaspectRatio={1}src="https://picsum.photos/400/400?q=1"/></StandardTileImage><StandardTileContents as="span"><StandardTileName as="span">Option 2</StandardTileName><StandardTileDescription as="span">Description</StandardTileDescription></StandardTileContents></StandardTile></SelectionSetLabel></SelectionSetInput></Column><Column span={4}><SelectionSetInput value="Option3"><SelectionSetLabel><StandardTile as="span"><StandardTileImage as="span"><BasicResponsiveImageaspectRatio={1}src="https://picsum.photos/400/400?q=2"/></StandardTileImage><StandardTileContents as="span"><StandardTileName as="span">Option 3</StandardTileName><StandardTileDescription as="span">Description</StandardTileDescription></StandardTileContents></StandardTile></SelectionSetLabel></SelectionSetInput></Column></Row></GridContainer></SelectionSet>
<div role="radiogroup" class="swan-selection-set"><div class="swan-grid-container"><div class="swan-row"><div class="swan-col-4"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option1"id="auto-id-tt3yrd0fx-321"name="auto-id-tt3yrd0fx-324"/><label class="swan-selection-set-label" for="auto-id-tt3yrd0fx-321"><span class="swan-standard-tile"><span class="swan-standard-tile-image"><spanclass="swan-responsive-image-wrapper swan-aspect-ratio-container"style="padding-bottom: 100%;"><span class="swan-aspect-ratio-content"><imgsrc="https://picsum.photos/400/400"class="swan-responsive-image" /></span></span></span><span class="swan-standard-tile-contents"><span class="swan-standard-tile-name">Option 1</span><span class="swan-standard-tile-description">Description</span></span></span></label></div><div class="swan-col-4"><inputtype="radio"class="swan-selection-set-input swan-radio"value="Option2"id="auto-id-tt3yrd0fx-322"name="auto-id-tt3yrd0fx-324"/><label class="swan-selection-set-label" for="auto-id-tt3yrd0fx-322"><span class="swan-standard-tile"><span class="swan-standard-tile-image"><spanclass="swan-responsive-image-wrapper swan-aspect-ratio-container"style="padding-bottom: 100%;"><span class="swan-aspect-ratio-content"><imgsrc="https://picsum.photos/400/400?q=1"class="swan-responsive-image" /></span></span></span><span class="swan-standard-tile-contents"><span class="swan-standard-tile-name">Option 2</span><span class="swan-standard-tile-description">Description</span></span></span></label></div><div class="swan-col-4"><input type="radio" class="swan-selection-set-input swan-radio"value="Option3 id="auto-id-tt3yrd0fx-323" name="auto-id-tt3yrd0fx-324"/><label class="swan-selection-set-label" for="auto-id-tt3yrd0fx-323"><span class="swan-standard-tile"><span class="swan-standard-tile-image"><spanclass="swan-responsive-image-wrapper swan-aspect-ratio-container"style="padding-bottom: 100%;"><span class="swan-aspect-ratio-content"><imgsrc="https://picsum.photos/400/400?q=2"class="swan-responsive-image" /></span></span></span><span class="swan-standard-tile-contents"><span class="swan-standard-tile-name">Option 3</span><span class="swan-standard-tile-description">Description</span></span></span></label></div></div></div></div>
Default value
Use defaultSelectedValue
or defaultSelectedValues
to assign initial selections. For the Vanilla API, use checked
on the input element.
Error messaging
Use SelectionSetError
to provide an error message on a Selection Set.
When a Selection Set has an error, each input should have aria-describedby
and aria-errormessage
attributes whose value is the id of the error message. The error message should not be a label tag with a for attribute pointing to the input.
The preview has been updated.
<Box><SelectionSetvariant="multi-select"skin="simple-column"defaultSelectedValue="Option1"><SelectionSetInputvalue="Option1"aria-describedby="myExampleSelectionSetError"aria-errormessage="myExampleSelectionSetError"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInputvalue="Option2"aria-describedby="myExampleSelectionSetError"aria-errormessage="myExampleSelectionSetError"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInputvalue="Option3"aria-describedby="myExampleSelectionSetError"aria-errormessage="myExampleSelectionSetError"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet><SelectionSetError id="myExampleSelectionSetError">Please make a selection.</SelectionSetError></Box>
<div><divclass="swan-selection-set swan-selection-set-skin-simple-column swan-selection-set-show-inputs"><inputtype="checkbox"aria-describedby="myExampleSelectionSetError"aria-errormessage="myExampleSelectionSetError"class="swan-selection-set-input swan-checkbox"value="Option1"id="auto-id-nvav3bf3y-716"name="auto-id-nvav3bf3y-719"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-716">Option 1</label><inputtype="checkbox"aria-describedby="myExampleSelectionSetError"aria-errormessage="myExampleSelectionSetError"class="swan-selection-set-input swan-checkbox"value="Option2"id="auto-id-nvav3bf3y-717"name="auto-id-nvav3bf3y-719"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-717">Option 2</label><inputtype="checkbox"aria-describedby="myExampleSelectionSetError"aria-errormessage="myExampleSelectionSetError"class="swan-selection-set-input swan-checkbox"value="Option3"id="auto-id-nvav3bf3y-718"name="auto-id-nvav3bf3y-719"/><label class="swan-selection-set-label" for="auto-id-nvav3bf3y-718">Option 3</label></div><p id="myExampleSelectionSetError" class="swan-selection-set-error">Please make a selection.</p></div>
Controlled
Single select
Use selectedValue
and onSelectedValueChange
in order to control the state of a single-select
Selection Set in React. onSelectedValueChange
will be invoked with the new value as the first argument and the actual input
event as the second arg in case you need it.
() => {const [selectedValue, setSelectedValue] = React.useState('Option2')return (<SelectionSetvariant="single-select"selectedValue={selectedValue}onSelectedValueChange={newSelectedValue =>setSelectedValue(newSelectedValue)}><SelectionSetInput value="Option1"><SelectionSetLabel>Option 1</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option2"><SelectionSetLabel>Option 2</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="Option3"><SelectionSetLabel>Option 3</SelectionSetLabel></SelectionSetInput></SelectionSet>)}
Multi-select
Use selectedValues
and onSelectedValuesChange
in order to control the state of a multi-select
Selection Set in React. selectedValues
is an object { [value: string]: boolean}
which represents which values are selected and which are not. If a value is omitted from the object, it will be considered unselected. onSelectedValuesChange
will be invoked with the new value as the first arg and the actual input
event as the second arg in case you need it.
() => {const [selectedValues, setSelectedValues] = React.useState({B: true,C: true,})return (<SelectionSetvariant="multi-select"selectedValues={selectedValues}onSelectedValuesChange={newSelectedValues =>setSelectedValues(newSelectedValues)}><SelectionSetInput value="A"><SelectionSetLabel>A</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="B"><SelectionSetLabel>B</SelectionSetLabel></SelectionSetInput><SelectionSetInput value="C"><SelectionSetLabel>C</SelectionSetLabel></SelectionSetInput></SelectionSet>)}
Implementation
Accessible label
The outermost element must have an accessible label such as aria-labelledby
with the title of the Selection Set. If the Selection Set does not have a visible title, use aria-label
on the outermost element instead. This label must be localized.
Accessible role
For vanilla JS, if there is more than one input in the Selection Set, the outermost element must also have a role
attribute. Use role="radiogroup"
if it is a single-select
variant. Use role="group"
if it is a multi-select variant.
Required fields
Use aria-required="true"
on an input element when a Checkbox or Radio Button is a required field in a form.
Input inside label
You cannot place another form element such as an input
tag, inside a SelectionSetLabel
or swan-selection-set-label
.
Grid
The outermost Selection Set element can be combined with a Grid row element, if the selections that the user is choosing from are spread out among the columns inside that row. For instance, if you are presenting a row of Standard Tiles to choose from, the grid row can also act as the Selection Set.