Master Detail
MasterDetail: a list with a detail pane, side by side on wide containers and stacked below 42rem with a Back button. Controlled or uncontrolled selection, optional URL sync through a router-agnostic adapter (hash routers included), j/k that follow focus, a detail that collapses to a rail or resizes, remembered under a storageKey, and focus that moves to the detail's heading and back to the row. Agents open and close items by the block's name.
Example
Devices
6- OnlineKitchen
- UpdatingHall
- Low batteryGarage
- OfflinePorch
- OnlineOffice
- OnlineNursery
Installation
lucide-reactUsage
A list with a detail pane, for review queues, inspectors and device lists: pass the list and a detail(id) view, and let it handle selection, stacking and focus.
API reference
MasterDetailListPane
| Prop | Type | Default |
|---|---|---|
labelrequired | string | – |
header | ReactNode | – |
toolbar | ReactNode | – |
paneRefrequired | (element: HTMLElement | null) => void | – |
onFocusRowrequired | (target: EventTarget) => void | – |
childrenrequired | ReactNode | – |
MasterDetailDetailHeader
| Prop | Type | Default |
|---|---|---|
viewrequired | MasterDetailView | – |
titleIdrequired | string | – |
headingLevelrequired | 2 | 3 | 4 | – |
labelsrequired | MasterDetailLabels | – |
stackedrequiredBack on a stacked layout; Close and Collapse beside the list. | boolean | – |
onClose | () => void | – |
onCollapse | () => void | – |
MasterDetailRail
| Prop | Type | Default |
|---|---|---|
labelrequired | string | – |
onExpandrequired | () => void | – |
MasterDetailIdle
| Prop | Type | Default |
|---|---|---|
title | ReactNode | – |
titleIdrequired | string | – |
labelsrequired | MasterDetailLabels | – |
stackedrequiredStacked, it collapses to a bar; beside the list, to the rail. | boolean | – |
collapsedrequired | boolean | – |
onToggleShows the collapse button. | () => void | – |
childrenrequired | ReactNode | – |
MasterDetail
| Prop | Type | Default |
|---|---|---|
labelrequiredNames the block: agents open and close items through it by this name. | string | – |
listThe list, whose rows read the selection with `useMasterDetail()`. Or use `renderList`. | ReactNode | – |
renderListRenders the list with the selection: usually a `List` whose rows spread `state.itemProps(id)`. | (state: MasterDetailState) => ReactNode | – |
renderDetailrequiredThe open item's view, or null when the id is unknown (then `emptyDetail` shows). | (id: string) => MasterDetailView | null | – |
emptyDetailShown beside the list while nothing is open, on wide containers (and stacked ones with `idleDetail="visible"`). | ReactNode | – |
emptyDetailTitleA title for `emptyDetail`, in a bar above it that also holds its collapse button; it names the pane. | ReactNode | – |
idleDetailWhat a stacked container (under 42rem) shows while nothing is open: `hidden` (default) only the list; `visible` keeps `emptyDetail` under the list, like a live monitor, with a button that collapses it to its bar. With `collapsible`, the idle detail also gets that button beside the list, where it collapses to the rail. | "hidden" | "visible" | "hidden" |
height`fill` (default) fills the parent's height, for a bounded box like an app shell's main column. `auto` sizes it to its content between `--master-detail-min-height` (16rem) and `--master-detail-max-height` (40rem), the panes scrolling inside, for a block in a scrolling page. | "fill" | "auto" | "fill" |
headerAbove the list, like a title and a count. | ReactNode | – |
toolbarUnder the header, like a search field or filters. | ReactNode | – |
selectedId | string | null | – |
defaultSelectedId | string | null | – |
onSelectedIdChange | (id: string | null, details: ChangeDetails<MasterDetailSelectReason>) => void | – |
itemsThe items agents may open, `{ id, label }`. Without them `open` takes any id and lists none. | readonly MasterDetailEntry[] | – |
urlKeeps the selected id in the URL when uncontrolled: `createUrlParam("device")` from `@/lib/url-param`. | UrlParamAdapter | – |
followFocusWhile an item is open on a wide container, moving focus to another row (j/k, arrows) opens it. | boolean | false |
collapsibleAdds a button that collapses the detail to a rail with an expand button. | boolean | false |
defaultCollapsed | boolean | false |
onCollapsedChange | (collapsed: boolean) => void | – |
resizableA handle between the panes resizes them, by drag or arrow keys. | boolean | false |
defaultListSizeThe list's starting share of the width when resizable, like `40` (percent) or `"22rem"`. | ResizableSize | 38 |
storageKeyRemembers the collapsed state and the panes' sizes in localStorage under keys that start with this. | string | – |
closableShows a Close button in the detail's header on wide containers. Default true. | boolean | true |
headingLevelThe level of the open item's title. Default 2. | 2 | 3 | 4 | 2 |
getRowElementThe focusable element of a row, to return focus to. By default the row with `data-item-id` or `data-row-id`. | (id: string) => HTMLElement | null | undefined | – |
scopeThe `ShortcutScope` that Escape belongs to. | string | "master-detail" |
labels | Partial<MasterDetailLabels> | – |
style`--master-detail-height` (100% by default) and `--master-detail-list-width` set the block's size; with `height="auto"`, `--master-detail-min-height` and `--master-detail-max-height` bound it. `--master-detail-idle-height` (50%) caps a stacked idle detail. | CSSProperties | – |
Also takes <div> attributes and render except children, aria-label, style.
Other exports
masterDetailuseDetailFocususeNarrowerThanuseSelectedIduseStoredFlaguseSyncAfterCommitMasterDetailContextmasterDetailLabelsuseMasterDetailtype MasterDetailEntrytype MasterDetailOptionstype MasterDetailSelectReasontype FocusRequesttype MasterDetailLabelstype MasterDetailStatetype MasterDetailViewtype MasterDetailPropsAccessibility
- The list and the detail are named regions; the open row has aria-current.
- Opening moves focus to the detail's heading, and Close, Back or Escape return it to the row that opened it.
- Below 42rem of container the panes stack: the list, or the open item with a Back button. Nothing overlays.
- With idleDetail="visible" the idle detail stays under the list, with a Collapse/Expand button that keeps focus and says aria-expanded.
Agent actions
Agents open and close items through the block by its label (open(id), close()), with the items you pass listed as choices; Back, Close, Collapse and Expand are buttons they press by name.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.