From dfcdf92f7a6a002ffdba274ade408084be610256 Mon Sep 17 00:00:00 2001 From: zkwolf Date: Fri, 12 Mar 2021 14:51:06 +0800 Subject: [PATCH] fix: drawer esc keydown #3148 (#3790) --- components/drawer/index.jsx | 17 ++++++++++++++--- components/vc-drawer/src/Drawer.js | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/components/drawer/index.jsx b/components/drawer/index.jsx index 9049ded1fb..9177a184b6 100644 --- a/components/drawer/index.jsx +++ b/components/drawer/index.jsx @@ -80,6 +80,11 @@ const Drawer = { } }, methods: { + domFocus() { + if (this.$refs.vcDrawer) { + this.$refs.vcDrawer.domFocus(); + } + }, close(e) { this.$emit('close', e); }, @@ -95,9 +100,14 @@ const Drawer = { }); }, pull() { - this.setState({ - _push: false, - }); + this.setState( + { + _push: false, + }, + () => { + this.domFocus(); + }, + ); }, onDestroyTransitionEnd() { const isDestroyOnClose = this.getDestroyOnClose(); @@ -211,6 +221,7 @@ const Drawer = { const prefixCls = getPrefixCls('drawer', customizePrefixCls); const vcDrawerProps = { + ref: 'vcDrawer', props: { ...omit(rest, [ 'closable', diff --git a/components/vc-drawer/src/Drawer.js b/components/vc-drawer/src/Drawer.js index 1a54d7ac78..51f95b7a6d 100644 --- a/components/vc-drawer/src/Drawer.js +++ b/components/vc-drawer/src/Drawer.js @@ -85,6 +85,9 @@ const Drawer = { this.getDefault(this.$props); if (open) { this.isOpenChange = true; + this.$nextTick(() => { + this.domFocus(); + }); } this.$forceUpdate(); } @@ -103,6 +106,11 @@ const Drawer = { }); } this.preProps.open = val; + if (val) { + this.$nextTick(() => { + this.domFocus(); + }); + } }, placement(val) { if (val !== this.preProps.placement) { @@ -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();