React adapter
@subfloor/react renders the same markup and hands it to the core. It works in the Next.js App Router and renders closed on the server.
onOpenChange calls:
Usage
'use client' // only in the component that holds the state
import { Sidepanel, Modal } from '@subfloor/react'
import { useState } from 'react'
export function DeleteProject() {
const [open, setOpen] = useState(false)
return (
<>
<button onClick={() => setOpen(true)}>Delete project</button>
<Modal
title="Delete project?"
open={open}
onOpenChange={(next, reason) => setOpen(next)}
footer={<button onClick={() => setOpen(false)}>Cancel</button>}
>
<p>This removes the project and its history.</p>
</Modal>
</>
)
}- Keep the component mounted and drive it with
open; unmounting it skips the closing transition. onOpenChangeis called once for each change the user makes (Escape, backdrop, close button, acommandforbutton), never for a change you made throughopen.- A visitor can open a dialog or popover before React hydrates. It stays open, and
onOpenChange(true)is called once when React takes over, unless React already wanted it open. Try it on its own page. Clicks on your own React buttons and menu items still need React. - Without
openit is uncontrolled: open it with<button command="show-modal" commandfor={id}>and give it anid.
Removed while open
A dialog that a route change removes while it is open gives focus back only if focus was lost: to returnFocus when set, else to the button that opened it. If the page has already put focus somewhere else, such as the next thing to do, it stays there. Move focus in a layout effect or with autoFocus: a useEffect runs after the dialog is gone, so focus would visit the opener first.
Removed while open
Background
Content 1. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 2. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 3. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 4. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 5. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 6. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 7. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 8. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 9. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 10. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 11. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 12. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.