Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(useFileDialog): add directory parameters #3513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/useFileDialog/index.md
Expand Up @@ -13,6 +13,7 @@ import { useFileDialog } from '@vueuse/core'

const { files, open, reset, onChange } = useFileDialog({
accept: 'image/*', // Set to accept only image files
directory: true, // Select directories instead of files if set true
})

onChange((files) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/useFileDialog/index.ts
Expand Up @@ -23,12 +23,19 @@ export interface UseFileDialogOptions extends ConfigurableDocument {
* @default false
*/
reset?: boolean
/**
* Select directories instead of files.
* @see [HTMLInputElement webkitdirectory](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory)
* @default false
*/
directory?: boolean
}

const DEFAULT_OPTIONS: UseFileDialogOptions = {
multiple: true,
accept: '*',
reset: false,
directory: false,
}

export interface UseFileDialogReturn {
Expand Down Expand Up @@ -79,6 +86,8 @@ export function useFileDialog(options: UseFileDialogOptions = {}): UseFileDialog
}
input.multiple = _options.multiple!
input.accept = _options.accept!
// webkitdirectory key is not stabled, maybe replaced in the future.
input.webkitdirectory = _options.directory!
if (hasOwn(_options, 'capture'))
input.capture = _options.capture!
if (_options.reset)
Expand Down