Skip to content

Commit

Permalink
Merge branch 'main' into nl/3210-fix-converted-federal-agency-none-check
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoByte authored Dec 11, 2024
2 parents 62d53ff + 2df6603 commit b6ae867
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/registrar/templates/django/forms/widgets/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
class="{{ uswds_input_class }}{% if classes %} {{ classes }}{% endif %}"
{% if widget.value != None %}value="{{ widget.value|stringformat:'s' }}"{% endif %}
{% if aria_label %}aria-label="{{ aria_label }} {{ label }}"{% endif %}
{% if sublabel_text %}aria-describedby="{{ widget.attrs.id }}__sublabel"{% endif %}
{% include "django/forms/widgets/attrs.html" %}
/>
11 changes: 10 additions & 1 deletion src/registrar/templatetags/field_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def input_with_errors(context, field=None): # noqa: C901
legend_classes = []
group_classes = []
aria_labels = []
sublabel_text = []

# this will be converted to an attribute string
described_by = []
Expand Down Expand Up @@ -103,6 +104,9 @@ def input_with_errors(context, field=None): # noqa: C901
elif key == "add_aria_label":
aria_labels.append(value)

elif key == "sublabel_text":
sublabel_text.append(value)

attrs["id"] = field.auto_id

# do some work for various edge cases
Expand Down Expand Up @@ -152,11 +156,16 @@ def input_with_errors(context, field=None): # noqa: C901
if group_classes:
context["group_classes"] = " ".join(group_classes)

# We handle sublabel_text here instead of directy in the template to avoid conflicts
if sublabel_text:
sublabel_div_id = f"{attrs['id']}__sublabel"
described_by.insert(0, sublabel_div_id)

if described_by:
# ensure we don't overwrite existing attribute value
if "aria-describedby" in attrs:
described_by.append(attrs["aria-describedby"])
attrs["aria_describedby"] = " ".join(described_by)
attrs["aria-describedby"] = " ".join(described_by)

if aria_labels:
context["aria_label"] = " ".join(aria_labels)
Expand Down

0 comments on commit b6ae867

Please sign in to comment.