Skip to content

Commit

Permalink
Improve accessibility (#1)
Browse files Browse the repository at this point in the history
* Accessibility: Live update the question for easier screen reader usage

* Accessibility: Always focus first AnswerButton on Question Cards for quicker keyboard and AT use

* Accessibility: Hide redundant, visual only progress indicator, from AT

* Accessibility: Hack to make AnswerIndicators accessible

Due to the inherent inaccessibility of Popper, this is a very dirty workaround to make the contents of the results table known to Screen Reader users. It shouldn't be done this way, but doing it properly would require a major architectural change. Also, aria-label can only be used on interactive elements, which this is not.

* Accessibility: Also adhere to reduce motion for ResultMatches
  • Loading branch information
KreerC authored Jan 29, 2025
1 parent 97cf72a commit 650a1e4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/components/AnswerButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Popper from 'vue3-popper'
import type { Answer } from '../content.config'
import { answerLabels } from '../store'
import { onMounted } from 'vue';
defineProps<{
answer: Answer
Expand All @@ -12,6 +13,12 @@ defineProps<{
const emit = defineEmits<{
save: [Answer]
}>()
onMounted(() => {
// For accessibility reason, we always want to focus the first button
const button = document.querySelector('.answer-button button')
button?.focus()
})
</script>

<template>
Expand All @@ -32,6 +39,7 @@ const emit = defineEmits<{
:class="{ 'ring-3 ring-primary-yellow': selected }"
@click="emit('save', answer)"
:disabled="disabled"
tabindex="0"
>
<slot class="me-1" />
{{ answerLabels[answer] }}
Expand Down
4 changes: 2 additions & 2 deletions src/components/AnswerIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const styles: Record<Answer, any> = {
class="flex h-10 w-10 items-center justify-center rounded-full text-white"
:class="[styles[answer].class]"
v-bind="$attrs"
:aria-label="answerLabels[answer]"
>
<component :is="styles[answer].icon" class="h-7 w-7" aria-hidden="true" />
<span class="sr-only">{{ answerLabels[answer] }}</span>
<component :is="styles[answer].icon" class="h-7 w-7" aria-hidden="true" />
</div>
</Popper>
</template>
2 changes: 1 addition & 1 deletion src/components/QuestionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const hasAnswer = computed(
</div>
</Transition>
<Transition mode="out-in" :name="transitionName">
<div class="" :key="currentQuestionIndex">
<div aria-live="assertive" class="" :key="currentQuestionIndex">
<h2 class="my-4 text-xl font-medium max-md:hyphens-auto @md:text-4xl">
{{ currentQuestion.thesis }}
</h2>
Expand Down
7 changes: 6 additions & 1 deletion src/components/ResultMatches.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ dl {
}
.progress-result {
animation: result-bar 1s cubic-bezier(0, 0, 0.2, 1);
transform-origin: left;
}
@media (prefers-reduced-motion: no-preference) {
.progress-result {
animation: result-bar 1s cubic-bezier(0, 0, 0.2, 1);
}
}
@keyframes result-bar {
from {
transform: scaleX(0);
Expand Down
1 change: 1 addition & 0 deletions src/views/Questionnaire.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const previousQuestion = () => {
aria-valuemin="1"
:aria-valuemax="questionsCount"
:aria-valuenow="currentQuestionProgress"
aria-hidden="true"
>
<div
class="h-2 bg-purple-900 duration-300 ease-out motion-safe:transition-all"
Expand Down

0 comments on commit 650a1e4

Please sign in to comment.