From cfa99abde64bd98062c90fd68b69386989f31e32 Mon Sep 17 00:00:00 2001 From: rickcole Date: Fri, 8 May 2020 20:05:36 +0800 Subject: [PATCH] =?UTF-8?q?drawer=20overlay=E9=80=BB=E8=BE=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scss/components/_drawer.scss | 2 ++ src/components/Drawer.tsx | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scss/components/_drawer.scss b/scss/components/_drawer.scss index 6898605d..6568436a 100644 --- a/scss/components/_drawer.scss +++ b/scss/components/_drawer.scss @@ -115,6 +115,8 @@ } &.#{$ns}Drawer--noOverlay { + pointer-events: none; + .#{$ns}Drawer-close svg { margin-top: px2rem(2px); width: px2rem(20px); diff --git a/src/components/Drawer.tsx b/src/components/Drawer.tsx index 4ed21777..22154f66 100644 --- a/src/components/Drawer.tsx +++ b/src/components/Drawer.tsx @@ -69,12 +69,14 @@ export class Drawer extends React.Component { if (this.props.show) { this.handleEntered(); } + document.body.addEventListener('click', this.handleRootClick, true); } componentWillUnmount() { if (this.props.show) { this.handleExited(); } + document.body.removeEventListener('click', this.handleRootClick, true); } contentRef = (ref: any) => (this.contentDom = ref); @@ -105,7 +107,7 @@ export class Drawer extends React.Component { }; @autobind - handleWidgetClick(e: React.MouseEvent) { + handleRootClick(e: MouseEvent) { const {classPrefix: ns, closeOnOutside, onHide} = this.props; if ((e.target as HTMLElement).closest(`.${ns}Drawer-content`)) { return; @@ -159,7 +161,7 @@ export class Drawer extends React.Component { }, className )} - onClick={this.handleWidgetClick} // 其实不需要插件,直接写逻辑吧 + // onClick={this.handleWidgetClick} // 其实不需要插件,直接写逻辑吧 > {overlay ? (