Changed dialog stack from using element ids to data-ids to allow duplicate ids to work

This commit is contained in:
Stefan Zermatten
2019-02-18 15:17:31 +02:00
parent a31a70f435
commit e63ae96cb5
9 changed files with 38 additions and 36 deletions

View File

@@ -4,8 +4,8 @@
Test Dialog
</div>
<div>
<v-btn @click="openDialog(_uid + 'btn')" :id="_uid + 'btn'">Open Dialog</v-btn>
<v-btn fab @click="openDialog(_uid + 'fab')" :id="_uid + 'fab'" color="green">Open Dialog</v-btn>
<v-btn @click="openDialog('btn')" data-id="btn">Open Dialog</v-btn>
<v-btn fab @click="openDialog('fab')" data-id="fab" color="green">Open Dialog</v-btn>
</div>
</dialog-base>
</template>

View File

@@ -1,7 +1,7 @@
<template lang="html">
<v-card-text>
<v-layout align-center justify-center>
<v-btn @click="openDialog(_uid + 'btn')" :id="_uid + 'btn'">
<v-btn @click="openDialog('btn')" data-id="btn">
Open Dialog
</v-btn>
</v-layout>

View File

@@ -22,6 +22,7 @@
:data-element-id="dialog.elementId"
:data-return-element-id="dialog.returnElementId"
:data-index="index"
:ref="index"
:style="getDialogStyle(index)"
:elevation="6"
>
@@ -49,10 +50,6 @@
},
},
methods: {
logAndReturn(thing){
console.log(thing);
return thing;
},
popDialogStack(result){
this.$store.dispatch("popDialogStack", result);
},
@@ -67,13 +64,22 @@
const top = (num - index) * -OFFSET;
return `left:${left}px; top:${top}px;`;
},
getTopElementByDataId(elementId, offset = 0){
let stackLength = this.$store.state.dialogStack.dialogs.length - offset;
if (stackLength){
let topDialog = this.$refs[stackLength - 1][0];
return topDialog.$el.querySelector(`[data-id='${elementId}']`);
} else {
return document.querySelector(`[data-id='${elementId}']`);
}
},
enter(target, done){
if (!target || !target.attributes['data-element-id']){
done();
return;
}
let elementId = target.attributes['data-element-id'].value;
let source = document.getElementById(elementId);
let source = this.getTopElementByDataId(elementId, 1);
if (!source){
done();
return;
@@ -119,7 +125,7 @@
}
elementId = target.attributes['data-element-id'].value;
}
let source = document.getElementById(elementId);
let source = this.getTopElementByDataId(elementId);
if (!source){
done();
return;