Skip to content

Commit b531492

Browse files
committed
Add htmlFor and aria-label attributes to form labels to improve accessibility
1 parent 475d460 commit b531492

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@react.component
22
let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmit, ~disabled) => {
3-
<form className="form-horizontal flex flex-col gap-4" onSubmit=handleSubmit disabled>
3+
<form className="form-horizontal flex flex-col gap-4" onSubmit=handleSubmit disabled aria-label="Comment submission form">
44
<div className="flex flex-col gap-0 items-center lg:gap-4 lg:flex-row">
5-
<label className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Name"->React.string} </label>
5+
<label htmlFor="comment_author" className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Name"->React.string} </label>
66
<input
77
type_="text"
88
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -11,10 +11,12 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
1111
id="comment_author"
1212
onChange=handleAuthorChange
1313
value={author}
14+
aria-label="Author name"
15+
aria-required="true"
1416
/>
1517
</div>
1618
<div className="flex flex-col gap-0 items-center lg:gap-4 lg:flex-row">
17-
<label className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Text"->React.string} </label>
19+
<label htmlFor="comment_text" className="w-full lg:w-2/12 lg:text-end shrink-0"> {"Text"->React.string} </label>
1820
<input
1921
type_="text"
2022
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -23,6 +25,8 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
2325
id="comment_text"
2426
onChange=handleTextChange
2527
value={text}
28+
aria-label="Comment text"
29+
aria-required="true"
2630
/>
2731
</div>
2832
<div className="flex flex-col gap-0 lg:gap-4 lg:flex-row">
@@ -31,6 +35,7 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
3135
type_="submit"
3236
className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
3337
value="Post"
38+
aria-label="Submit comment"
3439
/>
3540
</div>
3641
</form>

client/app/bundles/comments/rescript/CommentForm/forms/InlineForm.res

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
33
<form
44
className="form-inline flex flex-col lg:flex-row flex-wrap gap-4"
55
onSubmit=handleSubmit
6-
disabled>
6+
disabled
7+
aria-label="Comment submission form">
78
<div className="flex gap-2 items-center">
8-
<label> {"Name"->React.string} </label>
9+
<label> htmlFor="comment_author" {"Name"->React.string} </label>
910
<input
1011
type_="text"
1112
className="px-3 py-1 leading-4 border border-gray-300 rounded"
@@ -14,10 +15,12 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
1415
id="comment_author"
1516
value={author}
1617
onChange=handleAuthorChange
18+
aria-label="Author name"
19+
aria-required="true"
1720
/>
1821
</div>
1922
<div className="flex gap-2 items-center">
20-
<label> {"Text"->React.string} </label>
23+
<label> htmlFor="comment_text" {"Text"->React.string} </label>
2124
<input
2225
type_="text"
2326
className="px-3 py-1 leading-4 border border-gray-300 rounded"
@@ -26,13 +29,16 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
2629
id="comment_text"
2730
onChange=handleTextChange
2831
value={text}
32+
aria-label="Comment text"
33+
aria-required="true"
2934
/>
3035
</div>
3136
<div className="flex gap-2">
3237
<input
3338
type_="submit"
3439
className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
3540
value="Post"
41+
aria-label="Submit comment"
3642
/>
3743
</div>
3844
</form>

client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.res

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@react.component
22
let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmit, ~disabled) => {
3-
<form onSubmit=handleSubmit disabled className="flex flex-col gap-4">
3+
<form onSubmit=handleSubmit disabled className="flex flex-col gap-4" aria-label="Comment submission form">
44
<div className="flex flex-col gap-0">
5-
<label className="w-full"> {"Name"->React.string} </label>
5+
<label htmlFor="comment_author" className="w-full"> {"Name"->React.string} </label>
66
<input
77
type_="text"
88
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -11,10 +11,12 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
1111
id="comment_author"
1212
onChange=handleAuthorChange
1313
value={author}
14+
aria-label="Author name"
15+
aria-required="true"
1416
/>
1517
</div>
1618
<div className="flex flex-col gap-0">
17-
<label className="w-full"> {"Text"->React.string} </label>
19+
<label htmlFor="comment_text" className="w-full"> {"Text"->React.string} </label>
1820
<input
1921
type_="text"
2022
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -23,13 +25,16 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
2325
id="comment_text"
2426
onChange=handleTextChange
2527
value={text}
28+
aria-label="Comment text"
29+
aria-required="true"
2630
/>
2731
</div>
2832
<div className="flex flex-col gap-0">
2933
<input
3034
type_="submit"
3135
className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
3236
value="Post"
37+
aria-label="Submit comment"
3338
/>
3439
</div>
3540
</form>

0 commit comments

Comments
 (0)