Files
FileExplorer
Browse a nested file collection, open files from the keyboard, and preview local files when available.
import '@reactloom/files/styles.css';
import { FileExplorer } from '@reactloom/files';Examples
Operations file browser
- Reports
- Inbox
Choose a file to preview.
import { FileExplorer, type FileExplorerEntry } from '@reactloom/files';
import { useState } from 'react';
export default function Example() {
const [entries] = useState<FileExplorerEntry[]>(() => [
{ id: 'reports', label: 'Reports', children: [
{ id: 'daily', label: 'Daily reconciliation', file: new File(['Order,Total\n1042,830'], 'reconciliation.csv', { type: 'text/csv' }) },
] },
{ id: 'inbox', label: 'Inbox', children: [] },
]);
return <FileExplorer label="Operations files" entries={entries} />;
}Controlled document selection
- Incident notes
- Handover checklist
Incident notes
import { useState } from 'react';
import { FileExplorer } from '@reactloom/files';
const entries = [{ id: 'incident', label: 'Incident notes' }, { id: 'handover', label: 'Handover checklist' }];
export default function Example() {
const [selected, setSelected] = useState<string | null>('incident');
return <FileExplorer label="Support documents" entries={entries} selectedId={selected} onOpen={(entry) => setSelected(entry.id)} />;
}API reference
| Prop | Type | Default |
|---|---|---|
entriesNodes with IDs and labels. Folders supply children and files can supply a browser File. | readonly FileExplorerEntry[] | — |
labelName the explorer and its tree. | string | — |
selectedId · defaultSelectedIdControlled or initial selection. | string | null | — |
onOpenCalled when a file is activated. | (item: FileExplorerEntry) => void | — |
emptyMessagePrompt displayed before selecting a file. | string | — |
Keyboard interaction
| Key | Action |
|---|---|
| Up / Down | Move through visible folders and files |
| Left / Right | Collapse or expand a folder in reading order |
| Enter / Space | Toggle a folder or open a file |
| Tab | Move to the selected file’s download link |
Usage guidelines
The root explorer accepts className, style, and a ref.
Do
- Supply stable IDs and fetch file content in the consuming app when using a remote filesystem.
Don’t
- Avoid using filenames as IDs when separate folders can contain files with the same name.