Skip to content

Commit

Permalink
feat(useFileDialog): add directory parameters (#3513)
Browse files Browse the repository at this point in the history
Co-authored-by: banruo <shl@dataqin.com>
  • Loading branch information
huiliangShen and banruo committed Nov 9, 2023
1 parent b6d2bd3 commit cefca9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit cefca9a

Please sign in to comment.