Skip to content
Eskais UI

Blocks

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
  • Online
    Kitchen
  • Updating
    Hall
  • Low battery
    Garage
  • Offline
    Porch
  • Online
    Office
  • Online
    Nursery
No device open

Installation

npx shadcn@latest add @eskais/master-detail

Usage

Import
import { masterDetail } from "@/components/ui/master-detail-primitive"import {  useDetailFocus,  useNarrowerThan,  useSelectedId,  useStoredFlag,  useSyncAfterCommit,} from "@/components/ui/use-master-detail"import {  MasterDetailContext,  MasterDetailDetailHeader,  MasterDetailIdle,  MasterDetailListPane,  MasterDetailRail,  masterDetailLabels,  useMasterDetail,} from "@/components/ui/master-detail-parts"import { MasterDetail, masterDetailLabels, useMasterDetail } from "@/components/ui/master-detail"

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

PropTypeDefault
labelrequiredstring–
headerReactNode–
toolbarReactNode–
paneRefrequired(element: HTMLElement | null) => void–
onFocusRowrequired(target: EventTarget) => void–
childrenrequiredReactNode–

MasterDetailDetailHeader

PropTypeDefault
viewrequiredMasterDetailView–
titleIdrequiredstring–
headingLevelrequired2 | 3 | 4–
labelsrequiredMasterDetailLabels–
stackedrequiredBack on a stacked layout; Close and Collapse beside the list.boolean–
onClose() => void–
onCollapse() => void–

MasterDetailRail

PropTypeDefault
labelrequiredstring–
onExpandrequired() => void–

MasterDetailIdle

PropTypeDefault
titleReactNode–
titleIdrequiredstring–
labelsrequiredMasterDetailLabels–
stackedrequiredStacked, it collapses to a bar; beside the list, to the rail.boolean–
collapsedrequiredboolean–
onToggleShows the collapse button.() => void–
childrenrequiredReactNode–

MasterDetail

PropTypeDefault
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–
selectedIdstring | null–
defaultSelectedIdstring | 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.booleanfalse
collapsibleAdds a button that collapses the detail to a rail with an expand button.booleanfalse
defaultCollapsedbooleanfalse
onCollapsedChange(collapsed: boolean) => void–
resizableA handle between the panes resizes them, by drag or arrow keys.booleanfalse
defaultListSizeThe list's starting share of the width when resizable, like `40` (percent) or `"22rem"`.ResizableSize38
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.booleantrue
headingLevelThe level of the open item's title. Default 2.2 | 3 | 42
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"
labelsPartial<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 MasterDetailProps

Accessibility

  • 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.