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

perf(a11y): add aria-checked attribute to switch #644

Merged
merged 5 commits into from
Aug 31, 2022
Merged
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
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