Skip to content

Commit

Permalink
fix: drawer esc keydown vueComponent#3148
Browse files Browse the repository at this point in the history
  • Loading branch information
zkwolf committed Mar 11, 2021
1 parent dced59c commit 4bc384d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 14 additions & 3 deletions components/drawer/index.jsx
Expand Up @@ -80,6 +80,11 @@ const Drawer = {
}
},
methods: {
domFocus() {
if (this.$refs.vcDrawer) {
this.$refs.vcDrawer.domFocus();
}
},
close(e) {
this.$emit('close', e);
},
Expand All @@ -95,9 +100,14 @@ const Drawer = {
});
},
pull() {
this.setState({
_push: false,
});
this.setState(
{
_push: false,
},
() => {
this.domFocus();
},
);
},
onDestroyTransitionEnd() {
const isDestroyOnClose = this.getDestroyOnClose();
Expand Down Expand Up @@ -211,6 +221,7 @@ const Drawer = {
const prefixCls = getPrefixCls('drawer', customizePrefixCls);

const vcDrawerProps = {
ref: 'vcDrawer',
props: {
...omit(rest, [
'closable',
Expand Down
13 changes: 13 additions & 0 deletions components/vc-drawer/src/Drawer.js
Expand Up @@ -85,6 +85,9 @@ const Drawer = {
this.getDefault(this.$props);
if (open) {
this.isOpenChange = true;
this.$nextTick(() => {
this.domFocus();
});
}
this.$forceUpdate();
}
Expand All @@ -103,6 +106,11 @@ const Drawer = {
});
}
this.preProps.open = val;
if (val) {
this.$nextTick(() => {
this.domFocus();
});
}
},
placement(val) {
if (val !== this.preProps.placement) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4bc384d

Please sign in to comment.