Stop preview jumping when scrolling to components, and improve scrolling behaviour

This commit is contained in:
Andrew Kingston 2023-08-22 18:55:36 +01:00
parent d0414812cf
commit a83e987dcd
2 changed files with 9 additions and 7 deletions

View File

@ -475,7 +475,7 @@
node.style.scrollMargin = "100px"
node.scrollIntoView({
behavior: "smooth",
block: "start",
block: "nearest",
inline: "start",
})
}

View File

@ -73,18 +73,20 @@
)
$: autoCloseSidePanel = !$builderStore.inBuilder && $sidePanelStore.open
// Scroll navigation into view if selected
$: {
if (
// Scroll navigation into view if selected.
// Memoize into a primitive to avoid spamming this whenever builder store
// changes.
$: selected =
$builderStore.inBuilder &&
$builderStore.selectedComponentId === "navigation"
) {
$: {
if (selected) {
const node = document.getElementsByClassName("nav-wrapper")?.[0]
if (node) {
node.style.scrollMargin = "100px"
node.scrollIntoView({
behavior: "smooth",
block: "start",
block: "nearest",
inline: "start",
})
}