From 42c658178edaac46345b28086afc8443cb969024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=A4=9A=E7=9B=8A?= Date: Thu, 3 Mar 2022 18:57:35 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E5=A4=8D=20DropDownButton=20?= =?UTF-8?q?=E5=9C=A8=20hover=20=E7=8A=B6=E6=80=81=E4=B8=8B=E4=B8=8D?= =?UTF-8?q?=E5=A5=BD=E7=82=B9=E5=87=BB=E6=8C=89=E9=92=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#3690)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/components/Example.jsx | 2 +- src/renderers/DropDownButton.tsx | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/components/Example.jsx b/examples/components/Example.jsx index 2573c1b26..b141e29ac 100644 --- a/examples/components/Example.jsx +++ b/examples/components/Example.jsx @@ -696,7 +696,7 @@ export const examples = [ { label: 'APP 多页应用', icon: 'fa fa-cubes', - path: '/app/', + path: '/examples/app/', component: () => { // 如果在 gh-pages 里面 if (/^\/amis/.test(window.location.pathname)) { diff --git a/src/renderers/DropDownButton.tsx b/src/renderers/DropDownButton.tsx index 48aae5e79..32b000c03 100644 --- a/src/renderers/DropDownButton.tsx +++ b/src/renderers/DropDownButton.tsx @@ -147,12 +147,14 @@ export default class DropDownButton extends React.Component< }; target: any; + timer: ReturnType; constructor(props: DropDownButtonProps) { super(props); this.open = this.open.bind(this); this.close = this.close.bind(this); this.toogle = this.toogle.bind(this); + this.keepOpen = this.keepOpen.bind(this); this.domRef = this.domRef.bind(this); } @@ -183,9 +185,17 @@ export default class DropDownButton extends React.Component< } close() { - this.setState({ - isOpened: false - }); + this.timer = setTimeout(() => { + this.setState({ + isOpened: false + }); + }, 200); + } + + keepOpen() { + if (this.timer) { + clearTimeout(this.timer); + } } renderButton( @@ -260,6 +270,7 @@ export default class DropDownButton extends React.Component< menuClassName )} onClick={closeOnClick ? this.close : noop} + onMouseEnter={this.keepOpen} ref={ref} > {children