Skip to content

Commit c8257f8

Browse files
Daniel Karlssonbep
authored andcommitted
Render task list item inside label for correct accessibility
Fixes #3303
1 parent 0abdeee commit c8257f8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

‎helpers/content_renderer.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ func (r *HugoHTMLRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
5050

5151
switch {
5252
case bytes.HasPrefix(text, []byte("[ ] ")):
53-
text = append([]byte(`<input type="checkbox" disabled class="task-list-item">`), text[3:]...)
53+
text = append([]byte(`<label><input type="checkbox" disabled class="task-list-item">`), text[3:]...)
54+
text = append(text, []byte(`</label>`)...)
5455

5556
case bytes.HasPrefix(text, []byte("[x] ")) || bytes.HasPrefix(text, []byte("[X] ")):
56-
text = append([]byte(`<input type="checkbox" checked disabled class="task-list-item">`), text[3:]...)
57+
text = append([]byte(`<label><input type="checkbox" checked disabled class="task-list-item">`), text[3:]...)
58+
text = append(text, []byte(`</label>`)...)
5759
}
5860

5961
r.Renderer.ListItem(out, text, flags)

‎helpers/content_renderer_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ END
108108
`, true, `<p>TODO:</p>
109109
110110
<ul class="task-list">
111-
<li><input type="checkbox" checked disabled class="task-list-item"> On1</li>
112-
<li><input type="checkbox" checked disabled class="task-list-item"> On2</li>
113-
<li><input type="checkbox" disabled class="task-list-item"> Off</li>
111+
<li><label><input type="checkbox" checked disabled class="task-list-item"> On1</label></li>
112+
<li><label><input type="checkbox" checked disabled class="task-list-item"> On2</label></li>
113+
<li><label><input type="checkbox" disabled class="task-list-item"> Off</label></li>
114114
</ul>
115115
116116
<p>END</p>
@@ -122,7 +122,7 @@ END
122122
{`* [ ] Off
123123
124124
END`, true, `<ul class="task-list">
125-
<li><input type="checkbox" disabled class="task-list-item"> Off</li>
125+
<li><label><input type="checkbox" disabled class="task-list-item"> Off</label></li>
126126
</ul>
127127
128128
<p>END</p>

0 commit comments

Comments
 (0)