INTEGRATIONS / FILE BROWSER
Find the useful details.
A keyboard-friendly folder tree and a clear view of file metadata. Your application supplies the data.
Start with the whole interaction.
The file browser connects folder selection, breadcrumbs, local search, sorting and a metadata inspector. The example Archive folder loads only when requested. Preview states let you check empty, loading, rejected and malformed results.
npx shadcn@latest add https://ui.bld8.dev/r/file-browser.jsonThe Next.js and Vite starters contain the same reusable React source. Sample entries are illustrative metadata. File contents, uploads, downloads, authentication and a storage API belong to the host application.
Connect a directory service.
import {FileBrowser, type FileBrowserProps} from '@bld8/blocks';
const loadChildren: NonNullable<FileBrowserProps['loadChildren']> =
async (parentId, {signal}) => {
const response = await fetch(
'/api/files?parentId=' + encodeURIComponent(parentId), {signal}
);
if (!response.ok) throw new Error('This folder could not be loaded.');
return response.json();
};
<FileBrowser entries={rootEntries} loadChildren={loadChildren} />This endpoint is an integration example for your own API. Authorise every folder request on the server. Return an array of entries with stable unique IDs, a label, and kind set to folder or file. The block validates lazy results before merging them; duplicate identities and invalid structures become a recoverable folder error.
For unloaded folders, set hasChildren and leave children undefined. An empty children array means the folder was loaded and is empty. Keep modified labels deterministic, and provide size in bytes for files when known.
Keep each request in its place.
The block owns its loading indicators, successful child cache and per-folder retry. It passes an AbortSignal, ignores stale results and clears the request scope when inputs change or the block unmounts. Your loader must forward the signal to fetch or other abortable work. Initial collection loading and connection errors use loading, error and onRetry.
Search applies to the current loaded folder. It does not search unloaded descendants or issue a server query. Sorting changes presentation; it does not move files. The inspector reads metadata only.
Keep focus with the next step.
Activating a focused table folder, breadcrumb, Up, Load folder or Retry folder moves focus to the persistent folder heading. Clear file search returns focus to the search field. Tree selection and sorting retain their own focus.
Initial and replacement data do not autofocus. Async results never reclaim focus after the user moves elsewhere. If your workspace retry remounts the entire block, your application owns focus continuity across that replacement.
Use the Tree on its own.
Tree supplies roving focus, expand/collapse, typeahead and explicit single selection. Arrow keys move focus without changing selection. Space selects; Enter selects and activates. Folder activation also toggles expansion.
<Tree label="Workspace folders" nodes={nodes}
expandedIds={expanded} onExpandedChange={setExpanded}
selectedId={selected} onSelectedChange={setSelected}
loadingIds={loading} errors={folderErrors}
onLoadChildren={requestChildren} />The primitive requests children; its host owns async work, cancellation, caching and updated nodes. Loading and error descriptions stay attached to the folder. Right Arrow or Enter can retry a failed expanded folder; the file-browser block also provides a visible retry action.
Motion that follows the interaction.
Folder groups open with a short eased height and opacity transition. Rows remain steady, and collapsing content immediately leaves the keyboard and accessibility path. Results and recovery states enter with short eased opacity and position changes; replaced content unmounts immediately, without retaining interactive exiting content. The heading and toolbar stay steady. Live reduced-motion changes remove the animated travel. Narrow layouts stack the tree, file list and inspector in reading order.
Review keyboard flow, real labels and assistive-technology behaviour in your final application. The example is a working starting point for metadata navigation, not a filesystem or cloud-storage service.