Skip to content

Commit 49b0e5b

Browse files
committed
Enable auto-focus on flash messages
Flash messages were rendered with disableAutoFocus set to true. Enable auto-focus by default so the banner receives focus and the yellow focus border is shown when a flash message appears (e.g. after adding a special appointment note).
1 parent cdfadee commit 49b0e5b

5 files changed

Lines changed: 23 additions & 45 deletions

File tree

manage_breast_screening/core/jinja2/layout-app.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@
6161
{% block content %}
6262
{% block flash_messages %}
6363
{% set info_notification_params = get_notification_banner_params(
64-
request, message_type='info',
65-
disable_auto_focus=disable_auto_focus|default(true)
64+
request, message_type='info'
6665
) %}
6766

6867
{% set success_notification_params = get_notification_banner_params(
69-
request, message_type='success',
70-
disable_auto_focus=disable_auto_focus|default(true)
68+
request, message_type='success'
7169
) %}
7270

7371
{% set warning_notification_params = get_notification_banner_params(
74-
request, message_type='warning',
75-
disable_auto_focus=disable_auto_focus|default(true)
72+
request, message_type='warning'
7673
) %}
7774

7875
{% if success_notification_params %}

manage_breast_screening/core/jinja2/workflow_step.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
</div>
2222
<div class="nhsuk-grid-column-three-quarters app-workflow-container__main" id="workflow_content">
2323
{% set info_notification_params = get_notification_banner_params(
24-
request, message_type='info',
25-
disable_auto_focus=disable_auto_focus|default(true)
24+
request, message_type='info'
2625
) %}
2726

2827
{% set success_notification_params = get_notification_banner_params(
29-
request, message_type='success',
30-
disable_auto_focus=disable_auto_focus|default(true)
28+
request, message_type='success'
3129
) %}
3230

3331
{% set warning_notification_params = get_notification_banner_params(
34-
request, message_type='warning',
35-
disable_auto_focus=disable_auto_focus|default(true)
32+
request, message_type='warning'
3633
) %}
3734

3835
{% if success_notification_params %}

manage_breast_screening/core/template_helpers.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def message_with_heading(heading: str, html=None) -> SafeString:
8686

8787

8888
def get_notification_banner_params(
89-
request, message_type="info", disable_auto_focus=True
89+
request, message_type="info", disable_auto_focus=False
9090
):
9191
levels = {"info": INFO, "warning": WARNING, "success": SUCCESS}
9292
try:
@@ -102,18 +102,14 @@ def get_notification_banner_params(
102102

103103
message = messages[0].message
104104

105+
params = {"type": message_type}
106+
if disable_auto_focus:
107+
params["disableAutoFocus"] = True
105108
if _is_safe_message(message):
106-
return {
107-
"html": Markup(message),
108-
"type": message_type,
109-
"disableAutoFocus": disable_auto_focus,
110-
}
109+
params["html"] = Markup(message)
111110
else:
112-
return {
113-
"text": message,
114-
"type": message_type,
115-
"disableAutoFocus": disable_auto_focus,
116-
}
111+
params["text"] = message
112+
return params
117113

118114

119115
def _user_name_and_role_item(user):

manage_breast_screening/core/tests/jinja2/test_base_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_success_banner(jinja_env):
5050

5151
assertInHTML(
5252
"""
53-
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner" data-disable-auto-focus="true">
53+
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner">
5454
<div class="nhsuk-notification-banner__header">
5555
<h2 class="nhsuk-notification-banner__title" id="nhsuk-notification-banner-title">Success</h2>
5656
</div>
@@ -80,7 +80,7 @@ def test_success_banner_with_html_message(jinja_env):
8080

8181
assertInHTML(
8282
"""
83-
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner" data-disable-auto-focus="true">
83+
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner">
8484
<div class="nhsuk-notification-banner__header">
8585
<h2 class="nhsuk-notification-banner__title" id="nhsuk-notification-banner-title">Success</h2>
8686
</div>

manage_breast_screening/core/tests/test_template_helpers.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,15 @@ def dummy_request(self):
8080

8181
def test_info_banner_with_text_message(self, dummy_request):
8282
result = get_notification_banner_params(dummy_request, "info")
83-
assert result == {"text": "abc", "type": "info", "disableAutoFocus": True}
83+
assert result == {"text": "abc", "type": "info"}
8484

8585
def test_success_banner_with_text_message(self, dummy_request):
8686
result = get_notification_banner_params(dummy_request, "success")
87-
assert result == {"text": "def", "type": "success", "disableAutoFocus": True}
87+
assert result == {"text": "def", "type": "success"}
8888

8989
def test_warning_banner_with_text_message(self, dummy_request):
9090
result = get_notification_banner_params(dummy_request, "warning")
91-
assert result == {
92-
"text": "warning!",
93-
"type": "warning",
94-
"disableAutoFocus": True,
95-
}
91+
assert result == {"text": "warning!", "type": "warning"}
9692

9793
def test_invalid_message_type(self, dummy_request):
9894
with pytest.raises(
@@ -101,11 +97,11 @@ def test_invalid_message_type(self, dummy_request):
10197
):
10298
get_notification_banner_params(dummy_request, "error")
10399

104-
def test_autofocus_param(self, dummy_request):
100+
def test_autofocus_can_be_disabled(self, dummy_request):
105101
result = get_notification_banner_params(
106-
dummy_request, "info", disable_auto_focus=False
102+
dummy_request, "info", disable_auto_focus=True
107103
)
108-
assert result == {"text": "abc", "type": "info", "disableAutoFocus": False}
104+
assert result == {"text": "abc", "type": "info", "disableAutoFocus": True}
109105

110106

111107
class TestNotificationBannerParamsForHTMLMessages:
@@ -120,16 +116,8 @@ def dummy_request(self):
120116

121117
def test_info_banner_with_html_message(self, dummy_request):
122118
result = get_notification_banner_params(dummy_request, "info")
123-
assert result == {
124-
"html": mark_safe("abc"),
125-
"type": "info",
126-
"disableAutoFocus": True,
127-
}
119+
assert result == {"html": mark_safe("abc"), "type": "info"}
128120

129121
def test_success_banner_with_html_message(self, dummy_request):
130122
result = get_notification_banner_params(dummy_request, "success")
131-
assert result == {
132-
"html": mark_safe("def"),
133-
"type": "success",
134-
"disableAutoFocus": True,
135-
}
123+
assert result == {"html": mark_safe("def"), "type": "success"}

0 commit comments

Comments
 (0)