Also show modal when pressing Esc, handle multiple Escs
This commit is contained in:
parent
cf6bf8243c
commit
fbcd7eee93
1 changed files with 31 additions and 10 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="modal-example" ref="calibrationModalEl" uk-modal="bg-close: false;">
|
<div id="modal-example" ref="calibrationModalEl" uk-modal="bg-close: false; esc-close:false;">
|
||||||
<div class="uk-modal-dialog uk-modal-body">
|
<div class="uk-modal-dialog uk-modal-body">
|
||||||
<!-- Get the style from uk-close, but use stop.prevent to avoid it actually closing -->
|
<!-- Get the style from uk-close, but use stop.prevent to avoid it actually closing -->
|
||||||
<button
|
<button
|
||||||
|
|
@ -47,6 +47,8 @@ export default {
|
||||||
tasks: [],
|
tasks: [],
|
||||||
taskIndex: 0,
|
taskIndex: 0,
|
||||||
movingBackward: false,
|
movingBackward: false,
|
||||||
|
modalOpen: false,
|
||||||
|
confirmingClose: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -159,12 +161,18 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
show: function () {
|
show: function () {
|
||||||
|
this.modalOpen = true;
|
||||||
|
window.addEventListener("keydown", this.handleKeydown);
|
||||||
|
|
||||||
// Show the modal element
|
// Show the modal element
|
||||||
var el = this.$refs["calibrationModalEl"];
|
var el = this.$refs["calibrationModalEl"];
|
||||||
this.showModalElement(el); // Calls the mixin
|
this.showModalElement(el); // Calls the mixin
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function () {
|
hide: function () {
|
||||||
|
this.modalOpen = false;
|
||||||
|
window.removeEventListener("keydown", this.handleKeydown);
|
||||||
|
|
||||||
// Show the modal
|
// Show the modal
|
||||||
var el = this.$refs["calibrationModalEl"];
|
var el = this.$refs["calibrationModalEl"];
|
||||||
this.hideModalElement(el); // Calls the mixin
|
this.hideModalElement(el); // Calls the mixin
|
||||||
|
|
@ -174,19 +182,32 @@ export default {
|
||||||
this.$emit("onClose");
|
this.$emit("onClose");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleKeydown(event) {
|
||||||
|
if (event.key === "Escape" && !event.repeat && this.modalOpen && !this.confirmingClose) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.confirmClose();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
confirmClose() {
|
confirmClose() {
|
||||||
|
if (this.confirmingClose) return;
|
||||||
|
this.confirmingClose = true;
|
||||||
let confirmationMessage =
|
let confirmationMessage =
|
||||||
"Close calibration wizard?<br><br>This can be re-opened from the Settings tab at any time.";
|
"Close calibration wizard?<br><br>This can be re-opened from the Settings tab at any time.";
|
||||||
// Use standard modal confirmation
|
// Use standard modal confirmation
|
||||||
this.modalConfirm(confirmationMessage).then(
|
this.modalConfirm(confirmationMessage)
|
||||||
() => {
|
.then(
|
||||||
// User clicked YES → hide modal
|
() => {
|
||||||
this.hide();
|
// User clicked YES → hide modal
|
||||||
},
|
this.hide();
|
||||||
() => {
|
},
|
||||||
// User clicked NO → do nothing, modal stays open
|
() => {
|
||||||
},
|
// User clicked NO → do nothing, modal stays open
|
||||||
);
|
},
|
||||||
|
)
|
||||||
|
.finally(() => {
|
||||||
|
this.confirmingClose = false; // reset flag when confirmation modal is gone
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue