Overlays
Popover
Small non-modal panel opened by a button, for interactive content.
Example
cr-popover shows a button, named by label, that opens a panel anchored below it (or above when space runs out). The panel content is free: a short form, settings, links. The panel grows out of the button with a spring.
'use client';
import { useState } from 'react';
import { CrButton, CrCheckbox, CrInput, CrPopover } from '@cristal-ui/react';
export default function PopoverBasic() {
const [open, setOpen] = useState(false);
return (
<CrPopover label="Share" open={open} onCrToggle={(event) => setOpen(event.detail)}>
<div style={{ display: 'grid', gap: 'var(--cr-spacing-lg)', width: 280 }}>
<CrInput label="Recipient address" type="email" />
<CrCheckbox label="Allow editing" />
<CrButton onClick={() => setOpen(false)}>Invite</CrButton>
</div>
</CrPopover>
);
}Opening and closing
The user closes the panel with Escape, a click outside, the button, or by tabbing out of the panel. To close it after an action ("Invite", "Apply"), set open back to false; onCrToggle reports every opening and closing done by the user.
For plain help text, prefer a tooltip; for a list of actions, a menu; for a task that must block the page, a dialog.
If the user asked their system to reduce motion, the panel appears and disappears straight away, without growing.
Accessibility
- The button carries
aria-haspopup="dialog",aria-expandedandaria-controls; the panel is a non-modal dialog (role="dialog") named by the button. - On opening, focus goes to the first interactive element of the panel, or to the panel itself when it has none.
- Escape closes the panel and returns focus to the button, as does an action that closes it while focus is inside.
- The panel does not trap focus: Tab leaves it and closes it, the rest of the page stays usable.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Désactive le bouton. |
label (obligatoire) | string | — | Libellé du bouton, qui nomme aussi le panneau pour les lecteurs d'écran (obligatoire). |
open | boolean | false | Panneau ouvert ; à remettre à false pour le fermer après une action (« Appliquer »). |
Events
| React | event.detail | Description |
|---|---|---|
onCrToggle | boolean | Émis quand l'utilisateur ouvre ou ferme le panneau ; detail : l'état ouvert. |
Slots
| Slot | Description |
|---|---|
| default | Le contenu du panneau. |
CSS parts
To style it from outside: cr-popover::part(name) { … }
| Part | Description |
|---|---|
panel | Le panneau. |
trigger | Le bouton qui ouvre le panneau. |