Skip to content

Commit 9d38c4d

Browse files
GiteaBotsilverwind
andauthored
Fix unclickable checkboxes (#30195) (#30199)
Backport #30195 by @silverwind Fix #30185, regression from #30162. The checkboxes were unclickable because the label was positioned over the checkbox with `padding`. Now it uses `margin` so the checkbox itself will be clickable in all cases. Secondly, I changed the for/id linking to also add missing `for` attributes when `id` is present. The other way around (only `for` present) is currently not handled and I think there are likey no occurences in the code and introducing new non-generated `id`s might cause problems elsewhere if we do, so I skipped on that. Co-authored-by: silverwind <me@silverwind.io>
1 parent 19443a2 commit 9d38c4d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

web_src/css/modules/checkbox.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ input[type="radio"] {
4141

4242
.ui.checkbox label,
4343
.ui.radio.checkbox label {
44-
padding-left: 1.85714em;
44+
margin-left: 1.85714em;
4545
}
4646

4747
.ui.checkbox + label {

web_src/js/modules/fomantic/checkbox.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ export function initAriaCheckboxPatch() {
66
if (el.hasAttribute('data-checkbox-patched')) continue;
77
const label = el.querySelector('label');
88
const input = el.querySelector('input');
9-
if (!label || !input || input.getAttribute('id') || label.getAttribute('for')) continue;
10-
const id = generateAriaId();
11-
input.setAttribute('id', id);
12-
label.setAttribute('for', id);
9+
if (!label || !input) continue;
10+
const inputId = input.getAttribute('id');
11+
const labelFor = label.getAttribute('for');
12+
13+
if (inputId && !labelFor) { // missing "for"
14+
label.setAttribute('for', inputId);
15+
} else if (!inputId && !labelFor) { // missing both "id" and "for"
16+
const id = generateAriaId();
17+
input.setAttribute('id', id);
18+
label.setAttribute('for', id);
19+
} else {
20+
continue;
21+
}
1322
el.setAttribute('data-checkbox-patched', 'true');
1423
}
1524
}

0 commit comments

Comments
 (0)