8000 feat(useFileDialog): add directory parameters (#3513) · vueuse/vueuse@cefca9a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit cefca9a

Browse files
huiliangShenbanruo
andauthored
feat(useFileDialog): add directory parameters (#3513)
Co-authored-by: banruo <shl@dataqin.com>
1 parent b6d2bd3 commit cefca9a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/core/useFileDialog/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useFileDialog } from '@vueuse/core'
1313

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

1819
onChange((files) => {

packages/core/useFileDialog/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ export interface UseFileDialogOptions extends ConfigurableDocument {
2323
* @default false
2424
*/
2525
reset?: boolean
26+
/**
27+
* Select directories instead of files.
28+
* @see [HTMLInputElement webkitdirectory](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory)
29+
* @default false
30+
*/
31+
directory?: boolean
2632
}
2733

2834
const DEFAULT_OPTIONS: UseFileDialogOptions = {
2935
multiple: true,
3036
accept: '*',
3137
reset: false,
38+
directory: false,
3239
}
3340

3441
export interface UseFileDialogReturn {
@@ -79,6 +86,8 @@ export function useFileDialog(options: UseFileDialogOptions = {}): UseFileDialog
7986
}
8087
input.multiple = _options.multiple!
8188
input.accept = _options.accept!
89+
// webkitdirectory key is not stabled, maybe replaced in the future.
90+
input.webkitdirectory = _options.directory!
8291
if (hasOwn(_options, 'capture'))
8392
input.capture = _options.capture!
8493
if (_options.reset)

0 commit comments

Comments
 (0)
0