Skip to content

Commit 7934d33

Browse files
committed
Disable globalDropZone when dropZoneSelector exists
1 parent b4514d0 commit 7934d33

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

demo/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- just for tests -->
33
<video src="#" style="background-color: aqua"> TEST </video>
44

5+
<!--<FileInput :state="state" :drop-zone-selector="'#app'">-->
56
<FileInput :state="state" :global-drop-zone="true">
67
<FileInputSelectedInfo :state="state"/>
78
</FileInput>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alttiri/vue-file-input",
3-
"version": "1.6.1-20251108",
3+
"version": "1.7.0-20251108",
44
"type": "module",
55
"description": "Vue.js file input with Drag and Drop support.",
66
"homepage": "https://github.com/alttiri/vue-file-input",

src/components/FileInput.vue

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ const templateInputElem: Ref<HTMLFileInputElement | null> = ref(null);
1212
1313
type IProps = {
1414
state: FileInputState,
15-
globalDropZone?: boolean,
15+
globalDropZone?: boolean | null,
1616
dropZoneSelector?: string | null,
1717
accept?: string,
1818
multiple?: boolean,
1919
nwdirectory?: boolean,
2020
}
2121
2222
const props = withDefaults(defineProps<IProps>(), {
23-
globalDropZone: true,
23+
globalDropZone: null,
2424
dropZoneSelector: null,
2525
accept: "*/*",
2626
multiple: true,
@@ -51,6 +51,16 @@ onMounted(() => {
5151
inputElem.value = templateInputElem.value;
5252
});
5353
54+
const globalDropZoneEx = computed(() => {
55+
if (dropZoneSelector.value) {
56+
return false;
57+
}
58+
if (globalDropZone.value === null) {
59+
return true;
60+
}
61+
return globalDropZone.value;
62+
});
63+
5464
function onFileInputChange(event: Event) {
5565
const fileElem = event.target as HTMLFileInputElement;
5666
setFiles(fileElem.files);
@@ -62,7 +72,7 @@ const dropZone: ComputedRef<HTMLElement | null> = computed(() => {
6272
if (dropZoneSelector.value) {
6373
return document.querySelector(dropZoneSelector.value);
6474
} else
65-
if (globalDropZone.value) {
75+
if (globalDropZoneEx.value) {
6676
return document.body;
6777
}
6878
return fileInputElem.value;
@@ -118,7 +128,7 @@ function onDragOver(event: DragEvent) {
118128
}
119129
function onDragEnter(event: DragEvent) {
120130
stopEvent(event);
121-
if (globalDropZone.value && event.relatedTarget !== null) {
131+
if (globalDropZoneEx.value && event.relatedTarget !== null) {
122132
return;
123133
}
124134
if (!dropHover.value) {
@@ -130,7 +140,7 @@ function onDragEnter(event: DragEvent) {
130140
}
131141
function onDragLeave(event: DragEvent) {
132142
stopEvent(event);
133-
if (globalDropZone.value) {
143+
if (globalDropZoneEx.value) {
134144
if (event.relatedTarget !== null) {
135145
return;
136146
}

0 commit comments

Comments
 (0)