fix: drawer esc keydown #3148

pull/3150/head
tanjinzhou 2020-11-10 15:13:31 +08:00
parent 8096003ed1
commit 7cd86b5a00
3 changed files with 28 additions and 4 deletions

View File

@ -85,6 +85,11 @@ const Drawer = defineComponent({
} }
}, },
methods: { methods: {
domFocus() {
if (this.$refs.vcDrawer) {
(this.$refs.vcDrawer as any).domFocus();
}
},
close(e: Event) { close(e: Event) {
this.$emit('update:visible', false); this.$emit('update:visible', false);
this.$emit('close', e); this.$emit('close', e);
@ -101,9 +106,14 @@ const Drawer = defineComponent({
}); });
}, },
pull() { pull() {
this.setState({ this.setState(
sPush: false, {
}); sPush: false,
},
() => {
this.domFocus();
},
);
}, },
onDestroyTransitionEnd() { onDestroyTransitionEnd() {
const isDestroyOnClose = this.getDestroyOnClose(); const isDestroyOnClose = this.getDestroyOnClose();
@ -248,6 +258,7 @@ const Drawer = defineComponent({
[haveMask]: !!haveMask, [haveMask]: !!haveMask,
}), }),
wrapStyle: this.getRcDrawerStyle(), wrapStyle: this.getRcDrawerStyle(),
ref: 'vcDrawer',
}; };
return <VcDrawer {...vcDrawerProps}>{this.renderBody(prefixCls)}</VcDrawer>; return <VcDrawer {...vcDrawerProps}>{this.renderBody(prefixCls)}</VcDrawer>;
}, },

View File

@ -31,7 +31,7 @@ export default defineComponent({
render() { render() {
const { $slots, $attrs } = this; const { $slots, $attrs } = this;
const { rootPrefixCls, popupClassName } = {...this.$props, ...this.injectExtraProps} as any; const { rootPrefixCls, popupClassName } = { ...this.$props, ...this.injectExtraProps } as any;
const { theme: antdMenuTheme } = this.menuPropsContext; const { theme: antdMenuTheme } = this.menuPropsContext;
const props = { const props = {
...this.$props, ...this.$props,

View File

@ -77,6 +77,11 @@ const Drawer = defineComponent({
}); });
} }
this.preProps.open = val; this.preProps.open = val;
if (val) {
nextTick(() => {
this.domFocus();
});
}
}, },
placement(val) { placement(val) {
if (val !== this.preProps.placement) { if (val !== this.preProps.placement) {
@ -113,6 +118,9 @@ const Drawer = defineComponent({
this.getDefault(this.$props); this.getDefault(this.$props);
if (open) { if (open) {
this.isOpenChange = true; this.isOpenChange = true;
nextTick(() => {
this.domFocus();
});
} }
this.$forceUpdate(); this.$forceUpdate();
} }
@ -140,6 +148,11 @@ const Drawer = defineComponent({
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();