File browser
Folders and files with a folder tree, breadcrumbs, search, list and grid views, selection, a context menu, renaming and drag and drop.
c2-file-browser is the folder view of Google Drive, Dropbox or a CMS media library: a folder tree, breadcrumbs, search, sorting, a list and a grid view, selection, a context menu, renaming and drag and drop. It is the interface over your storage and never reads or writes a file itself: each thing the user asks for is an event, and your app updates items.
Import
import '@c2n/components/file-browser'Usage
Items and folders
items is a flat list of { id, name, parent, kind, size, modified, type, thumbnail }. parent is the id of the folder holding the item, empty for the root; kind is folder or file; size is in bytes, modified an ISO date or a timestamp, type a MIME type (the extension is used without one), and thumbnail the URL of a preview for the grid. folder is the open folder and root-label names the root.
For a tree too large to send at once, set loadChildren to a function that returns a folder’s items. It runs the first time a folder opens, in the list or in the tree, behind a skeleton; the result is cached until refresh().
browser.loadChildren = async (folder) => (await fetch(`/api/files?parent=${folder}`)).json()Navigation, search and sorting
A double-click or Enter opens a folder (folder-change) or fires item-open for a file; the breadcrumbs, the tree and Backspace go back up. The search field filters the open folder by name; with search="remote" it fires search for your app to answer instead. A column header or the sort menu sorts by name, date, size or kind (sort, sort-direction, sort-change), folders always first. view switches between list and grid (view-change). Below --c2-file-browser--narrow-width the folder pane gives way, an Up button appears, and each row shows its size and date under the name.
Selection and actions
A click selects one item, Ctrl or Cmd+click toggles one, Shift+click selects a range and Ctrl or Cmd+A selects everything; in the list the check box toggles one. value holds the selected ids and selection-change reports them (it does not bubble). selection="single" keeps one.
actions fills the context menu (right-click, the menu key or Shift+F10, or a row’s ⋯ button) and the bar shown while items are selected. Picking one fires item-action with the action and the items; an action marked multiple is offered for several items at once. Two ids are special: rename edits the name in place (also F2) and fires item-rename, and delete is bound to the Delete key.
Drag and drop
Dragging items onto a folder, in the list, the grid or the tree, fires item-move with the items and the target folder; a folder never goes into itself. Dropping files from the desktop fires files-drop with the files and the folder they landed in. Pair it with c2-upload or your own transport.
Accessibility
Both views are a multi-selectable list box with one Tab stop: the arrow keys move through the items (all four in the grid), Shift extends the selection, Ctrl or Cmd moves without selecting, Space toggles, Home and End jump to the ends, and typing jumps to a name. Each item is named by its name, kind, size and date (“Q4 roadmap.pdf, PDF, 2.4 MB, modified Nov 2, 2026”). The folder pane is a tree with its own keyboard, the breadcrumbs a navigation trail, and folder changes and moves are announced.