Collapsible
A collapsible panel controlled by a button.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use Phem\Ui\Collapsible;
use function Phem\Ui\{CollapsiblePanel, CollapsibleTrigger};
#[Component]
function CollapsibleHeroDemo(): Node
{
return (
<Collapsible>
<CollapsibleTrigger>Recovery keys</CollapsibleTrigger>
<CollapsiblePanel>
<div className="flex flex-col gap-2 px-3.5 py-2">
<div>alien-bean-pasta</div>
<div>wild-irish-burrito</div>
<div>horse-battery-staple</div>
</div>
</CollapsiblePanel>
</Collapsible>
);
}
Examples#
#
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 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.
API reference#
Import the components of the family:
use Phem\Ui\Collapsible;
use function Phem\Ui\{CollapsibleTrigger, CollapsiblePanel};Collapsible#
A section that opens and closes: Base UI Collapsible.Root, on the phem-collapsible controller.
| Prop | Type | Default |
|---|---|---|
defaultOpen | bool | false |
disabled | bool | false |
children | ?Html | null |
...attrs | array | [] |
CollapsibleTrigger#
The button that opens and closes the panel. It has a caret that turns when the panel is open.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
CollapsiblePanel#
The panel. Its height animates with --collapsible-panel-height. With hiddenUntilFound, the closed panel has hidden="until-found": the search of the browser (Ctrl+F) finds its text and opens it.
| Prop | Type | Default |
|---|---|---|
hiddenUntilFound | bool | false |
children | ?Html | null |
...rest | mixed | — |
The source of the examples: examples/ui/Collapsible.phem.