Overlays
Dialogs, menus, popovers, tooltips and toasts, each with the keyboard and focus behavior people expect.
Dialog
A dialog interrupts for one task: a floating card that rises 4px as it opens and fades as it closes. It is the native dialog element, so focus moves in, stays in, and returns to the control that opened it, and the page behind cannot be reached. Escape and the close button dismiss it. With guard set, dismissing asks before discarding what was typed, and a click on the backdrop never closes it. A dialog may scroll inside itself when its content is taller than the screen; it is the one place a nested scroll area is expected.
Session name: Morning session
Code
"use client";
import { useState } from "react";
import { Button, Dialog, Field, FormStatus, TextInput } from "@oxidase/ui";
/** A task in a dialog. Escape and the close button dismiss it; unsaved input asks first. */
export function DialogDemo() {
const [open, setOpen] = useState(false);
const [name, setName] = useState("Morning session");
const [draft, setDraft] = useState(name);
const dirty = draft !== name;
return (
<>
<Button
onClick={() => {
setDraft(name);
setOpen(true);
}}
>
Rename session
</Button>
<FormStatus>Session name: {name}</FormStatus>
<Dialog
open={open}
onClose={() => setOpen(false)}
title="Rename session"
description="The name appears in your journal. It does not change the record."
closeLabel="Close rename session"
guard={dirty ? "Discard the new name?" : undefined}
footer={
<>
<Button onClick={() => setOpen(false)}>Cancel</Button>
<Button
variant="primary"
onClick={() => {
setName(draft.trim() || name);
setOpen(false);
}}
>
Save name
</Button>
</>
}
>
<Field label="Name">
<TextInput value={draft} onChange={(event) => setDraft(event.currentTarget.value)} />
</Field>
</Dialog>
</>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | None | Whether the dialog is shown. |
onClose | () => void | None | Called on Escape, the close button, or the backdrop when unguarded. |
title | ReactNode | None | Required. Names the dialog for assistive technology. |
description | ReactNode | None | One or two sentences of context, read with the title. |
closeLabel | string | "Close" | Name the record: Close ticket 1042. |
size | "small" | "regular" | "large" | "regular" | 26, 34, or 46rem wide, never wider than the screen. |
placement | "center" | "sheet" | "center" | A sheet rises from the bottom on phones and sits at the side on larger screens. |
guard | string | None | The question asked before discarding unsaved input. |
footer | ReactNode | None | Actions, aligned to the end. The confirming action goes last. |
Confirm dialog
Before something that cannot be undone, ask once, name exactly what is lost, and make the confirming button say the action. For the most destructive actions, ask for a typed word; its field has a visible label.
Code
"use client";
import { useState } from "react";
import { Button, ConfirmDialog, FormStatus } from "@oxidase/ui";
/** A destructive confirmation that names what is lost and asks for the word. Nothing is deleted here. */
export function ConfirmDemo() {
const [open, setOpen] = useState(false);
const [outcome, setOutcome] = useState("");
return (
<>
<Button onClick={() => setOpen(true)}>Delete practice history</Button>
<FormStatus>{outcome}</FormStatus>
<ConfirmDialog
open={open}
onClose={() => setOpen(false)}
onConfirm={() => {
setOpen(false);
setOutcome("In the product this would delete the history. This example changes nothing.");
}}
title="Delete practice history?"
description="Every session and trial on this account is removed. Exports you already downloaded are not affected. This cannot be undone."
confirmLabel="Delete history"
danger
typeToConfirm="DELETE"
/>
</>
);
}Popover
A popover holds a small, non-modal panel attached to its trigger, such as filters. Focus is not trapped. Escape closes it and returns focus to the trigger; a click outside closes it and leaves focus where the click put it.
Code
<Popover label="Ticket filters" trigger="Filters">
<Checkbox label="Open" defaultChecked />
<Checkbox label="Waiting on member" />
<Checkbox label="Closed this week" />
</Popover>
Tooltip
A tooltip names or briefly explains a control, on hover and on keyboard focus, and Escape dismisses it. It is never the only place important information lives, because touch screens cannot hover.
Code
<Tooltip content="Download this session as CSV">
<IconButton
label="Download this session as CSV"
icon={<Icon icon={Download} size="small" />}
variant="secondary"
/>
</Tooltip>
Toast
A toast confirms that an action finished and, when it can, offers to undo it. It is announced politely and stays while it is pointed at or focused. Errors never appear in a toast: a failure belongs beside the thing that failed, where it can be fixed.
Ticket 1042 is open.
Code
"use client";
import { useState } from "react";
import { Button, FormStatus, Stack, ToastProvider, useToast } from "@oxidase/ui";
function ArchiveButton({ onArchive, onUndo }: { onArchive: () => void; onUndo: () => void }) {
const toast = useToast();
return (
<Button
onClick={() => {
onArchive();
toast.show({ message: "Ticket archived", action: { label: "Undo", onAction: onUndo } });
}}
>
Archive ticket
</Button>
);
}
/** A completed action with an undo. Toasts never carry errors: those belong beside what failed. */
export function ToastDemo() {
const [archived, setArchived] = useState(false);
return (
<ToastProvider>
<Stack gap="s8" align="start">
<ArchiveButton onArchive={() => setArchived(true)} onUndo={() => setArchived(false)} />
<FormStatus>{archived ? "Ticket 1042 is archived." : "Ticket 1042 is open."}</FormStatus>
</Stack>
</ToastProvider>
);
}Layers
Floating layers stack in a fixed order, so a menu inside a dialog or a toast above both always lands right.
layer.sticky10layer.nav40layer.dropdown50layer.overlay60layer.modal70layer.toast80layer.skip90
- Never invent a z-index. If something needs to float, it belongs to one of these layers.