Skip to content

Commit

Permalink
Merge pull request #4747 from open-formulieren/feature/4717-accessibi…
Browse files Browse the repository at this point in the history
…lity-improvements-aria

Feature/4717 accessibility improvements aria
  • Loading branch information
sergei-maertens authored Nov 12, 2024
2 parents 4c53505 + b5daa22 commit 6b715c6
Show file tree
Hide file tree
Showing 11 changed files with 653 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/openforms/emails/tests/test_confirmation_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def test_checkboxes_ordering(self):
context = get_confirmation_email_context_data(submission)
rendered_content = render_email_template("{% summary %}", context)

self.assertIn("Value 1; Value 2", rendered_content)
self.assertInHTML("<ul><li>Value 1</li><li>Value 2</li></ul>", rendered_content)

def test_get_confirmation_email_templates(self):
email_template1 = ConfirmationEmailTemplateFactory.create(
Expand Down
16 changes: 11 additions & 5 deletions src/openforms/formio/formatters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Generic, Iterable, Sequence, TypeVar

from django.utils.encoding import force_str
from django.utils.html import format_html_join
from django.utils.html import format_html, format_html_join

from ..typing import Component

Expand Down Expand Up @@ -51,12 +51,18 @@ def normalise_value_to_list(self, component: ComponentT, value: Any):
def join_formatted_values(
self, component: Component, formatted_values: Iterable[str]
) -> str:
if self.as_html:
args_generator = ((formatted,) for formatted in formatted_values)
return format_html_join(self.multiple_separator, "{}", args_generator)
else:
if not self.as_html:
return self.multiple_separator.join(formatted_values)

args_generator = ((formatted,) for formatted in formatted_values)
if component.get("multiple", False):
return format_html(
"<ul>{values}</ul>",
values=format_html_join("", "<li>{}</li>", args_generator),
)

return format_html_join(self.multiple_separator, "{}", args_generator)

def process_result(self, component: ComponentT, formatted: str) -> str:
return formatted

Expand Down
14 changes: 13 additions & 1 deletion src/openforms/formio/formatters/formio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.template.defaultfilters import date as fmt_date, time as fmt_time, yesno
from django.utils.dateparse import parse_date, parse_time
from django.utils.formats import number_format
from django.utils.html import format_html
from django.utils.html import format_html, format_html_join
from django.utils.translation import gettext, gettext_lazy as _

from glom import glom
Expand Down Expand Up @@ -120,6 +120,18 @@ def format(self, component: SelectBoxesComponent, value: dict[str, bool]) -> str
selected_labels = [
entry["label"] for entry in component["values"] if value.get(entry["value"])
]
if self.as_html:
# For the html output, wrap the values in li tags and put it inside an ul tag.
# The selectboxes formatter handles all values at the same time,
# so handle the full html formatting here.
return format_html(
"<ul>{values}</ul>",
values=format_html_join(
"",
"<li>{}</li>",
((selected_label,) for selected_label in selected_labels),
),
)
return self.multiple_separator.join(selected_labels)


Expand Down
Loading

0 comments on commit 6b715c6

Please sign in to comment.