-
+
+
+
+
+
+
+
+
+
+
+
+ {{ state.avatar.name }}
+
+
+
+
+
+
+
+
+
+
+ {{ files?.[0]?.name }}
+
+
+
diff --git a/playground/app/pages/index.vue b/playground/app/pages/index.vue
index 057f52a8..991b8d12 100644
--- a/playground/app/pages/index.vue
+++ b/playground/app/pages/index.vue
@@ -1,81 +1,11 @@
-
-
-
-
-
-
+
+
+ Playground
+
-
-
-
-
-
-
+
+
+
+
diff --git a/src/runtime/components/FileUpload.vue b/src/runtime/components/FileUpload.vue
index 354bf713..5b708ff1 100644
--- a/src/runtime/components/FileUpload.vue
+++ b/src/runtime/components/FileUpload.vue
@@ -33,6 +33,7 @@ export interface FileUploadProps
{
* @defaultValue false
*/
dropzone?: boolean
+ defaultValue?: File[]
class?: any
ui?: FileUpload['slots']
}
@@ -46,6 +47,7 @@ export interface FileUploadSlots {
open: UseFileDialogReturn['open']
reset: UseFileDialogReturn['reset']
previewUrls: string[]
+ files: FileList[]
}): any
}
@@ -73,9 +75,8 @@ const appConfig = useAppConfig() as FileUpload['AppConfig']
const { emitFormInput, emitFormChange, id, name, disabled, ariaAttrs } = useFormField(props, { deferInputValidation: true })
-// eslint-disable-next-line vue/no-dupe-keys
const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.fileUpload || {}) })({
-
+ dropzone: props.dropzone
}))
const inputRef = ref()
@@ -84,14 +85,14 @@ const { files, open, reset, onCancel, onChange } = useFileDialog({
multiple: props.multiple,
accept: props.accept,
reset: props.reset,
- input: inputRef.value
+ input: inputRef.value,
+ initialFiles: props.defaultValue
})
const previewUrls = computed(() => Array.from(files.value || []).map(file => URL.createObjectURL(file)))
onChange((files) => {
- console.log('files:', typeof files?.[0])
- modelValue.value = props.multiple ? files : files?.[0]
+ modelValue.value = (props.multiple ? files : files?.[0]) as (M extends true ? File[] : File) | null
})
onCancel(() => {
@@ -101,7 +102,7 @@ onCancel(() => {
-
+
{
:required="required"
:disabled="disabled"
hidden
+ tabindex="-1"
v-bind="{ ...$attrs, ...ariaAttrs }"
>
diff --git a/src/theme/file-upload.ts b/src/theme/file-upload.ts
index ab5a7066..269d3c46 100644
--- a/src/theme/file-upload.ts
+++ b/src/theme/file-upload.ts
@@ -1,5 +1,11 @@
export default {
slots: {
- root: ''
+ root: '',
+ base: ''
+ },
+ variants: {
+ dropzone: {
+ base: 'border-dashed'
+ }
}
}