Skip to content

Commit abcf352

Browse files
committed
fix(components): scrollIntoView might not be available
1 parent 1b29e99 commit abcf352

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

packages/app-backend-core/src/index.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,31 @@ function connectBridge () {
357357
if (instance) {
358358
const [el] = await ctx.api.getComponentRootElements(instance)
359359
if (el) {
360-
el.scrollIntoView({
361-
behavior: 'smooth',
362-
block: 'center',
363-
inline: 'center'
364-
})
360+
if (typeof el.scrollIntoView === 'function') {
361+
el.scrollIntoView({
362+
behavior: 'smooth',
363+
block: 'center',
364+
inline: 'center'
365+
})
366+
} else {
367+
// Handle nodes that don't implement scrollIntoView
368+
const bounds = await ctx.api.getComponentBounds(instance)
369+
const scrollTarget = document.createElement('div')
370+
scrollTarget.style.position = 'absolute'
371+
scrollTarget.style.width = `${bounds.width}px`
372+
scrollTarget.style.height = `${bounds.height}px`
373+
scrollTarget.style.top = `${bounds.top}px`
374+
scrollTarget.style.left = `${bounds.left}px`
375+
document.body.appendChild(scrollTarget)
376+
scrollTarget.scrollIntoView({
377+
behavior: 'smooth',
378+
block: 'center',
379+
inline: 'center'
380+
})
381+
setTimeout(() => {
382+
document.body.removeChild(scrollTarget)
383+
}, 2000)
384+
}
365385
highlight(instance, ctx)
366386
setTimeout(() => {
367387
unHighlight()

0 commit comments

Comments
 (0)