fix: drawer esc keydown #3148 (#3790)

pull/3939/head
zkwolf 2021-03-12 14:51:06 +08:00 committed by GitHub
parent dced59c65c
commit dfcdf92f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -80,6 +80,11 @@ const Drawer = {
}
},
methods: {
domFocus() {
if (this.$refs.vcDrawer) {
this.$refs.vcDrawer.domFocus();
}
},
close(e) {
this.$emit('close', e);
},
@ -95,9 +100,14 @@ const Drawer = {
});
},
pull() {
this.setState({
_push: false,
});
this.setState(
{
_push: false,
},
() => {
this.domFocus();
},
);
},
onDestroyTransitionEnd() {
const isDestroyOnClose = this.getDestroyOnClose();
@ -211,6 +221,7 @@ const Drawer = {
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
const vcDrawerProps = {
ref: 'vcDrawer',
props: {
...omit(rest, [
'closable',

View File

@ -85,6 +85,9 @@ const Drawer = {
this.getDefault(this.$props);
if (open) {
this.isOpenChange = true;
this.$nextTick(() => {
this.domFocus();
});
}
this.$forceUpdate();
}
@ -103,6 +106,11 @@ const Drawer = {
});
}
this.preProps.open = val;
if (val) {
this.$nextTick(() => {
this.domFocus();
});
}
},
placement(val) {
if (val !== this.preProps.placement) {
@ -140,6 +148,11 @@ const Drawer = {
clearTimeout(this.timeout);
},
methods: {
domFocus() {
if (this.dom) {
this.dom.focus();
}
},
onKeyDown(e) {
if (e.keyCode === KeyCode.ESC) {
e.stopPropagation();