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

Fix sidebar scroll restoration issue #2569

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default defineConfig({
trailingSlash: 'always',
integrations: [
starlight({
// TODO(HiDeoo) Remove
components: { Sidebar: './src/components/Sidebar.astro' },
title: 'Starlight',
logo: {
light: '/src/assets/logo-light.svg',
Expand Down
45 changes: 45 additions & 0 deletions docs/src/components/Sidebar.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
// TODO(HiDeoo) Remove this entire file
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/Sidebar.astro';
---

<Default {...Astro.props}><slot /></Default>

<div class="sl-hidden md:sl-block">
<div dir="ltr" lang="en" class="sponsors">
<h2 class="sponsors-title">Sponsored by</h2>
<a href="https://starlight.astro.build/" aria-label="Starlight"></a>
<a href="https://starlight.astro.build/" aria-label="Starlight"></a>
</div>
</div>

<style>
.sponsors {
display: flex;
flex-wrap: wrap;
gap: 0 1.5rem;
padding: 1.5rem 0.5rem 0.75rem;
}
a {
display: flex;
align-items: center;
min-height: 3rem;
opacity: 0.75;
background-color: red;
width: 96px;
}
a:hover {
opacity: 1;
}

.sponsors-title {
width: 100%;
color: var(--sl-color-gray-3);
font-size: var(--sl-text-xs);
font-weight: 400;
font-family: var(--__sl-font-mono);
line-height: var(--sl-line-height-headings);
margin: 0 0 0.5rem;
}
</style>
16 changes: 15 additions & 1 deletion packages/starlight/components/Page.astro
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ const pagefindEnabled =
<SkipLink {...Astro.props} />
<PageFrame {...Astro.props}>
<Header slot="header" {...Astro.props} />
{Astro.props.hasSidebar && <Sidebar slot="sidebar" {...Astro.props} />}
{
Astro.props.hasSidebar && (
<Fragment slot="sidebar">
<Sidebar {...Astro.props} />
<script is:inline>
(() => {
const scroller = document.getElementById('starlight__sidebar');
if (!window._starlightScrollRestore || !scroller) return;
scroller.scrollTop = window._starlightScrollRestore;
delete window._starlightScrollRestore;
})();
</script>
</Fragment>
)
}
<script src="./SidebarPersistState"></script>
<TwoColumnContent {...Astro.props}>
<PageSidebar slot="right-sidebar" {...Astro.props} />
Expand Down
9 changes: 0 additions & 9 deletions packages/starlight/components/SidebarPersister.astro
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ declare global {
</script>

<slot />

<script is:inline>
(() => {
const scroller = document.getElementById('starlight__sidebar');
if (!window._starlightScrollRestore || !scroller) return;
scroller.scrollTop = window._starlightScrollRestore;
delete window._starlightScrollRestore;
})();
</script>
</sl-sidebar-state-persist>

<style>
Expand Down
Loading