Skip to content

Commit

Permalink
Fix Safari VoiceOver issue (#2633)
Browse files Browse the repository at this point in the history
* fix: safari voiceover issue

* chore: add comment + bug report + pr links

* chore: fix comment indentation
  • Loading branch information
HiDeoo authored Nov 25, 2024
1 parent 866661b commit 5adb720
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit 5adb720

Please sign in to comment.