Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 909d06b

Browse files
geoffrichPuruVJ
andauthored
fix: Various a11y fixes (#107)
* Various a11y fixes - remove non-li from ul - remove unnecessary `<label>` - use toggle button instead of switch for consistency * Changeset * Fix ToggleButton's alignment --------- Co-authored-by: Puru Vijay <[email protected]>
1 parent dc79aa5 commit 909d06b

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

.changeset/seven-flies-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/site-kit': patch
3+
---
4+
5+
Fix some ThemeToggle/Nav a11y issues

packages/site-kit/src/lib/components/Nav.svelte

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ Top navigation bar for the application. It provides a slot for the left side, th
7373
<Icon name={open ? 'close' : 'menu'} size="1em" />
7474
</button>
7575

76-
<ul>
76+
<ul class="menu-section">
7777
<slot name="nav-center" />
7878
</ul>
7979

80-
<ul class="external">
81-
<slot name="nav-right" />
82-
83-
<Separator />
84-
80+
<div class="external menu-section">
81+
<ul>
82+
<slot name="nav-right" />
83+
<Separator />
84+
</ul>
8585
<div class="appearance">
8686
<span class="caption">Theme</span>
8787
<ThemeToggle />
8888
</div>
89-
</ul>
89+
</div>
9090
</nav>
9191

9292
<style>
@@ -96,7 +96,7 @@ Top navigation bar for the application. It provides a slot for the left side, th
9696
height: 100%;
9797
top: 0;
9898
left: 0;
99-
background: var(--back);
99+
background: var(--sk-back-1);
100100
opacity: 0.8;
101101
z-index: 2;
102102
backdrop-filter: grayscale(0.5) blur(2px);
@@ -141,9 +141,12 @@ Top navigation bar for the application. It provides a slot for the left side, th
141141
}
142142
}
143143
144-
ul {
144+
.menu-section {
145145
position: relative;
146146
width: 100%;
147+
}
148+
149+
ul {
147150
padding: 0;
148151
margin: 0;
149152
list-style: none;
@@ -198,23 +201,23 @@ Top navigation bar for the application. It provides a slot for the left side, th
198201
}
199202
200203
@media (max-width: 799px) {
201-
ul {
204+
.menu-section {
202205
position: relative;
203206
display: none;
204207
width: 100%;
205-
background: var(--back);
208+
background: var(--sk-back-1);
206209
padding: 1rem var(--sk-page-padding-side);
207210
}
208211
209-
.open ul {
212+
.open .menu-section {
210213
display: block;
211214
}
212215
213-
ul.external {
216+
.external {
214217
padding: 1rem var(--sk-page-padding-side) 1rem;
215218
}
216219
217-
ul.external::before {
220+
.external::before {
218221
content: '';
219222
position: absolute;
220223
top: 0;
@@ -224,7 +227,7 @@ Top navigation bar for the application. It provides a slot for the left side, th
224227
background: radial-gradient(circle at center, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.05));
225228
}
226229
227-
ul.external::after {
230+
.external::after {
228231
content: '';
229232
position: absolute;
230233
width: 100%;
@@ -260,7 +263,8 @@ Top navigation bar for the application. It provides a slot for the left side, th
260263
/* justify-content: space-between; */
261264
}
262265
263-
ul {
266+
ul,
267+
.menu-section {
264268
display: flex;
265269
width: auto;
266270
height: 100%;
@@ -277,7 +281,7 @@ Top navigation bar for the application. It provides a slot for the left side, th
277281
height: 100%;
278282
}
279283
280-
ul.external {
284+
.external {
281285
padding: 0 var(--sk-page-padding-side) 0 0;
282286
justify-content: end;
283287
}

packages/site-kit/src/lib/components/ThemeToggle.svelte

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,24 @@
6565
onDestroy(() => query?.removeEventListener('change', cb));
6666
</script>
6767
68-
<label title="toggle dark mode">
69-
<button
70-
on:click={toggle}
71-
type="button"
72-
role="switch"
73-
aria-checked={$theme.current === 'dark' ? 'true' : false}
74-
>
75-
<span class="check" class:checked={$theme.current === 'dark'}>
76-
<span class="icon">
77-
{#if BROWSER}
78-
{#if $theme.current === 'dark'}
79-
{@html `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M12 21q-3.775 0-6.388-2.613T3 12q0-3.45 2.25-5.988T11 3.05q.625-.075.975.45t-.025 1.1q-.425.65-.638 1.375T11.1 7.5q0 2.25 1.575 3.825T16.5 12.9q.775 0 1.538-.225t1.362-.625q.525-.35 1.075-.037t.475.987q-.35 3.45-2.937 5.725T12 21Zm0-2q2.2 0 3.95-1.213t2.55-3.162q-.5.125-1 .2t-1 .075q-3.075 0-5.238-2.163T9.1 7.5q0-.5.075-1t.2-1q-1.95.8-3.163 2.55T5 12q0 2.9 2.05 4.95T12 19Zm-.25-6.75Z"/></svg>`}
80-
{:else}
81-
{@html `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M0 0h24v24H0z"/><path fill="currentColor" d="M12 19a1 1 0 0 1 .993.883L13 20v1a1 1 0 0 1-1.993.117L11 21v-1a1 1 0 0 1 1-1zm6.313-2.09l.094.083l.7.7a1 1 0 0 1-1.32 1.497l-.094-.083l-.7-.7a1 1 0 0 1 1.218-1.567l.102.07zm-11.306.083a1 1 0 0 1 .083 1.32l-.083.094l-.7.7a1 1 0 0 1-1.497-1.32l.083-.094l.7-.7a1 1 0 0 1 1.414 0zM4 11a1 1 0 0 1 .117 1.993L4 13H3a1 1 0 0 1-.117-1.993L3 11h1zm17 0a1 1 0 0 1 .117 1.993L21 13h-1a1 1 0 0 1-.117-1.993L20 11h1zM6.213 4.81l.094.083l.7.7a1 1 0 0 1-1.32 1.497l-.094-.083l-.7-.7A1 1 0 0 1 6.11 4.74l.102.07zm12.894.083a1 1 0 0 1 .083 1.32l-.083.094l-.7.7a1 1 0 0 1-1.497-1.32l.083-.094l.7-.7a1 1 0 0 1 1.414 0zM12 2a1 1 0 0 1 .993.883L13 3v1a1 1 0 0 1-1.993.117L11 4V3a1 1 0 0 1 1-1zm0 5a5 5 0 1 1-4.995 5.217L7 12l.005-.217A5 5 0 0 1 12 7z"/></g></svg>`}
82-
{/if}
68+
<button
69+
on:click={toggle}
70+
type="button"
71+
aria-pressed={$theme.current === 'dark' ? 'true' : 'false'}
72+
aria-label="Dark mode"
73+
>
74+
<span class="check" class:checked={$theme.current === 'dark'}>
75+
<span class="icon">
76+
{#if BROWSER}
77+
{#if $theme.current === 'dark'}
78+
{@html `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M12 21q-3.775 0-6.388-2.613T3 12q0-3.45 2.25-5.988T11 3.05q.625-.075.975.45t-.025 1.1q-.425.65-.638 1.375T11.1 7.5q0 2.25 1.575 3.825T16.5 12.9q.775 0 1.538-.225t1.362-.625q.525-.35 1.075-.037t.475.987q-.35 3.45-2.937 5.725T12 21Zm0-2q2.2 0 3.95-1.213t2.55-3.162q-.5.125-1 .2t-1 .075q-3.075 0-5.238-2.163T9.1 7.5q0-.5.075-1t.2-1q-1.95.8-3.163 2.55T5 12q0 2.9 2.05 4.95T12 19Zm-.25-6.75Z"/></svg>`}
79+
{:else}
80+
{@html `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M0 0h24v24H0z"/><path fill="currentColor" d="M12 19a1 1 0 0 1 .993.883L13 20v1a1 1 0 0 1-1.993.117L11 21v-1a1 1 0 0 1 1-1zm6.313-2.09l.094.083l.7.7a1 1 0 0 1-1.32 1.497l-.094-.083l-.7-.7a1 1 0 0 1 1.218-1.567l.102.07zm-11.306.083a1 1 0 0 1 .083 1.32l-.083.094l-.7.7a1 1 0 0 1-1.497-1.32l.083-.094l.7-.7a1 1 0 0 1 1.414 0zM4 11a1 1 0 0 1 .117 1.993L4 13H3a1 1 0 0 1-.117-1.993L3 11h1zm17 0a1 1 0 0 1 .117 1.993L21 13h-1a1 1 0 0 1-.117-1.993L20 11h1zM6.213 4.81l.094.083l.7.7a1 1 0 0 1-1.32 1.497l-.094-.083l-.7-.7A1 1 0 0 1 6.11 4.74l.102.07zm12.894.083a1 1 0 0 1 .083 1.32l-.083.094l-.7.7a1 1 0 0 1-1.497-1.32l.083-.094l.7-.7a1 1 0 0 1 1.414 0zM12 2a1 1 0 0 1 .993.883L13 3v1a1 1 0 0 1-1.993.117L11 4V3a1 1 0 0 1 1-1zm0 5a5 5 0 1 1-4.995 5.217L7 12l.005-.217A5 5 0 0 1 12 7z"/></g></svg>`}
8381
{/if}
84-
</span>
82+
{/if}
8583
</span>
86-
</button>
87-
</label>
84+
</span>
85+
</button>
8886
8987
<style>
9088
button {

packages/site-kit/src/lib/components/ToggleButton.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
export let label;
77
</script>
88

9-
<button aria-pressed={pressed} on:click={() => (pressed = !pressed)}>
10-
<span class="visually-hidden">{label}</span>
11-
</button>
9+
<button aria-pressed={pressed} aria-label={label} on:click={() => (pressed = !pressed)} />
1210

1311
<style>
1412
button {
@@ -21,7 +19,6 @@
2119
height: var(--size);
2220
width: calc(100% - 0.6em);
2321
max-width: calc(2 * var(--size));
24-
top: -2px;
2522
border-radius: 0.5em;
2623
-webkit-appearance: none;
2724
appearance: none;

0 commit comments

Comments
 (0)