Skip to main content

fast-accordion

As defined by the W3C:

An accordion is a vertically stacked set of interactive headings that each contain a title, content snippet, or thumbnail representing a section of content. The headings function as controls that enable users to reveal or hide their associated sections of content. Accordions are commonly used to reduce the need to scroll when presenting multiple sections of content on a single page.

Setup

Basic Setup

import {
provideFASTDesignSystem,
fastAccordion,
fastAccordionItem
} from "@microsoft/fast-components";

provideFASTDesignSystem()
.register(
fastAccordion(),
fastAccordionItem()
);

Customizing Icons

import {
provideFASTDesignSystem,
fastAccordion,
fastAccordionItem
} from "@microsoft/fast-components";

provideFASTDesignSystem()
.register(
fastAccordion(),
fastAccordionItem({
collapsedIcon: `...your collapsed icon...`,
expandedIcon: `...your expanded icon...`,
})
);

Usage

Live Editor
Result
Loading...

Create your own design

Accordion

import { Accordion, accordionTemplate as template } from "@microsoft/fast-foundation";
import { accordionStyles as styles } from "./my-accordion.styles";

export const myAccordion = Accordion.compose({
baseName: "accordion",
template,
styles,
});

AccordionItem

import {
AccordionItem,
AccordionItemOptions,
accordionItemTemplate as template,
} from "@microsoft/fast-foundation";
import { accordionItemStyles as styles } from "./my-accordion-item.styles";

export const myAccordionItem = AccordionItem.compose<AccordionItemOptions>({
baseName: "accordion-item",
template,
styles,
collapsedIcon: `...default collapsed icon...`,
expandedIcon: `...default expanded icon...`,
});

API

class: Accordion

Superclass

NameModulePackage
FoundationElement/src/foundation-element/foundation-element.js

Fields

NamePrivacyTypeDefaultDescriptionInherited From
expandmodepublicAccordionExpandModeControls the expand mode of the Accordion, either allowing single or multiple item expansion.
$presentationpublicComponentPresentation or nullA property which resolves the ComponentPresentation instance for the current component.FoundationElement
templatepublicElementViewTemplate or void or nullSets the template of the element instance. When undefined, the element will attempt to resolve the template from the associated presentation or custom element definition.FoundationElement
stylespublicElementStyles or void or nullSets the default styles for the element instance. When undefined, the element will attempt to resolve default styles from the associated presentation or custom element definition.FoundationElement

Methods

NamePrivacyDescriptionParametersReturnInherited From
templateChangedprotectedvoidFoundationElement
stylesChangedprotectedvoidFoundationElement

Events

NameTypeDescriptionInherited From
changeFires a custom 'change' event when the active item changes

Attributes

NameFieldInherited From
expand-modeexpandmode

CSS Parts

NameDescription
itemThe slot for the accordion items

Variables

NameDescriptionType
AccordionExpandModeExpand mode for Accordion{ single: "single", multi: "multi", }

class: AccordionItem

Superclass

NameModulePackage
FoundationElement/src/foundation-element/foundation-element.js

Fields

NamePrivacyTypeDefaultDescriptionInherited From
headinglevelpublic1 or 2 or 3 or 4 or 5 or 62Configures the level of the heading element.
expandedpublicbooleanfalseExpands or collapses the item.
idpublicstringThe item ID
$presentationpublicComponentPresentation or nullA property which resolves the ComponentPresentation instance for the current component.FoundationElement
templatepublicElementViewTemplate or void or nullSets the template of the element instance. When undefined, the element will attempt to resolve the template from the associated presentation or custom element definition.FoundationElement
stylespublicElementStyles or void or nullSets the default styles for the element instance. When undefined, the element will attempt to resolve default styles from the associated presentation or custom element definition.FoundationElement

Methods

NamePrivacyDescriptionParametersReturnInherited From
templateChangedprotectedvoidFoundationElement
stylesChangedprotectedvoidFoundationElement

Events

NameTypeDescriptionInherited From
changeFires a custom 'change' event when the button is invoked

Attributes

NameFieldInherited From
heading-levelheadinglevel
expanded
idid

CSS Parts

NameDescription
headingWraps the button
buttonThe button which serves to invoke the item
heading-contentWraps the slot for the heading content within the button
iconThe icon container
expanded-iconThe expanded icon slot
collapsed-iconThe collapsed icon
regionThe wrapper for the accordion item content

Slots

NameDescription
startContent which can be provided between the heading and the icon
endContent which can be provided between the start slot and icon
headingContent which serves as the accordion item heading and text of the expand button
The default slot for accordion item content
expanded-iconThe expanded icon
collapsed-iconThe collapsed icon

Additional resources