skip to content
mpkcn

~/components/file-explorer

File Explorer

A ranger-style file browser with Miller columns, a preview pane, a path bar and a / filter, driven entirely from the keyboard.

~/projects/atlas
atlas2026
relay2025
nightly2024
Dunes under an orange sky

atlas

A map viewer that streams vector tiles and keeps working offline.

status
shipped
stack
Next.js, MapLibre, IndexedDB
1/6

Installation

terminal
npx mpkcn add file-explorer
deps:none beyond react· tested with react@19.3.0

Usage

Give it a tree of folders (nodes with children) and files. Each folder opens in the next column; the selected file shows in the preview pane.

tsx
import { FileExplorer } from "@/components/mpkcn/file-explorer";

const tree = [
  {
    name: "projects",
    children: [
      {
        name: "atlas",
        meta: "2026",
        description: "A map viewer that works offline.",
        image: { src: "/shots/atlas.png", alt: "Atlas map view" },
        details: [
          { label: "status", value: "shipped" },
          { label: "stack", value: "Next.js, MapLibre" },
        ],
        href: "https://atlas.example.com",
      },
    ],
  },
  { name: "readme.md", description: "Hello." },
];

export function Projects() {
  return <FileExplorer items={tree} defaultPath={["projects", "atlas"]} />;
}

The built-in preview shows image, the name, description, details and an href link. Give one file a preview to replace it, or pass renderPreview to draw every preview yourself.

Examples

Open a file

onOpen runs on Enter or double click on a file, and adds an "open" button to the preview. In the demo above it opens the project pictures in a Media Lightbox.

tsx
<FileExplorer items={tree} onOpen={(node) => router.push(`/work/${node.id}`)} />

Narrow widths

Below 672px of its own width (a container query), it shows one column at a time above the preview, with a ‹ .. button to go back up.

~/projects/atlas
atlas2026
relay2025
nightly2024
Dunes under an orange sky

atlas

A map viewer that streams vector tiles and keeps working offline.

status
shipped
stack
Next.js, MapLibre, IndexedDB
1/6

Your own preview

renderPreview gets the selected file and the path to it.

~/projects/atlas
atlas2026
relay2025
nightly2024

$ stat projects/atlas

name: atlas

depth: 2

meta: 2026

1/6

Props

PropTypeDefaultDescription
itemsFileNode[]—Top-level files and folders. A node with `children` is a folder.
rootstring"~"Root shown at the start of the path bar.
defaultPathstring[]first at each levelIds (or names) of the starting selection, top level first.
maxColumnsnumber3Most columns side by side on wide screens.
heightnumber | string420Height of the browser body.
onSelect(node, path) => void—Called when the selected file changes.
onOpen(node, path) => void—Called on Enter or double click on a file.
renderPreview(node, path) => ReactNode—Your own preview for every file.
filterbooleantrueLet / open a filter box.
labelstring"File explorer"Accessible name of the whole browser.
classNamestring—Extra classes for the outer box.

FileNode is { name; id?; meta?; children?; keywords?; description?; image?: { src; alt? }; details?: { label; value }[]; href?; preview? }. id defaults to name and only needs to be unique among its siblings.

Accessibility

  • Each column is a listbox named after its folder, and each row an option with aria-selected. Only the selected row of each column is in the Tab order, so Tab moves from column to column and then into the preview.
  • ↑ ↓ Home End move, → or Enter go into a folder (Enter on a file calls onOpen, → moves to the preview), ← or Esc go back. / opens the filter; Esc clears it and Enter jumps to the results. The match count is a status region.
  • The preview is a labelled region you can focus and scroll with the keyboard.
  • The picture wipe and the blinking row cursor are skipped under prefers-reduced-motion.