Skip to content

Commit

Permalink
feat(useFileDialog): add a parameter reset (#3059)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaqvil committed May 12, 2023
1 parent 6676ef7 commit 6d8477c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/core/useFileDialog/index.ts
Expand Up @@ -18,11 +18,17 @@ export interface UseFileDialogOptions extends ConfigurableDocument {
* @see [HTMLInputElement Capture](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture)
*/
capture?: string
/**
* Reset when open file dialog.
* @default false
*/
reset?: boolean
}

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

export interface UseFileDialogReturn {
Expand Down Expand Up @@ -57,6 +63,12 @@ export function useFileDialog(options: UseFileDialogOptions = {}): UseFileDialog
}
}

const reset = () => {
files.value = null
if (input)
input.value = ''
}

const open = (localOptions?: Partial<UseFileDialogOptions>) => {
if (!input)
return
Expand All @@ -69,16 +81,11 @@ export function useFileDialog(options: UseFileDialogOptions = {}): UseFileDialog
input.accept = _options.accept!
if (hasOwn(_options, 'capture'))
input.capture = _options.capture!

if (_options.reset)
reset()
input.click()
}

const reset = () => {
files.value = null
if (input)
input.value = ''
}

return {
files: readonly(files),
open,
Expand Down

0 comments on commit 6d8477c

Please sign in to comment.