From 3f0272393986d0a22e1508d080ff91fdb73b3dbe Mon Sep 17 00:00:00 2001 From: Sean Lynch Date: Thu, 20 Jun 2024 23:52:58 -0400 Subject: [PATCH] [AppLayout] Fix scrolling to #fragment on page load by making body scrollable instead of
. Remove `overlapHeader` prop (always overlap). (#404) --- .changeset/nine-owls-tell.md | 5 ++ .../src/lib/components/AppLayout.svelte | 60 +++++++------------ packages/svelte-ux/src/routes/+layout.svelte | 13 ++-- .../src/routes/changelog/+page.svelte | 2 +- .../src/routes/customization/+layout.svelte | 2 +- .../svelte-ux/src/routes/docs/+layout.svelte | 6 +- 6 files changed, 38 insertions(+), 50 deletions(-) create mode 100644 .changeset/nine-owls-tell.md diff --git a/.changeset/nine-owls-tell.md b/.changeset/nine-owls-tell.md new file mode 100644 index 000000000..5890ec8ed --- /dev/null +++ b/.changeset/nine-owls-tell.md @@ -0,0 +1,5 @@ +--- +'svelte-ux': minor +--- + +[AppLayout] Fix scrolling to #fragment on page load by making body scrollable instead of
. Remove `overlapHeader` prop (always overlap). diff --git a/packages/svelte-ux/src/lib/components/AppLayout.svelte b/packages/svelte-ux/src/lib/components/AppLayout.svelte index cb2eca86b..711821d40 100644 --- a/packages/svelte-ux/src/lib/components/AppLayout.svelte +++ b/packages/svelte-ux/src/lib/components/AppLayout.svelte @@ -10,24 +10,17 @@ export let navWidth = 240; export let headerHeight = 64; - /** Control whether nav should be full height (default) or header should be full width */ + /** Control whether header should be full width (deafult) or nav should be full height */ export let headerPosition: 'full' | 'inset' = 'full'; - /** Overlap `main` under header using negative top margin with positive top padding to support background blur */ - export let overlapHeader = false; - - $: areas = - headerPosition === 'full' ? "'header header' 'aside main'" : "'aside header' 'aside main'"; - export let classes: { root?: string; aside?: string; nav?: string; } = {}; - const settingsClasses = getComponentClasses('AppLayout'); + const settingsClasses = getComponentClasses('AppLayout'); const { showDrawer } = getSettings(); - $: temporaryDrawer = browser ? !$mdScreen : false; @@ -35,15 +28,19 @@ style:--headerHeight="{headerHeight}px" style:--drawerWidth="{$showDrawer ? navWidth : 0}px" style:--navWidth="{navWidth}px" - style:--areas={areas} class={cls( 'AppLayout', - 'grid grid-cols-[auto,1fr] grid-rows-[var(--headerHeight),1fr] h-screen', + '[&>header]:fixed [&>header]:top-0 [&>header]:h-[var(--headerHeight)] [&>header]:transition-all', + headerPosition === 'full' || temporaryDrawer + ? '[&>header]:w-full' + : '[&>header]:w-[calc(100%-var(--drawerWidth))] [&>header]:left-[var(--drawerWidth)] [&>header]:duration-500', + '[&>main]:md:pl-[var(--drawerWidth)] [&>main]:pt-[var(--headerHeight)] [&>main]:transition-[padding] [&>main]:duration-500', + /* Fix scrolling offset for headings (h1, ...) or other elements with an id set (``) */ + '[:where(&_[id])]:scroll-m-[var(--headerHeight)]', settingsClasses.root, classes.root, $$props.class )} - class:overlapHeader > @@ -54,41 +51,24 @@ - - diff --git a/packages/svelte-ux/src/routes/+layout.svelte b/packages/svelte-ux/src/routes/+layout.svelte index 4ab455247..18e59fc4b 100644 --- a/packages/svelte-ux/src/routes/+layout.svelte +++ b/packages/svelte-ux/src/routes/+layout.svelte @@ -297,14 +297,14 @@ -
+