-
-
-
@@ -107,6 +121,10 @@
type: Boolean,
default: true
},
+ closeOnEsc: {
+ type: Boolean,
+ default: true
+ },
hideHeader: {
type: Boolean,
default: false
@@ -114,6 +132,10 @@
hideFooter: {
type: Boolean,
default: false
+ },
+ hideHeaderClose: {
+ type: Boolean,
+ default: false
}
},
methods: {
@@ -162,17 +184,22 @@
this.hide();
}
},
- pressedButton(e) {
- // If not visible don't do anything
- if (!this.visible) {
- return;
- }
-
- // Support for esc key press
- const key = e.which || e.keyCode;
- if (key === 27) { // 27 is esc
+ onEsc() {
+ // If ESC presses, hide modal
+ if (this.visible && this.closeOnEsc) {
this.hide();
}
+ },
+ enforceFocus(e) {
+ // If focus leaves modal, bring it back
+ // eventListener bound on document
+ if (this.visible &&
+ document !== e.target &&
+ this.$refs.content &&
+ this.$refs.content !== e.target &&
+ !this.$refs.content.contains(e.target)) {
+ this.$refs.content.focus();
+ }
}
},
created() {
@@ -190,12 +217,12 @@
},
mounted() {
if (typeof document !== 'undefined') {
- document.addEventListener('keydown', this.pressedButton);
+ document.addEventListener('focus', this.enforceFocus);
}
},
destroyed() {
if (typeof document !== 'undefined') {
- document.removeEventListener('keydown', this.pressedButton);
+ document.removeEventListener('focus', this.enforceFocus);
}
}
};