Skip to content

File Dialog

FileDialog is the complete open/save picker: filename history, wildcard filtering, a two-column listing, metadata, scroll bars, and mode-specific actions. Every read goes through an injectable FileSystem, so the same component works with Node storage or a confined in-memory tree.

Usage

ts
import { FileDialog } from '@jsvision/files';
import { signal } from '@jsvision/ui';

const dialog = new FileDialog({
  fs: virtualFs,
  directory: signal('/workspace'),
  wildcard: signal('*.ts'),
  showError: (message) => showStatus(message),
});

Live example

Inspect the composed picker, navigate a virtual project, and launch the real modal FileDialog.

Props and public state

FileDialog exposes its directory, wildcard, and filename signals plus the composed FileList, FileInput, FileInfoPane, history control, list scroll bar, action buttons, and result(). FileDialogOptions accepts an injectable FileSystem. Prefer openFile when you only need a resolved path and do not need those internals.

Configuration

FileDialogOptions fieldTypeDefaultPurpose
fsFileSystemnodeFileSystemSupplies every path, listing, and stat operation.
directorySignal<string>resolved current working directoryDrives browsing and metadata.
wildcardSignal<string>*.*Filters file rows; directories remain navigable.
filenameSignal<string>empty signalReceives list focus and typed paths or wildcards.
savebooleanfalseSelects open actions or the save/replace/clear action set.
filter(entry: DirEntry) => booleannoneAdds a file predicate after wildcard matching.
titlestringlocalized open/save titleLabels the modal frame.
inputNamestringlocalized Name labelChanges the filename label and accelerator.
i18nI18nisolated English catalogLocalizes package-owned text.
historyIdnumberfile-dialog history IDIsolates the recent-path list.
showError(message: string) => voidnonePresents invalid-parent or empty-name feedback.
onResolve(path: string | null) => voidnoneObserves a successful path before modal completion.

Browsing and resolving

Activating a directory descends without closing. A wildcard typed into the filename field updates the list. For an ordinary non-empty filename, the dialog validates that its parent path is a readable directory, records the absolute result, and closes. It does not require the target file to exist; that is necessary for Save As and means open workflows must validate/read the returned path themselves. An empty name or an invalid/unreadable parent calls showError and remains open.

ts
import { openFile } from '@jsvision/files';

const path = await openFile(app, {
  fs: virtualFs,
  directory: '/workspace',
  wildcard: '*.ts',
});
if (path !== null) {
  const source = virtualFs.readFile(path); // open-mode existence/readability check
  openSource(source);
}

Open and save modes

Open mode presents Open, Cancel, and Help. Save mode adds Replace and Clear behavior and changes the default title and action set. Recent-path history remains separate from Change Directory history. Replace copies the focused entry into filename; Clear empties it. Neither action closes the dialog.

Sizing and layout

The dialog is drag-resizable but never below its translated design minimum. Its flex composition grows the listing and keeps the filename, metadata, bar, and action column reachable.

Best practices

  • Inject a narrow FileSystem; never let a browser example reach host disk.
  • Treat showError as required product feedback even though it is technically optional.
  • Use openFile for ordinary modal ownership and direct construction for customization.

Theming

The frame uses dialog; metadata uses fileInfo; embedded lists, inputs, history, scroll bars, and buttons use their standard theme roles.