Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: drawer esc keydown #3790

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions components/drawer/index.jsx
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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