Components
Accordion
A set of collapsible panels with headings.
Anatomy#
Import the component and assemble its parts:
import { Accordion } from '@egoist/solid-base/accordion';
<Accordion.Root>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger />
</Accordion.Header>
<Accordion.Panel />
</Accordion.Item>
</Accordion.Root>;Examples#
Open multiple panels#
You can set up the accordion to allow multiple panels to be open at the same time using the
multiple prop.
Hidden until found#
The hiddenUntilFound prop hides closed panels with
hidden="until-found"
so the browser can search their contents and reveal the matching panel automatically. It can be
set on each Accordion.Panel, or once on Accordion.Root to apply to all panels.
To try it, press Ctrl+F (Cmd+F on macOS) and search
for "restocking" — the browser opens the closed panel containing the match. When
hiddenUntilFound is enabled, closed panels always remain mounted in the DOM, which also makes
their contents indexable by search engines.
Older browsers that don't support hidden="until-found" keep panels hidden until their trigger
opens them, and find-in-page skips over the contents.
Controlled#
Pass value (an array of the open items' values) and update it from onValueChange. Give each
Accordion.Item a value to identify it:
const [value, setValue] = createSignal(['shipping']);
<Accordion.Root value={value()} onValueChange={(next) => setValue(next)}>
<Accordion.Item value="shipping">{/* ... */}</Accordion.Item>
<Accordion.Item value="returns">{/* ... */}</Accordion.Item>
</Accordion.Root>;API reference#
<Accordion.Root>
Groups all parts of the accordion. Renders a <div> element.
valueAccordionValue<Value>—The controlled value of the item(s) that should be expanded.
To render an uncontrolled accordion, use the defaultValue prop instead.
defaultValueAccordionValue<Value>—The uncontrolled value of the item(s) that should be initially expanded.
To render a controlled accordion, use the value prop instead.
disabledbooleanfalseWhether the component should ignore user interaction.
hiddenUntilFoundbooleanfalseAllows the browser's built-in page search to find and expand the panel contents.
Overrides the keepMounted prop and uses hidden="until-found" to hide the element without removing it from the DOM.
keepMountedbooleanfalseWhether to keep the element in the DOM while the panel is closed. This prop is ignored when hiddenUntilFound is used.
loopFocusboolean—Deprecated following the APG guidance update to remove roving focus.
This prop no longer affects keyboard focus behavior.
onValueChange| ((value: AccordionValue<Value>, eventDetails: AccordionRootChangeEventDetails) => void)—Event handler called when an accordion item is expanded or collapsed. Provides the new value as an argument.
multiplebooleanfalseWhether multiple items can be open at the same time.
orientationOrientation'vertical'Deprecated following the APG guidance update to remove roving focus.
This prop no longer affects keyboard focus behavior.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the accordion is disabled.
data-orientationIndicates the orientation of the accordion.
<Accordion.Trigger>
A button that opens and closes the corresponding panel. Renders a <button> element.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-indexIndicates the index of the accordion item.
data-panel-openPresent when the accordion panel is open.
data-disabledPresent when the trigger or its accordion item is disabled.
<Accordion.Item>
Groups an accordion header with the corresponding panel. Renders a <div> element.
valueany—A unique value that identifies this accordion item. If no value is provided, a unique ID will be generated automatically. Use when controlling the accordion programmatically, or to set an initial open state.
disabledbooleanfalseWhether the component should ignore user interaction.
onOpenChange| ((open: boolean, eventDetails: AccordionItem.ChangeEventDetails) => void)—Event handler called when the panel is opened or closed.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-indexIndicates the index of the accordion item.
data-disabledPresent when the accordion item is disabled.
data-openPresent when the accordion item is open.
<Accordion.Header>
A heading that labels the corresponding panel. Renders an <h3> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-indexIndicates the index of the accordion item.
data-disabledPresent when the accordion item is disabled.
data-openPresent when the accordion item is open.
<Accordion.Panel>
A collapsible panel with the accordion item contents. Renders a <div> element.
hiddenUntilFoundbooleanfalseAllows the browser's built-in page search to find and expand the panel contents.
Overrides the keepMounted prop and uses hidden="until-found" to hide the element without removing it from the DOM.
keepMountedbooleanfalseWhether to keep the element in the DOM while the panel is closed. This prop is ignored when hiddenUntilFound is used.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-indexIndicates the index of the accordion item.
data-openPresent when the accordion panel is open.
data-orientationIndicates the orientation of the accordion.
data-disabledPresent when the accordion item is disabled.
--accordion-panel-heightThe accordion panel's height.
--accordion-panel-widthThe accordion panel's width.