|
@@ -4,8 +4,8 @@
|
|
|
@after-enter="afterEnter"
|
|
|
@after-leave="afterLeave">
|
|
|
<div
|
|
|
- class="el-dialog__wrapper"
|
|
|
- role="presentation"
|
|
|
+ class="el-drawer__wrapper"
|
|
|
+ tabindex="-1"
|
|
|
v-show="visible">
|
|
|
<div
|
|
|
class="el-drawer__container"
|
|
@@ -16,14 +16,17 @@
|
|
|
<div
|
|
|
aria-modal="true"
|
|
|
aria-labelledby="el-drawer__title"
|
|
|
+ :aria-label="title"
|
|
|
class="el-drawer"
|
|
|
:class="[direction, customClass]"
|
|
|
:style="isHorizontal ? `width: ${size}` : `height: ${size}`"
|
|
|
ref="drawer"
|
|
|
- role="presentation">
|
|
|
- <header class="el-drawer__header" id="el-drawer__title">
|
|
|
+ role="dialog"
|
|
|
+ tabindex="-1"
|
|
|
+ >
|
|
|
+ <header class="el-drawer__header" id="el-drawer__title" v-if="withHeader">
|
|
|
<slot name="title">
|
|
|
- <span role="heading">{{ title }}</span>
|
|
|
+ <span role="heading" tabindex="0" :title="title">{{ title }}</span>
|
|
|
</slot>
|
|
|
<button
|
|
|
:aria-label="`close ${title || 'drawer'}`"
|
|
@@ -45,16 +48,16 @@
|
|
|
|
|
|
<script>
|
|
|
import Popup from 'element-ui/src/utils/popup';
|
|
|
-import Migrating from 'element-ui/src/mixins/migrating';
|
|
|
import emitter from 'element-ui/src/mixins/emitter';
|
|
|
+import Utils from 'element-ui/src/utils/aria-utils';
|
|
|
|
|
|
export default {
|
|
|
name: 'ElDrawer',
|
|
|
- mixins: [Popup, emitter, Migrating],
|
|
|
+ mixins: [Popup, emitter],
|
|
|
props: {
|
|
|
appendToBody: {
|
|
|
type: Boolean,
|
|
|
- default: true
|
|
|
+ default: false
|
|
|
},
|
|
|
beforeClose: {
|
|
|
type: Function
|
|
@@ -63,6 +66,10 @@ export default {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
+ closeOnPressEscape: {
|
|
|
+ type: Boolean,
|
|
|
+ default: true
|
|
|
+ },
|
|
|
destroyOnClose: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
@@ -78,6 +85,10 @@ export default {
|
|
|
return ['ltr', 'rtl', 'ttb', 'btt'].indexOf(val) !== -1;
|
|
|
}
|
|
|
},
|
|
|
+ modalAppendToBody: {
|
|
|
+ type: Boolean,
|
|
|
+ default: true
|
|
|
+ },
|
|
|
showClose: {
|
|
|
type: Boolean,
|
|
|
default: true
|
|
@@ -96,6 +107,10 @@ export default {
|
|
|
wrapperClosable: {
|
|
|
type: Boolean,
|
|
|
default: true
|
|
|
+ },
|
|
|
+ withHeader: {
|
|
|
+ type: Boolean,
|
|
|
+ default: true
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -105,7 +120,8 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- closed: false
|
|
|
+ closed: false,
|
|
|
+ prevActiveElement: null
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
@@ -116,8 +132,17 @@ export default {
|
|
|
if (this.appendToBody) {
|
|
|
document.body.appendChild(this.$el);
|
|
|
}
|
|
|
+ this.prevActiveElement = document.activeElement;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ Utils.focusFirstDescendant(this.$refs.drawer);
|
|
|
+ });
|
|
|
} else {
|
|
|
if (!this.closed) this.$emit('close');
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.prevActiveElement) {
|
|
|
+ this.prevActiveElement.focus();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -149,6 +174,12 @@ export default {
|
|
|
} else {
|
|
|
this.hide();
|
|
|
}
|
|
|
+ },
|
|
|
+ handleClose() {
|
|
|
+ // This method here will be called by PopupManger, when the `closeOnPressEscape` was set to true
|
|
|
+ // pressing `ESC` will call this method, and also close the drawer.
|
|
|
+ // This method also calls `beforeClose` if there was one.
|
|
|
+ this.closeDrawer();
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|