@@ -14,7 +14,7 @@ import { Absence, Prisma } from '@prisma/client';
1414import { formatFullDate } from '@utils/dates' ;
1515import { submitAbsence } from '@utils/submitAbsence' ;
1616import { validateAbsenceForm } from '@utils/validateAbsenceForm' ;
17- import { useState } from 'react' ;
17+ import { useState , useId } from 'react' ;
1818import { useCustomToast } from '../../../CustomToast' ;
1919import { FileUpload } from '../../FileUpload' ;
2020import { AdminTeacherFields } from '../AdminTeacherFields' ;
@@ -310,6 +310,8 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
310310 const isUrgent =
311311 ( selectedDate . getTime ( ) - now . getTime ( ) ) / ( 1000 * 60 * 60 * 24 ) <= 7 ;
312312
313+ const id = useId ( ) ;
314+
313315 return (
314316 < Box
315317 as = "form"
@@ -329,11 +331,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
329331 ) }
330332
331333 < FormControl isRequired isInvalid = { ! ! errors . subjectId } >
332- < FormLabel id = "subjectLabel" as = "p" sx = { { display : 'flex' } } >
333- < Text textStyle = "h4" > Subject</ Text >
334+ < FormLabel id = { "subjectLabel" + id } as = "p" sx = { { display : 'flex' } } >
335+ < Text textStyle = "h4" > Subject</ Text >
334336 </ FormLabel >
335337 < InputDropdown
336- labelledBy = "subjectLabel"
338+ ariaLabelledBy = { "subjectLabel" + id }
337339 label = "subject"
338340 type = "subject"
339341 onChange = { ( value ) => {
@@ -353,11 +355,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
353355 </ FormControl >
354356
355357 < FormControl isRequired isInvalid = { ! ! errors . locationId } >
356- < FormLabel id = "locationLabel" as = "p" sx = { { display : 'flex' } } >
358+ < FormLabel id = { "locationLabel" + id } as = "p" sx = { { display : 'flex' } } >
357359 < Text textStyle = "h4" > Location</ Text >
358360 </ FormLabel >
359361 < InputDropdown
360- labelledBy = "locationLabel"
362+ ariaLabelledBy = { "locationLabel" + id }
361363 label = "location"
362364 type = "location"
363365 onChange = { ( value ) => {
@@ -377,11 +379,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
377379 </ FormControl >
378380
379381 < FormControl >
380- < FormLabel id = "roomNumberLabel" sx = { { display : 'flex' } } >
382+ < FormLabel id = { "roomNumberLabel" + id } sx = { { display : 'flex' } } >
381383 < Text textStyle = "h4" > Room Number</ Text >
382384 </ FormLabel >
383385 < Input
384- aria-labelledby = "roomNumberLabel"
386+ aria-labelledby = { "roomNumberLabel" + id }
385387 id = "roomNumber"
386388 name = "roomNumber"
387389 placeholder = "e.g. 2131"
@@ -397,11 +399,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
397399 />
398400
399401 < FormControl isRequired isInvalid = { ! ! errors . reasonOfAbsence } >
400- < FormLabel id = "reasonOfAbsenceLabel" sx = { { display : 'flex' } } >
402+ < FormLabel id = { "reasonOfAbsenceLabel" + id } sx = { { display : 'flex' } } >
401403 < Text textStyle = "h4" > Reason of Absence</ Text >
402404 </ FormLabel >
403405 < Textarea
404- aria-labelledby = "reasonOfAbsenceLabel"
406+ aria-labelledby = { "reasonOfAbsenceLabel" + id }
405407 id = "reasonOfAbsence"
406408 name = "reasonOfAbsence"
407409 placeholder = "Only visible to admin"
@@ -420,11 +422,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
420422 </ FormControl >
421423
422424 < FormControl >
423- < FormLabel id = "notesLabel" sx = { { display : 'flex' } } >
425+ < FormLabel id = { "notesLabel" + id } sx = { { display : 'flex' } } >
424426 < Text textStyle = "h4" > Notes</ Text >
425427 </ FormLabel >
426428 < Textarea
427- aria-labelledby = "notesLabel"
429+ aria-labelledby = { "notesLabel" + id }
428430 id = "notes"
429431 name = "notes"
430432 placeholder = "Visible to everyone"
0 commit comments