Skip to content

Commit 1a13c23

Browse files
authored
Enhance comment forms (#604)
* Fix incorrect label text in StackedFrom component * Remove redundant onSubmit handlers * Add htmlFor and aria-label attributes to form labels to improve accessibility * Fix: properly bind the disabled prop The disabled prop is incorrectly passed without a value. In ReScript, boolean props need to be explicitly set. * Fix CI failures - Use camelCase for aria attributes (ariaLabel, ariaRequired) - Use boolean `true` instead of string "true" for ariaRequired - Fix htmlFor placement inside label tags
1 parent dbed970 commit 1a13c23

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let make = (~fetchData) => {
122122
disabled
123123
/>
124124
| Stacked =>
125-
<StackedFrom
125+
<StackedForm
126126
author={state.author}
127127
handleAuthorChange
128128
text={state.text}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
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
4+
className="form-horizontal flex flex-col gap-4"
5+
onSubmit=handleSubmit
6+
disabled={disabled}
7+
ariaLabel="Comment submission form">
48
<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>
9+
<label htmlFor="comment_author" className="w-full lg:w-2/12 lg:text-end shrink-0">
10+
{"Name"->React.string}
11+
</label>
612
<input
713
type_="text"
814
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -11,10 +17,14 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
1117
id="comment_author"
1218
onChange=handleAuthorChange
1319
value={author}
20+
ariaLabel="Author name"
21+
ariaRequired=true
1422
/>
1523
</div>
1624
<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>
25+
<label htmlFor="comment_text" className="w-full lg:w-2/12 lg:text-end shrink-0">
26+
{"Text"->React.string}
27+
</label>
1828
<input
1929
type_="text"
2030
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -23,6 +33,8 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
2333
id="comment_text"
2434
onChange=handleTextChange
2535
value={text}
36+
ariaLabel="Comment text"
37+
ariaRequired=true
2638
/>
2739
</div>
2840
<div className="flex flex-col gap-0 lg:gap-4 lg:flex-row">
@@ -31,6 +43,7 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
3143
type_="submit"
3244
className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
3345
value="Post"
46+
ariaLabel="Submit comment"
3447
/>
3548
</div>
3649
</form>

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

Lines changed: 9 additions & 4 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={disabled}
7+
ariaLabel="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+
ariaLabel="Author name"
19+
ariaRequired=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,14 +29,16 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
2629
id="comment_text"
2730
onChange=handleTextChange
2831
value={text}
32+
ariaLabel="Comment text"
33+
ariaRequired=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"
35-
onSubmit=handleSubmit
3640
value="Post"
41+
ariaLabel="Submit comment"
3742
/>
3843
</div>
3944
</form>

client/app/bundles/comments/rescript/CommentForm/forms/StackedFrom.res renamed to client/app/bundles/comments/rescript/CommentForm/forms/StackedForm.res

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
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
4+
onSubmit=handleSubmit
5+
disabled={disabled}
6+
className="flex flex-col gap-4"
7+
ariaLabel="Comment submission form">
48
<div className="flex flex-col gap-0">
5-
<label className="w-full"> {"Name"->React.string} </label>
9+
<label htmlFor="comment_author" className="w-full"> {"Name"->React.string} </label>
610
<input
711
type_="text"
812
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -11,10 +15,12 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
1115
id="comment_author"
1216
onChange=handleAuthorChange
1317
value={author}
18+
ariaLabel="Author name"
19+
ariaRequired=true
1420
/>
1521
</div>
1622
<div className="flex flex-col gap-0">
17-
<label className="w-full"> {"Name"->React.string} </label>
23+
<label htmlFor="comment_text" className="w-full"> {"Text"->React.string} </label>
1824
<input
1925
type_="text"
2026
className="px-3 py-1 leading-4 border border-gray-300 rounded w-full"
@@ -23,14 +29,16 @@ let make = (~author, ~handleAuthorChange, ~text, ~handleTextChange, ~handleSubmi
2329
id="comment_text"
2430
onChange=handleTextChange
2531
value={text}
32+
ariaLabel="Comment text"
33+
ariaRequired=true
2634
/>
2735
</div>
2836
<div className="flex flex-col gap-0">
2937
<input
3038
type_="submit"
3139
className="self-start px-3 py-1 font-semibold border-0 rounded text-sky-50 bg-sky-600 hover:bg-sky-800"
32-
onSubmit=handleSubmit
3340
value="Post"
41+
ariaLabel="Submit comment"
3442
/>
3543
</div>
3644
</form>

0 commit comments

Comments
 (0)