Skip to content

Commit

Permalink
perf(a11y): add aria-checked attribute to switch (#644)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <[email protected]>
  • Loading branch information
kecrily and brc-dd authored Aug 31, 2022
1 parent 9a6e1ea commit eb9026d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/client/theme-default/components/VPSwitchAppearance.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { APPEARANCE_KEY } from '../../shared.js'
import VPSwitch from './VPSwitch.vue'
import VPIconSun from './icons/VPIconSun.vue'
import VPIconMoon from './icons/VPIconMoon.vue'
const checked = ref(false)
const toggle = typeof localStorage !== 'undefined' ? useAppearance() : () => {}
onMounted(() => {
checked.value = document.documentElement.classList.contains('dark')
})
function useAppearance() {
const query = window.matchMedia('(prefers-color-scheme: dark)')
const classList = document.documentElement.classList
Expand Down Expand Up @@ -33,6 +39,7 @@ function useAppearance() {
}
function setClass(dark: boolean): void {
checked.value = dark
classList[dark ? 'add' : 'remove']('dark')
}
Expand All @@ -44,6 +51,7 @@ function useAppearance() {
<VPSwitch
class="VPSwitchAppearance"
aria-label="toggle dark mode"
:aria-checked="checked"
@click="toggle"
>
<VPIconSun class="sun" />
Expand Down

0 comments on commit eb9026d

Please sign in to comment.