From c1353402ba584b1ccb6a22f5f52dff66180ddf03 Mon Sep 17 00:00:00 2001 From: heiyexing Date: Tue, 21 Nov 2023 21:20:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20LayerPopup=20trigge?= =?UTF-8?q?r=20&=20items=20=E5=AF=BC=E8=87=B4=E7=9A=84=20Bug=20(#2075)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复 LayerPopup trigger 切换时的问题 * fix: 修复 layerPopup items 为空的问题 --- dev-demos/component/popup/layerPopup.tsx | 23 ++++++++++++++++++++++ packages/component/src/popup/layerPopup.ts | 16 +++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/dev-demos/component/popup/layerPopup.tsx b/dev-demos/component/popup/layerPopup.tsx index ecadcb452a..2910311722 100644 --- a/dev-demos/component/popup/layerPopup.tsx +++ b/dev-demos/component/popup/layerPopup.tsx @@ -144,6 +144,29 @@ const Demo: FunctionComponent = () => { return ( <> +
+ + + +
{ public setOptions(option: Partial) { this.unbindLayerEvent(); const newOption = { ...option }; - const trigger = option.trigger || this.popupOption.trigger; - if (newOption.items?.length === 0 && trigger === 'hover') { - newOption.followCursor = false; - } + const trigger = newOption.trigger || this.popupOption.trigger; + const items = newOption.items || this.popupOption.items; + const isEmptyItems = items?.length === 0; + newOption.followCursor = trigger === 'hover' && !isEmptyItems; + super.setOptions(newOption); this.bindLayerEvent(); + if (isEmptyItems) { + this.hide(); + } return this; } protected getDefault(option: Partial): ILayerPopupOption { - const isClickTrigger = option.trigger === 'click'; + const isHoverTrigger = option.trigger === 'hover'; return { ...super.getDefault(option), trigger: 'hover', - followCursor: !isClickTrigger, + followCursor: isHoverTrigger, lngLat: { lng: 0, lat: 0,