fn
useFileDialog
v0.0.14testeddemoOpen a native file dialog programmatically and reactively track the selected files.
Examples
ts
const { files, open, onChange } = useFileDialog({ accept: 'image/*' });
onChange((selected) => console.log(selected));
open();ts
// Override options for a single call
const { open } = useFileDialog();
open({ multiple: false, accept: '.pdf' });Demo
Loading demo…
Signature
ts
export function useFileDialog(options: UseFileDialogOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
options? | UseFileDialogOptions | Options |
Returns
UseFileDialogReturnfiles, open, reset, onChange, and onCancel| Property | Type | Description |
|---|---|---|
files | ComputedRef<FileList | null> | The currently selected files, or null when none are selected |
open | (localOptions?: Partial<UseFileDialogOptions>) => void | Open the file dialog, optionally overriding options for this call only |
reset | () => void | Clear the current selection |
onChange | FileDialogEventHookOn<FileList | null> | Register a callback fired when the selection changes |
onCancel | FileDialogEventHookOn | Register a callback fired when the dialog is dismissed without a selection |