sp-accordion

Examples API

Attributes and Properties #

Property Attribute Type Default Description
allowMultiple allow-multiple boolean false Allows multiple accordion items to be opened at the same time
autofocus autofocus boolean false When this control is rendered, focus it automatically
disabled disabled boolean false Disable this control. It will not receive focus or events
tabIndex tabIndex number The tab index to apply to this control. See general documentation about the tabindex HTML property

Slots #

Name Description
default slot The sp-accordion-item children to display.

CSS Custom Properties #

Name Default
--spectrum-accordion-border-color var(--spectrum-global-color-gray-300)
--spectrum-accordion-icon-color var(--spectrum-global-color-gray-600)
--spectrum-accordion-icon-color-disabled var(--spectrum-alias-icon-color-disabled)
--spectrum-accordion-icon-color-hover var(--spectrum-alias-icon-color-hover)
--spectrum-accordion-icon-gap var(--spectrum-global-dimension-size-100)
--spectrum-accordion-icon-height var(--spectrum-global-dimension-size-125)
--spectrum-accordion-item-background-color-hover var(--spectrum-global-color-gray-200)
--spectrum-accordion-item-border-left-color-key-focus var(--spectrum-alias-border-color-key-focus)
--spectrum-accordion-item-border-left-size var(--spectrum-alias-border-size-thick)
--spectrum-accordion-item-border-size var(--spectrum-alias-border-size-thin)
--spectrum-accordion-item-content-padding var(--spectrum-global-dimension-size-200)
--spectrum-accordion-item-padding-x var(--spectrum-global-dimension-size-225)
--spectrum-accordion-item-title-text-size var(--spectrum-global-dimension-font-size-50)
--spectrum-accordion-item-title-tracking var(--spectrum-global-font-letter-spacing-medium)
--spectrum-accordion-text-color var(--spectrum-global-color-gray-700)
--spectrum-accordion-text-color-disabled var(--spectrum-global-color-gray-500)
--spectrum-accordion-text-color-hover var(--spectrum-global-color-gray-900)
--spectrum-accordion-text-line-height var(--spectrum-alias-component-text-line-height)

Description #

The <sp-accordion> element contains a list of items that can be expanded or collapsed to reveal additional content or information associated with each item. There can be zero expanded items, exactly one expanded item, or more than one item expanded at a time, depending on the configuration. This list of items is defined by child <sp-accordion-item> elements that are targetted to the default slot of their <sp-accordion> parent.

Usage #

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

yarn add @spectrum-web-components/accordion

Import the side effectful registration of <sp-accordion> and <sp-accordion-item> via:

import '@spectrum-web-components/accordion/sp-accordion.js';
import '@spectrum-web-components/accordion/sp-accordion-item.js';

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

import { Accordion, AccordionItem } from '@spectrum-web-components/accordion';

Example #

<sp-accordion>
<sp-accordion-item label="Heading 1">
<div>Item 1</div>
</sp-accordion-item>
<sp-accordion-item disabled label="Heading 2">
<div>Item 2</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 3">
<div>Item 3</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 4">
<div>Item 4</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 5">
<div>Item 5</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 6">
<div>Item 6</div>
</sp-accordion-item>
</sp-accordion>

Allow Multiple #

<sp-accordion allow-multiple>
<sp-accordion-item label="Heading 1">
<div>Item 1</div>
</sp-accordion-item>
<sp-accordion-item disabled label="Heading 2">
<div>Item 2</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 3">
<div>Item 3</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 4">
<div>Item 4</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 5">
<div>Item 5</div>
</sp-accordion-item>
<sp-accordion-item label="Heading 6">
<div>Item 6</div>
</sp-accordion-item>
</sp-accordion>