Skip to content

Commit 107543c

Browse files
Improve accessibility for teacher selection fields
Added unique aria-labelledby attributes and label IDs to the AdminTeacherFields and SearchDropdown components to enhance accessibility. Also fixed minor formatting in DeclareAbsenceForm. These changes ensure better screen reader support for form fields.
1 parent 8bc09ad commit 107543c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/components/absences/modals/AdminTeacherFields.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
FormLabel,
55
Text,
66
} from '@chakra-ui/react';
7+
import { useId } from 'react';
78
import { SearchDropdown } from './SearchDropdown';
89

910
interface AdminTeacherFieldsProps {
@@ -28,14 +29,21 @@ export const AdminTeacherFields: React.FC<AdminTeacherFieldsProps> = ({
2829
setFormData,
2930
setErrors,
3031
}) => {
32+
const id = useId();
33+
3134
return (
3235
<>
3336
<FormControl isRequired isInvalid={!!errors.absentTeacherId}>
34-
<FormLabel htmlFor="absentTeacher" sx={{ display: 'flex' }}>
37+
<FormLabel
38+
id={'absentTeacherLabel' + id}
39+
as="p"
40+
sx={{ display: 'flex' }}
41+
>
3542
<Text textStyle="h4">Teacher Absent</Text>
3643
</FormLabel>
3744
<SearchDropdown
3845
id="absentTeacher"
46+
ariaLabelledBy={'absentTeacherLabel' + id}
3947
excludedId={formData.substituteTeacherId}
4048
defaultValueId={Number(formData.absentTeacherId)}
4149
onChange={(value) => {
@@ -55,11 +63,16 @@ export const AdminTeacherFields: React.FC<AdminTeacherFieldsProps> = ({
5563
</FormControl>
5664

5765
<FormControl>
58-
<FormLabel htmlFor="substituteTeacher" sx={{ display: 'flex' }}>
66+
<FormLabel
67+
id={'substituteTeacherLabel' + id}
68+
as="p"
69+
sx={{ display: 'flex' }}
70+
>
5971
<Text textStyle="h4">Substitute Teacher</Text>
6072
</FormLabel>
6173
<SearchDropdown
6274
id="substituteTeacher"
75+
ariaLabelledBy={'substituteTeacherLabel' + id}
6376
excludedId={formData.absentTeacherId}
6477
defaultValueId={
6578
formData.substituteTeacherId

src/components/absences/modals/SearchDropdown.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ export type Option = { name: string; id: number; profilePicture: string };
2121

2222
interface SearchDropdownProps {
2323
id: string;
24+
ariaLabelledBy: string;
2425
excludedId?: string;
2526
defaultValueId?: number;
2627
onChange: (value: Option | null) => void;
2728
}
2829

2930
export const SearchDropdown: React.FC<SearchDropdownProps> = ({
3031
id,
32+
ariaLabelledBy,
3133
excludedId,
3234
defaultValueId,
3335
onChange,
@@ -174,6 +176,7 @@ export const SearchDropdown: React.FC<SearchDropdownProps> = ({
174176
id={id}
175177
name={id}
176178
ref={inputRef}
179+
aria-labelledby={ariaLabelledBy}
177180
value={searchQuery}
178181
onChange={isSelected ? undefined : handleSearchChange}
179182
onClick={() => {

src/components/absences/modals/declare/DeclareAbsenceForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Absence, Prisma } from '@prisma/client';
1414
import { formatFullDate } from '@utils/dates';
1515
import { submitAbsence } from '@utils/submitAbsence';
1616
import { validateAbsenceForm } from '@utils/validateAbsenceForm';
17-
import { useState, useId } from 'react';
17+
import { useId, useState } from 'react';
1818
import { useCustomToast } from '../../../CustomToast';
1919
import { FileUpload } from '../../FileUpload';
2020
import { AdminTeacherFields } from '../AdminTeacherFields';
@@ -340,7 +340,7 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
340340

341341
<FormControl isRequired isInvalid={!!errors.subjectId}>
342342
<FormLabel id={'subjectLabel' + id} as="p" sx={{ display: 'flex' }}>
343-
<Text textStyle="h4"> Subject</Text>
343+
<Text textStyle="h4">Subject</Text>
344344
</FormLabel>
345345
<InputDropdown
346346
ariaLabelledBy={'subjectLabel' + id}

0 commit comments

Comments
 (0)