Scroll to the selected component inside the app preview

This commit is contained in:
Andrew Kingston 2022-05-17 14:10:21 +01:00
parent ea38e5661e
commit ff47e8acd3
1 changed files with 16 additions and 0 deletions

View File

@ -136,6 +136,9 @@
// Determine and apply settings to the component // Determine and apply settings to the component
$: applySettings(staticSettings, enrichedSettings, conditionalSettings) $: applySettings(staticSettings, enrichedSettings, conditionalSettings)
// Scroll the selected element into view
$: selected && scrollIntoView()
// Update component context // Update component context
$: store.set({ $: store.set({
id, id,
@ -374,6 +377,19 @@
} }
} }
const scrollIntoView = () => {
const node = document.getElementsByClassName(id)?.[0]?.childNodes[0]
if (!node) {
return
}
node.style.scrollMargin = "80px"
node.scrollIntoView({
behavior: "smooth",
block: "start",
inline: "start",
})
}
onMount(() => { onMount(() => {
if ( if (
$appStore.isDevApp && $appStore.isDevApp &&