Skip to content

Commit 5cb9744

Browse files
committed
[TAC025] Improve the required fields on the forms for screen reader
1 parent e64e6ef commit 5cb9744

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
.label-required{
2+
cursor: help;
3+
border-bottom: $abbr-underline;
4+
text-decoration: none;
5+
padding-right: 0;
26
margin-left: 5px;
7+
8+
> span{
9+
padding-right: 0;
10+
margin-right: 0;
11+
}
312
}

decidim-core/app/assets/stylesheets/decidim/modules/_forms.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ $checkboxes-minimum-width: 200px;
1212
line-height: 1.2;
1313
}
1414

15-
.label-required{
16-
cursor: help;
17-
border-bottom: $abbr-underline;
18-
text-decoration: none;
19-
padding-right: 0;
20-
}
21-
2215
.form-input-extra-before,
2316
.form-input-extra-after{
2417
display: block;

decidim-core/lib/decidim/form_builder.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,20 @@ def file_is_present?(file)
685685

686686
def required_for_attribute(attribute)
687687
if attribute_required?(attribute)
688-
return content_tag(:span, "*", title: I18n.t("required", scope: "forms"),
689-
data: { tooltip: true, disable_hover: false, keep_on_hover: true },
690-
"aria-haspopup": true,
691-
class: "label-required").html_safe
688+
visible_title = content_tag(:span, "*", "aria-hidden": true)
689+
screenreader_title = content_tag(
690+
:span,
691+
I18n.t("required", scope: "forms"),
692+
class: "show-for-sr"
693+
)
694+
return content_tag(
695+
:span,
696+
visible_title + screenreader_title,
697+
title: I18n.t("required", scope: "forms"),
698+
data: { tooltip: true, disable_hover: false, keep_on_hover: true },
699+
"aria-haspopup": true,
700+
class: "label-required"
701+
).html_safe
692702
end
693703
"".html_safe
694704
end

0 commit comments

Comments
 (0)