Merge pull request #444 from lochstar/dialog-close

Added 'dismissableMask' and 'closeOnEscape' props to Dialog
pull/457/head
Cagatay Civici 2020-08-27 14:36:08 +03:00 committed by GitHub
commit ce5df49e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -8,6 +8,8 @@ export declare class Dialog extends Vue {
contentStyle?: string; contentStyle?: string;
rtl?: boolean; rtl?: boolean;
closable?: boolean; closable?: boolean;
dismissableMask?: boolean;
closeOnEscape?: boolean;
showHeader?: boolean; showHeader?: boolean;
baseZIndex?: number; baseZIndex?: number;
autoZIndex?: boolean; autoZIndex?: boolean;

View File

@ -1,7 +1,7 @@
<template> <template>
<div ref="mask" :class="maskClass" v-if="maskVisible"> <div ref="mask" :class="maskClass" v-if="maskVisible" @click="onMaskClick">
<transition name="p-dialog" @before-enter="onBeforeEnter" @enter="onEnter" @before-leave="onBeforeLeave" @leave="onLeave" @after-leave="onAfterLeave" @appear="onAppear"> <transition name="p-dialog" @before-enter="onBeforeEnter" @enter="onEnter" @before-leave="onBeforeLeave" @leave="onLeave" @after-leave="onAfterLeave" @appear="onAppear">
<div ref="dialog" :class="dialogClass" :style="dialogStyle" v-if="visible" v-bind="$attrs" v-on="listeners" role="dialog" :aria-labelledby="ariaLabelledById" :aria-modal="modal"> <div ref="dialog" :class="dialogClass" :style="dialogStyle" v-if="visible" v-bind="$attrs" v-on="listeners" role="dialog" :aria-labelledby="ariaLabelledById" :aria-modal="modal" @click.stop>
<div class="p-dialog-header" v-if="showHeader"> <div class="p-dialog-header" v-if="showHeader">
<slot name="header"> <slot name="header">
<span :id="ariaLabelledById" class="p-dialog-title" v-if="header" >{{header}}</span> <span :id="ariaLabelledById" class="p-dialog-title" v-if="header" >{{header}}</span>
@ -40,10 +40,15 @@ export default {
contentStyle: null, contentStyle: null,
rtl: Boolean, rtl: Boolean,
maximizable: Boolean, maximizable: Boolean,
dismissableMask: Boolean,
closable: { closable: {
type: Boolean, type: Boolean,
default: true default: true
}, },
closeOnEscape: {
type: Boolean,
default: true
},
showHeader: { showHeader: {
type: Boolean, type: Boolean,
default: true default: true
@ -122,6 +127,11 @@ export default {
this.onEnter(); this.onEnter();
} }
}, },
onMaskClick() {
if (this.modal && this.closable && this.dismissableMask) {
this.close();
}
},
focus() { focus() {
let focusTarget = this.$refs.dialog.querySelector('[autofocus]'); let focusTarget = this.$refs.dialog.querySelector('[autofocus]');
if (focusTarget) { if (focusTarget) {
@ -180,6 +190,8 @@ export default {
} }
} }
} }
} else if (event.which === 27 && this.closeOnEscape) {
this.close();
} }
}, },
bindDocumentKeydownListener() { bindDocumentKeydownListener() {

View File

@ -112,6 +112,18 @@ export default {
<td>null</td> <td>null</td>
<td>Defines if background should be blocked when dialog is displayed.</td> <td>Defines if background should be blocked when dialog is displayed.</td>
</tr> </tr>
<tr>
<td>closeOnEscape</td>
<td>boolean</td>
<td>true</td>
<td>Specifices if pressing escape key should hide the dialog.</td>
</tr>
<tr>
<td>dismissableMask</td>
<td>boolean</td>
<td>false</td>
<td>Specifices if clicking the modal background should hide the dialog.</td>
</tr>
<tr> <tr>
<td>position</td> <td>position</td>
<td>string</td> <td>string</td>