Skip to content

Commit 0916a21

Browse files
committed
fix: correct input reset method name and enhance extension handling in Dropzone component
1 parent 520bdbc commit 0916a21

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

adminforth/spa/src/afcl/Dropzone.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<!-- tag form used to reset the input (method .reset() in claer() function) -->
2+
<!-- tag form used to reset the input (method .reset() in clear() function) -->
33
<form class="flex items-center justify-center w-full"
44
@dragover.prevent="dragging = true"
55
@dragleave.prevent="dragging = false"
@@ -20,7 +20,7 @@
2020
:id="id"
2121
type="file"
2222
class="hidden"
23-
:accept="props.extensions.join(',')"
23+
:accept="normalizedExtensions.join(',')"
2424
@change="$event.target && doEmit(($event.target as HTMLInputElement).files!)"
2525
:multiple="props.multiple || false"
2626
/>
@@ -80,7 +80,7 @@
8080
</p>
8181

8282
<p class="text-xs text-lightDropzoneText dark:text-darkDropzoneText">
83-
{{ props.extensions.join(', ').toUpperCase().replace(/\./g, '') }}
83+
{{ normalizedExtensions.join(', ').toUpperCase().replace(/\./g, '') }}
8484
<template v-if="props.maxSizeBytes">
8585
(Max size: {{ humanifySize(props.maxSizeBytes) }})
8686
</template>
@@ -92,7 +92,7 @@
9292

9393
<script setup lang="ts">
9494
import { humanifySize } from '@/utils';
95-
import { ref, type Ref } from 'vue';
95+
import { ref, type Ref, computed } from 'vue';
9696
import { IconFileSolid } from '@iconify-prerendered/vue-flowbite';
9797
import { watch } from 'vue';
9898
import adminforth from '@/adminforth';
@@ -108,6 +108,13 @@ const emit = defineEmits(['update:modelValue']);
108108
109109
const id = `afcl-dropzone-${Math.random().toString(36).substring(7)}`;
110110
111+
const normalizedExtensions = computed(() => {
112+
return props.extensions.map(ext => {
113+
const trimmed = ext.trim().toLowerCase();
114+
return trimmed.startsWith('.') ? trimmed : `.${trimmed}`;
115+
});
116+
});
117+
111118
const selectedFiles: Ref<{
112119
name: string,
113120
size: number,
@@ -131,7 +138,7 @@ function doEmit(filesIn: FileList) {
131138
132139
const multiple = props.multiple || false;
133140
const files = Array.from(filesIn);
134-
const allowedExtensions = props.extensions.map(ext => ext.toLowerCase());
141+
const allowedExtensions = normalizedExtensions.value;
135142
const maxSizeBytes = props.maxSizeBytes;
136143
137144
if (!files.length) return;

0 commit comments

Comments
 (0)