Autofocus now optional for live_search

This change has been made because autofocus has been confusing
to users of screenreaders because they orient themselves by
what is in focus. Moving it when the page loads without warning
can cause confusion and mean they miss parts of the page
before the point focus has moved to.

So now we will only turn on autofocus if there are no other
elements in the page that need attention than the search box.
This commit is contained in:
Pea Tyczynska
2020-09-08 15:51:29 +01:00
committed by Tom Byers
parent fa54c0fec4
commit bd19b1171c

View File

@@ -1,21 +1,25 @@
{% from "components/textbox.html" import textbox %}
{% macro live_search(
target_selector=None,
show=False,
form=None,
label=None
label=None,
autofocus=False
) %}
{%- set search_label = label or form.search.label.text %}
{%- set param_extensions = {
"label": {"text": search_label},
"autocomplete": "off",
} %}
{% if autofocus %}
{% set x=param_extensions.__setitem__("attributes", {"data-module": "autofocus"}) %}
{% endif %}
{% if show %}
<div data-module="autofocus">
<div class="live-search js-header" data-module="live-search" data-targets="{{ target_selector }}">
{{ form.search(param_extensions={
"label": {"text": search_label},
"autocomplete": "off"
}) }}
{{ form.search(param_extensions=param_extensions) }}
<div role="region" aria-live="polite" class="live-search__status govuk-visually-hidden"></div>
</div>
</div>
{% endif %}
{% endmacro %}