Skip to content

Commit c677038

Browse files
committed
change label to p to prevent label click-through onto input
1 parent c06b63c commit c677038

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/components/absences/modals/DateOfAbsence.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const DateOfAbsence: React.FC<DateOfAbsenceProps> = ({
6565

6666
return (
6767
<FormControl isRequired isInvalid={!!error}>
68-
<FormLabel sx={{ display: 'flex' }}>
68+
<FormLabel as="p" id="dateOfAbsenceLabel" sx={{ display: 'flex' }}>
6969
<Text textStyle="h4">{label}</Text>
7070
</FormLabel>
7171
<Popover
@@ -77,6 +77,7 @@ export const DateOfAbsence: React.FC<DateOfAbsenceProps> = ({
7777
<PopoverTrigger>
7878
<Box>
7979
<Input
80+
aria-labelledby="dateOfAbsenceLabel"
8081
value={inputValue}
8182
onChange={handleInputChange}
8283
placeholder="YYYY-MM-DD"

src/components/absences/modals/InputDropdown.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import { useCustomToast } from '../../CustomToast';
1818
export type Option = { name: string; id: number };
1919

2020
interface InputDropdownProps {
21+
labelledBy: string;
2122
label: string;
2223
type: 'location' | 'subject';
2324
onChange: (value: Option | null) => void;
2425
defaultValueId?: number;
2526
}
2627

2728
export const InputDropdown: React.FC<InputDropdownProps> = ({
29+
labelledBy,
2830
label,
2931
type,
3032
onChange,
@@ -120,6 +122,7 @@ export const InputDropdown: React.FC<InputDropdownProps> = ({
120122
value={selectedOption ? selectedOption.name : ''}
121123
readOnly
122124
_focusVisible={{ outline: 'none' }}
125+
aria-labelledby={labelledBy}
123126
/>
124127
<InputRightElement pointerEvents="none">
125128
{isOpen ? <IoChevronUp /> : <IoChevronDown />}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
329329
)}
330330

331331
<FormControl isRequired isInvalid={!!errors.subjectId}>
332-
<FormLabel sx={{ display: 'flex' }}>
332+
<FormLabel id="subjectLabel" as="p" sx={{ display: 'flex' }}>
333333
<Text textStyle="h4">Subject</Text>
334334
</FormLabel>
335335
<InputDropdown
336+
labelledBy="subjectLabel"
336337
label="subject"
337338
type="subject"
338339
onChange={(value) => {
@@ -352,10 +353,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
352353
</FormControl>
353354

354355
<FormControl isRequired isInvalid={!!errors.locationId}>
355-
<FormLabel sx={{ display: 'flex' }}>
356+
<FormLabel id="locationLabel" as="p" sx={{ display: 'flex' }}>
356357
<Text textStyle="h4">Location</Text>
357358
</FormLabel>
358359
<InputDropdown
360+
labelledBy="locationLabel"
359361
label="location"
360362
type="location"
361363
onChange={(value) => {
@@ -373,29 +375,33 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
373375
/>
374376
<FormErrorMessage>{errors.locationId}</FormErrorMessage>
375377
</FormControl>
378+
376379
<FormControl>
377-
<FormLabel htmlFor="roomNumber" sx={{ display: 'flex' }}>
380+
<FormLabel id="roomNumberLabel" sx={{ display: 'flex' }}>
378381
<Text textStyle="h4">Room Number</Text>
379382
</FormLabel>
380383
<Input
384+
aria-labelledby="roomNumberLabel"
381385
id="roomNumber"
382386
name="roomNumber"
383387
placeholder="e.g. 2131"
384388
value={formData.roomNumber}
385389
onChange={handleChange}
386390
/>
387391
</FormControl>
392+
388393
<DateOfAbsence
389394
dateValue={initialDate}
390395
onDateSelect={handleDateSelect}
391396
error={errors.lessonDate}
392397
/>
393398

394399
<FormControl isRequired isInvalid={!!errors.reasonOfAbsence}>
395-
<FormLabel htmlFor="reasonOfAbsence" sx={{ display: 'flex' }}>
400+
<FormLabel id="reasonOfAbsenceLabel" sx={{ display: 'flex' }}>
396401
<Text textStyle="h4">Reason of Absence</Text>
397402
</FormLabel>
398403
<Textarea
404+
aria-labelledby="reasonOfAbsenceLabel"
399405
id="reasonOfAbsence"
400406
name="reasonOfAbsence"
401407
placeholder="Only visible to admin"
@@ -414,10 +420,11 @@ const DeclareAbsenceForm: React.FC<DeclareAbsenceFormProps> = ({
414420
</FormControl>
415421

416422
<FormControl>
417-
<FormLabel htmlFor="notes" sx={{ display: 'flex' }}>
423+
<FormLabel id="notesLabel" sx={{ display: 'flex' }}>
418424
<Text textStyle="h4">Notes</Text>
419425
</FormLabel>
420426
<Textarea
427+
aria-labelledby="notesLabel"
421428
id="notes"
422429
name="notes"
423430
placeholder="Visible to everyone"

src/components/absences/modals/edit/EditAbsenceForm.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,11 @@ const EditAbsenceForm: React.FC<EditAbsenceFormProps> = ({
291291
)}
292292

293293
<FormControl isRequired isInvalid={!!errors.subjectId}>
294-
<FormLabel sx={{ display: 'flex' }}>
294+
<FormLabel id="subjectLabel" as="p" sx={{ display: 'flex' }}>
295295
<Text textStyle="h4">Subject</Text>
296296
</FormLabel>
297297
<InputDropdown
298+
labelledBy="subjectLabel"
298299
label="subject"
299300
type="subject"
300301
onChange={(value) => {
@@ -315,10 +316,11 @@ const EditAbsenceForm: React.FC<EditAbsenceFormProps> = ({
315316
</FormControl>
316317

317318
<FormControl isRequired isInvalid={!!errors.locationId}>
318-
<FormLabel sx={{ display: 'flex' }}>
319+
<FormLabel id="locationLabel" as="p" sx={{ display: 'flex' }}>
319320
<Text textStyle="h4">Location</Text>
320321
</FormLabel>
321322
<InputDropdown
323+
labelledBy="locationLabel"
322324
label="location"
323325
type="location"
324326
onChange={(value) => {

0 commit comments

Comments
 (0)