From b69bf19da8d5990e4dc7c61dd484950927448ad0 Mon Sep 17 00:00:00 2001 From: LonHon Date: Mon, 17 Oct 2022 17:42:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Panel=E8=AE=BE=E7=BD=AE=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E4=BB=A5=E6=98=BE=E7=A4=BAselected=20item=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20=E9=80=89=E9=A1=B9=E8=BF=87=E5=A4=9A=E6=97=B6?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E5=AE=9A=E4=BD=8D=E9=9C=80=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E9=95=BF=E6=97=B6=E9=97=B4=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/menus/panel-and-modal/BaseClass.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/core/src/menus/panel-and-modal/BaseClass.ts b/packages/core/src/menus/panel-and-modal/BaseClass.ts index 72327ee7b..7d8faa14f 100644 --- a/packages/core/src/menus/panel-and-modal/BaseClass.ts +++ b/packages/core/src/menus/panel-and-modal/BaseClass.ts @@ -53,6 +53,17 @@ abstract class PanelAndModal { $menuElem.append($elem) } + // 尝试滚动到选中选项位置 + scrollToSelectedItem() { + try { + const { $elem } = this + const target = $elem.find('li.selected')[0] as HTMLElement + $elem[0].scrollTo(0, target.offsetTop) + } catch { + console.info('skip scrollToSelectedItem') + } + } + show() { if (this.isShow) return this.showTime = Date.now() @@ -60,6 +71,7 @@ abstract class PanelAndModal { const { $elem } = this $elem.show() this.isShow = true + this.scrollToSelectedItem() // 触发事件 const editor = PANEL_OR_MODAL_TO_EDITOR.get(this)