Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/strange-icons-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes a VoiceOver issue with Safari where the content of a `<script>` element could be read before the sidebar content.
9 changes: 7 additions & 2 deletions packages/starlight/components/SidebarPersister.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
- On smaller viewports, restoring state is skipped as the sidebar is collapsed inside a menu.
- The state is parsed from session storage and restored.
- This is a progressive enhancement, so any errors are swallowed silently.

The `aria-hidden` attribute on script tags is used to prevent a Safari/VoiceOver bug where the
script is read out loud due to them being inside a container with `display: contents`.
@see https://bugs.webkit.org/show_bug.cgi?id=283645
@see https://github.com/withastro/starlight/pull/2633
*/

import type { Props } from '../props';
Expand All @@ -28,7 +33,7 @@ declare global {
---

<sl-sidebar-state-persist data-hash={hash}>
<script is:inline>
<script is:inline aria-hidden="true">
(() => {
try {
if (!matchMedia('(min-width: 50em)').matches) return;
Expand All @@ -55,7 +60,7 @@ declare global {

<slot />

<script is:inline>
<script is:inline aria-hidden="true">
(() => {
const scroller = document.getElementById('starlight__sidebar');
if (!window._starlightScrollRestore || !scroller) return;
Expand Down