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

View File

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