React Reference ยท Props and Attributes
React popover attributes (popover and popoverTarget)
Reference for the HTML popover attributes in React 19: popover, popoverTarget, popoverTargetAction and the onToggle and onBeforeToggle events.
The HTML popover API turns any element into a layer that floats above the page and sits in the browser's top layer, with no z-index fighting and no portal. Light dismiss (click outside, press Escape) and focus handling come built in. React 19 passes the relevant attributes through, so you can write popovers as plain JSX.
Three attributes do the work. popover marks an element as a popover (it is hidden until opened). popoverTarget on a <button> or <input type="button"> names the popover's id. popoverTargetAction chooses whether that button toggles, shows or hides it. The popover also fires toggle events, which React exposes as onToggle and onBeforeToggle.
<button popoverTarget="menu">Open</button> <div id="menu" popover="auto">Hello</div>
Try it
Syntax
<div popover="auto | manual | hint" id="..." onToggle={fn} onBeforeToggle={fn} /> <button popoverTarget="id" popoverTargetAction="toggle | show | hide" />
| Name | Description |
|---|---|
popover |
"auto" (also ""): light dismiss, closes other auto popovers. "manual": no light dismiss, opened and closed explicitly. "hint": a lightweight popover such as a tooltip, in browsers that support it. |
popoverTarget |
The id of the popover this button controls. |
popoverTargetAction |
"toggle" (default), "show" or "hide". |
onBeforeToggle |
Runs just before the popover opens or closes. event.newState is "open" or "closed". Cancelable when opening. |
onToggle |
Runs after the state changed. Gives event.oldState and event.newState. |
Edge cases: pass popover as a string. In React 19, popover={true} or the bare shorthand popover is not a recognized boolean and logs a warning; write popover="" or popover="auto".
Usage notes
- No state needed for basic use. The browser tracks open and closed. Read the state only if the UI elsewhere depends on it, using
onToggle. - Imperative control. Call
ref.current.showPopover(),hidePopover()ortogglePopover()from an event handler.matches(':popover-open')tells you whether it is open. - Styling. Popovers get default UA styles (centered, with a border). Reset them with your own CSS, and style the open state with
:popover-open. The backdrop is::backdrop. - Anchoring is separate. The popover API places the element in the top layer but does not position it next to the button. Use CSS anchor positioning where supported, or compute the position yourself.
- Accessibility. The attributes wire up the relationship between button and popover for assistive tech, and
autopopovers return focus to the invoker on close. A popover is not a dialog: for modal behavior use<dialog>withshowModal(). - Do not combine
inertcarelessly. An inert popover cannot be interacted with. See inert. - Support. Popover is Baseline, available in current Chrome, Edge, Safari and Firefox. Check
HTMLElement.prototype.hasOwnProperty('popover')if you must support older browsers. - React 19 and later. Older React versions need workarounds because they did not know these attributes.
Related
- inert, Event handlers, Focus events, createPortal
- Lessons: Portals, Accessibility