Skip to content

Commit 69e0b07

Browse files
committed
fix accessibilty
1 parent eb43726 commit 69e0b07

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

frontend_vue/src/components/base/BaseFilterDropDown.vue

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
2-
<div v-clickaway="handleClickAway" class="relative">
2+
<div v-clickaway="closePopUp" class="relative">
33
<BaseButton
4-
ref="filterButton"
54
variant="text"
65
icon="filter"
76
aria-label="filter button"
@@ -15,17 +14,16 @@
1514
role="dialog"
1615
@click.stop
1716
>
18-
<fieldset id="radio-group-action" class="space-y-3">
17+
<fieldset id="radio-group-action" class="space-y-3" role="radiogroup">
1918
<BaseRadioInput
2019
v-for="option in filterOptions"
2120
:id="`${name}-${option}`"
2221
:key="option"
2322
:name="name"
24-
:label="option.charAt(0).toUpperCase() + option.slice(1)"
23+
:label="capitalizeOption(option)"
2524
:value="option"
2625
:checked="filterOption === option"
2726
@select-value="handleSelectFilter"
28-
@escape="handleClickAway"
2927
/>
3028
</fieldset>
3129
</div>
@@ -34,11 +32,10 @@ v-for="option in filterOptions"
3432
<script setup lang="ts">
3533
import BaseButton from '@/components/base/BaseButton.vue';
3634
import BaseRadioInput from '@/components/base/BaseRadioInput.vue';
37-
import { ref, useTemplateRef } from 'vue';
35+
import { ref, onMounted, onUnmounted } from 'vue';
3836
import { onClickaway } from '@/directives/clickAway';
3937
4038
const vClickaway = onClickaway;
41-
const filterButton = useTemplateRef('filterButton');
4239
4340
const props = defineProps<{
4441
filterOptions: string[];
@@ -51,14 +48,31 @@ const emits = defineEmits(['update-filter-option']);
5148
const showAlertFilterPopup = ref(false);
5249
const filterOption = ref(props.defaultFilterOption);
5350
54-
function handleClickAway() {
51+
onMounted(() => {
52+
document.addEventListener('keydown', handleEscapeKey);
53+
});
54+
55+
onUnmounted(() => {
56+
document.removeEventListener('keydown', handleEscapeKey);
57+
});
58+
59+
function capitalizeOption(option: string) {
60+
return `${option.charAt(0).toUpperCase()}${option.slice(1)}`;
61+
}
62+
63+
function closePopUp() {
5564
showAlertFilterPopup.value = false;
5665
}
5766
67+
68+
function handleEscapeKey(event: KeyboardEvent) {
69+
if (event.key === 'Escape' && showAlertFilterPopup.value) {
70+
closePopUp();
71+
}
72+
}
73+
5874
function handleSelectFilter(option: string) {
5975
filterOption.value = option;
60-
showAlertFilterPopup.value = false;
6176
emits('update-filter-option', option);
62-
filterButton.value?.$el?.focus();
6377
}
6478
</script>

frontend_vue/src/components/base/BasePill.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<p class="text-xs rounded-xl px-16 py-4 inline-block text-nowrap"
3-
:class="'bg-' + backgroundColour + ' text-' + textColour"
3+
:class="`bg-${backgroundColour} text-${textColour}`"
44
>
55
<slot></slot>
66
</p>

frontend_vue/src/components/base/BaseRadioInput.vue

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
type="radio"
1010
:name="name"
1111
@change="handleChangeOption"
12-
@keydown="handleKeyDown"
1312
/>
1413
{{ label }}</label
1514
>
@@ -33,32 +32,6 @@ function handleChangeOption(e: Event) {
3332
emits('selectValue', (e.target as HTMLInputElement).value);
3433
}
3534
36-
function handleKeyDown(e: KeyboardEvent) {
37-
const target = e.target as HTMLInputElement;
38-
39-
if (e.key === 'Enter' || e.key === ' ') {
40-
e.preventDefault();
41-
target.checked = true;
42-
value.value = target.value;
43-
emits('selectValue', target.value);
44-
} else if (e.key === 'Escape') {
45-
e.preventDefault();
46-
emits('escape');
47-
} else if (e.key === 'ArrowDown' || e.key === 'ArrowRight' || e.key === 'ArrowUp' || e.key === 'ArrowLeft') {
48-
e.preventDefault();
49-
const radioGroup = target.closest('[role="radiogroup"]');
50-
const radios = radioGroup?.querySelectorAll('input[type="radio"]') as NodeListOf<HTMLInputElement>;
51-
const currentIndex = Array.from(radios).indexOf(target);
52-
53-
const isDown = e.key === 'ArrowDown' || e.key === 'ArrowRight';
54-
const nextIndex = isDown
55-
? (currentIndex + 1) % radios.length
56-
: currentIndex === 0 ? radios.length - 1 : currentIndex - 1;
57-
58-
radios[nextIndex]?.focus();
59-
}
60-
}
61-
6235
watch(errorMessage, () => {
6336
emits('hasError', errorMessage.value);
6437
});

0 commit comments

Comments
 (0)