Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Panel打开时滚动定位到当前已选项 #4964

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/core/src/menus/panel-and-modal/BaseClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,25 @@ 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()

const { $elem } = this
$elem.show()
this.isShow = true
this.scrollToSelectedItem()

// 触发事件
const editor = PANEL_OR_MODAL_TO_EDITOR.get(this)
Expand Down