Shadcn File Browser Table
Folders and files in a table: move through folders with the breadcrumbs, select files to download or delete, and expand a file to see its details.
$ npx shadcn add https://www.shad-table.dev/r/file-browser-table.json3 items · 161 MB
| 4 items | ||
| 2 items | ||
| 96 KB |
A folder's name opens it. A file's name shows its details.
How it works
1.The table shows one folder at a time
The tree stays in one piece, and the table only gets the children of the open folder. The breadcrumbs are the path from the root to that folder, so every folder above is one click away.
const path = findPath(tree, folderId) ?? [tree]const folder = path[path.length - 1]<FileTable folder={folder} … />
2.Folders stay on top
Sorting by name, size or date reorders folders and files separately, so folders are always first, as in any file manager. The table runs with manualSorting and the entries are sorted before they reach it.
return [...entries].sort((a, b) => {if (a.kind !== b.kind) return a.kind === 'folder' ? -1 : 1return by[sort.id](a, b) * dir || by.name(a, b)})
3.A folder's name opens it, a file's name shows its details
Only files can expand. The details row lists what the file is: dimensions, pages or duration depending on its type, then size, dates, owner, version, location and tags. On small screens the Type, Owner and Modified columns hide, and the details still have them.
getRowCanExpand: (row) => row.original.kind === 'file',
4.Selection belongs to the folder
Moving to another folder clears the selection and closes any details, so Delete never touches files you can no longer see. The bar above the table shows how many are selected and their total size.
setFolderId(id)setRowSelection({})setExpanded({})
5.Focus follows you through the folders
Opening a folder moves focus to its name in the breadcrumbs. Going back up focuses the folder you came out of, so keyboard and screen reader users keep their place.
focusNext.current = folder.id.startsWith(`${id}/`)? childToward(id, folder.id): 'crumb'