Components
Collapsible
A collapsible panel controlled by a button.
Anatomy#
Import the component and assemble its parts:
import { Collapsible } from '@egoist/solid-base/collapsible';
<Collapsible.Root>
<Collapsible.Trigger />
<Collapsible.Panel />
</Collapsible.Root>;Examples#
Hidden until found#
The hiddenUntilFound prop hides the closed panel with
hidden="until-found"
so the browser can search its contents with find-in-page — Ctrl+F
(Cmd+F on macOS) — and reveal the panel when a match is found. The closed
panel always remains mounted in the DOM, which also makes its contents indexable by search
engines.
Older browsers that don't support hidden="until-found" keep the panel hidden until its trigger
opens it, and find-in-page skips over the contents.
<Collapsible.Root>
<Collapsible.Trigger>Shipping details</Collapsible.Trigger>
<Collapsible.Panel hiddenUntilFound>Standard shipping takes 3–5 business days.</Collapsible.Panel>
</Collapsible.Root>See the Accordion example for an interactive demo.
API reference#
<Collapsible.Root>
Groups all parts of the collapsible. Renders a <div> element.
openboolean—Whether the collapsible panel is currently open.
To render an uncontrolled collapsible, use the defaultOpen prop instead.
defaultOpenbooleanfalseWhether the collapsible panel is initially open.
To render a controlled collapsible, use the open prop instead.
onOpenChange| ((open: boolean, eventDetails: CollapsibleRootChangeEventDetails) => void)—Event handler called when the panel is opened or closed.
disabledbooleanfalseWhether the component should ignore user interaction.
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-openPresent when the collapsible is open.
data-closedPresent when the collapsible is closed.
<Collapsible.Trigger>
A button that opens and closes the collapsible 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-panel-openPresent when the collapsible panel is open.
data-disabledPresent when the trigger or the collapsible is disabled.
<Collapsible.Panel>
A panel with the collapsible 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 hidden. 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-openPresent when the collapsible panel is open.
data-closedPresent when the collapsible panel is closed.
--collapsible-panel-heightThe collapsible panel's height.
--collapsible-panel-widthThe collapsible panel's width.