Fixed #9 - Auto z-index layering for Toast

pull/41/head
cagataycivici 2019-07-11 10:39:23 +03:00
parent de04fd88ba
commit e749db2c7b
2 changed files with 36 additions and 2 deletions

View File

@ -1,5 +1,5 @@
<template>
<div :class="containerClass">
<div ref="container" :class="containerClass">
<transition-group name="p-toast-message" tag="div">
<ToastMessage v-for="msg of messages" :key="msg.id" :message="msg" @close="remove($event)"/>
</transition-group>
@ -9,15 +9,27 @@
<script>
import ToastEventBus from './ToastEventBus';
import ToastMessage from './ToastMessage';
import DomHandler from '../utils/DomHandler';
var messageIdx = 0;
export default {
props: {
group: String,
group: {
type: String,
default: null
},
position: {
type: String,
default: 'topright'
},
autoZIndex: {
type: Boolean,
default: true
},
baseZIndex: {
type: Number,
default: 0
}
},
data() {
@ -39,6 +51,11 @@ export default {
ToastEventBus.$on('remove-all-groups', () => {
this.messages = [];
});
this.updateZIndex();
},
beforeUpdate() {
this.updateZIndex();
},
methods: {
add(message) {
@ -58,6 +75,11 @@ export default {
}
this.messages.splice(index, 1);
},
updateZIndex() {
if (this.autoZIndex) {
this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
}
}
},
components: {

View File

@ -178,6 +178,18 @@ this.$toast.removeAllGroups();
<td>string</td>
<td>topright</td>
<td>Position of the toast in viewport, valid values are "topright", "topleft", "bottomleft" and "bottomright".</td>
</tr>
<tr>
<td>autoZIndex</td>
<td>boolean</td>
<td>true</td>
<td>Whether to automatically manage layering.</td>
</tr>
<tr>
<td>baseZIndex</td>
<td>number</td>
<td>0</td>
<td>Base zIndex value to use in layering.</td>
</tr>
</tbody>
</table>