Skip to content

Commit d0552f9

Browse files
Merge pull request #25 from Shaxine/master
Fix: Improved Snackbar stacking and placement when a dialog is shown
2 parents 1bb10a6 + a5b2b2b commit d0552f9

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<template>
2+
<v-card rounded="lg">
3+
<v-card-title color="primary" class="d-flex justify-space-between align-center">
4+
<div class="text-h5 text-medium-emphasis">
5+
Custom Dialog
6+
</div>
7+
<v-btn
8+
icon="mdi-close"
9+
variant="text"
10+
@click="close"
11+
></v-btn>
12+
</v-card-title>
13+
14+
<v-divider></v-divider>
15+
16+
<v-card-text class="text-center">
17+
{{ message }}
18+
<br/>
19+
<v-btn
20+
color="purple"
21+
text="Nested Notification"
22+
@click="showNotification"
23+
></v-btn>
24+
</v-card-text>
25+
26+
<v-divider></v-divider>
27+
28+
<v-card-actions class="d-flex justify-end">
29+
<v-btn
30+
class="text-none"
31+
color="success"
32+
rounded="xl"
33+
text="Confirm"
34+
variant="flat"
35+
@click="close"
36+
></v-btn>
37+
</v-card-actions>
38+
</v-card>
39+
</template>
40+
41+
<script setup>
42+
import { createNotification } from 'vuetify3-dialog'
43+
44+
const props = defineProps({
45+
message: {
46+
type: String,
47+
required: false
48+
}
49+
})
50+
51+
const emit = defineEmits(['closeDialog'])
52+
function close() {
53+
emit('closeDialog', false)
54+
}
55+
56+
function showNotification() {
57+
createNotification({
58+
text: "Notification from dialog!",
59+
notifyOptions: {
60+
timeout: 3000,
61+
location: 'bottom right'
62+
}
63+
})
64+
}
65+
</script>

cypress/test-server/src/components/HelloWorld.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<v-btn id="create-custom-component-dialog" @click="createCustomComponentDialog()" color="warning">Custom component Dialog</v-btn>
1919
<v-btn id="success-dialog" @click="successDialog()" color="success">Success Dialog</v-btn>
2020
<v-btn id="confirm-dialog" @click="confirmDialog()" color="primary">Confirm Dialog</v-btn>
21+
<br/>
22+
<v-btn id="custom-component-dialog-notif" @click="customComponentDialogNotif()" color="brown">Dialog w/Notification</v-btn>
2123
</div>
2224
</div>
2325

@@ -58,6 +60,7 @@
5860
<script lang="ts">
5961
import { defineComponent } from "vue";
6062
import MyComponent from "./MyComponent.vue";
63+
import DialogNotifComponent from "./DialogNotifComponent.vue";
6164
import sfcExampleVue from "./sfc-example.vue";
6265
6366
@@ -94,6 +97,17 @@ export default defineComponent({
9497
}
9598
})
9699
},
100+
customComponentDialogNotif(){
101+
this.$dialog.create({
102+
customComponent: {
103+
component: DialogNotifComponent,
104+
props: { message: "Notification within Dialog!" }
105+
},
106+
dialogOptions: {
107+
width: "600px"
108+
}
109+
})
110+
},
97111
successDialog(){
98112
this.$dialog.success({title: "My success dialog", text: "Hello world!"})
99113
},

src/Snackbar.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export function createNotification(options: CreateNotifyOptions) {
3939
options.notifyOptions?.location ||
4040
PluginContext.getPluginOptions()?.defaults?.notify?.location ||
4141
'top right';
42-
let location = potentialLocation.split(' ')[0] || 'top';
42+
let locationY = potentialLocation.split(' ')[0] || 'top';
43+
let locationX = potentialLocation.split(' ')[1] || 'right';
4344
let div = document.createElement('div');
4445

4546
if (!isNotEmptyAndNotNull(options.text)) throw new Error('text is required');
@@ -65,17 +66,22 @@ export function createNotification(options: CreateNotifyOptions) {
6566

6667
if ((vuetifyDivOverlay as HTMLElement)?.childElementCount > 1) {
6768
for (let child of (vuetifyDivOverlay as HTMLElement).children) {
68-
if (child === (vuetifyDivOverlay as HTMLElement).lastElementChild) continue;
69-
// console.log('child', child);
69+
if (
70+
child === (vuetifyDivOverlay as HTMLElement).lastElementChild ||
71+
!(
72+
child.classList.contains('v-snackbar--' + locationX) &&
73+
child.classList.contains('v-snackbar--' + locationY)
74+
)
75+
)
76+
continue;
7077
if ((child as HTMLElement).lastElementChild) {
71-
// console.log('child of child', (child as HTMLElement).lastElementChild);
7278
margin += ((child as HTMLElement).lastElementChild as HTMLElement).offsetHeight + 12;
7379
}
7480
}
7581
}
7682

7783
if (margin > 0) {
78-
switch (location) {
84+
switch (locationY) {
7985
case 'top':
8086
(vuetifyDivOverlay?.lastElementChild as HTMLElement).style.marginTop = `${margin + 12}px`;
8187
break;

0 commit comments

Comments
 (0)