Skip to content
Unkey Design Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Slide panel

A panel that slides in from the edge for a focused create or edit task.

import {
  Button,
  FormInput,
  SlidePanel,
  SlidePanelCloseButton,
  SlidePanelContent,
  SlidePanelHeader,
  SlidePanelTitle,
} from "@unkey/ui";
import { useState } from "react";

export default function SlidePanelDirty() {
  const [open, setOpen] = useState(false);
  const [name, setName] = useState("Acme API");

  return (
    <>
      <Button variant="outline" onClick={() => setOpen(true)}>
        Rename app
      </Button>
      <SlidePanel
        isOpen={open}
        onClose={() => setOpen(false)}
        onExitComplete={() => setName("Acme API")}
        dirty={name !== "Acme API"}
        widthClassName="w-96"
        fitContent
      >
        <SlidePanelHeader>
          <SlidePanelTitle>Rename app</SlidePanelTitle>
          <SlidePanelCloseButton />
        </SlidePanelHeader>
        <SlidePanelContent className="px-6 pt-4 pb-6">
          <FormInput label="Name" value={name} onChange={(e) => setName(e.target.value)} />
        </SlidePanelContent>
      </SlidePanel>
    </>
  );
}

Unsaved changes

Pass dirty when the panel holds edits. Escape, the backdrop and the close button then open a “Discard unsaved changes?” dialog before onClose runs.

Forms inside the panel can report on their own instead. Any child that calls useReportUnsavedChanges(dirty) arms the same dialog. SettingsGroupContent and SettingsGroupCollapsible already report.

The panel reports outward as well, so a page guard above it knows the panel holds changes.

Unsaved-changes registry

  • useUnsavedChanges() returns { isDirty, report } for the component that owns a scope.
  • UnsavedChangesScope passes report to its children.
  • useReportUnsavedChanges(dirty) reports from a child. It does nothing outside a scope.
  • DiscardChangesDialog is the shared confirm dialog. Use it only when you build a new guard. Pass copy to change its title, description and button labels, and loading while the discard runs. A loading dialog cannot be dismissed.

SlidePanelClose renders the Base UI close part. Give it a render prop for a Cancel button, and it goes through the same discard check.