Skip to content

Commit dfcdf92

Browse files
authored
fix: drawer esc keydown #3148 (#3790)
1 parent dced59c commit dfcdf92

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

components/drawer/index.jsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ const Drawer = {
8080
}
8181
},
8282
methods: {
83+
domFocus() {
84+
if (this.$refs.vcDrawer) {
85+
this.$refs.vcDrawer.domFocus();
86+
}
87+
},
8388
close(e) {
8489
this.$emit('close', e);
8590
},
@@ -95,9 +100,14 @@ const Drawer = {
95100
});
96101
},
97102
pull() {
98-
this.setState({
99-
_push: false,
100-
});
103+
this.setState(
104+
{
105+
_push: false,
106+
},
107+
() => {
108+
this.domFocus();
109+
},
110+
);
101111
},
102112
onDestroyTransitionEnd() {
103113
const isDestroyOnClose = this.getDestroyOnClose();
@@ -211,6 +221,7 @@ const Drawer = {
211221
const prefixCls = getPrefixCls('drawer', customizePrefixCls);
212222

213223
const vcDrawerProps = {
224+
ref: 'vcDrawer',
214225
props: {
215226
...omit(rest, [
216227
'closable',

components/vc-drawer/src/Drawer.js

+13
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ const Drawer = {
8585
this.getDefault(this.$props);
8686
if (open) {
8787
this.isOpenChange = true;
88+
this.$nextTick(() => {
89+
this.domFocus();
90+
});
8891
}
8992
this.$forceUpdate();
9093
}
@@ -103,6 +106,11 @@ const Drawer = {
103106
});
104107
}
105108
this.preProps.open = val;
109+
if (val) {
110+
this.$nextTick(() => {
111+
this.domFocus();
112+
});
113+
}
106114
},
107115
placement(val) {
108116
if (val !== this.preProps.placement) {
@@ -140,6 +148,11 @@ const Drawer = {
140148
clearTimeout(this.timeout);
141149
},
142150
methods: {
151+
domFocus() {
152+
if (this.dom) {
153+
this.dom.focus();
154+
}
155+
},
143156
onKeyDown(e) {
144157
if (e.keyCode === KeyCode.ESC) {
145158
e.stopPropagation();

0 commit comments

Comments
 (0)