From 3d0de7490b62876ea99c61d638c9c93eb7505a6d Mon Sep 17 00:00:00 2001 From: Patrick Cartlidge Date: Mon, 6 Nov 2023 13:15:14 +0000 Subject: [PATCH] Update initialisation script snippet in layouts For govuk-frontend v5, there now needs to be additional class added to the `body` tag to indicate that the components are supported. This class is `govuk-frontend-supported` and is added if the browser supports JS of type `module` (which is the new browser target for govuk-frontend). The script tag is directly taken from the documentation. --- .../components/_layout_for_admin.html.erb | 2 +- .../components/_layout_for_public.html.erb | 2 +- .../layouts/govuk_publishing_components/application.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb b/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb index 7d02bda7a7..191cc00962 100644 --- a/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +++ b/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb @@ -19,7 +19,7 @@ <%= javascript_tag nonce: true do -%> - document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled'); + document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : ''); <% end -%> <%= yield %> <%= javascript_include_tag "application" %> diff --git a/app/views/govuk_publishing_components/components/_layout_for_public.html.erb b/app/views/govuk_publishing_components/components/_layout_for_public.html.erb index 7799c669ec..36f24bfeff 100644 --- a/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +++ b/app/views/govuk_publishing_components/components/_layout_for_public.html.erb @@ -97,7 +97,7 @@ <%= tag.body class: body_css_classes do %> <%= javascript_tag nonce: true do -%> - document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled'); + document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : ''); <% end -%> <%= render "govuk_publishing_components/components/cookie_banner", layout_helper.cookie_banner_data %> <%= render "govuk_publishing_components/components/skip_link", { diff --git a/app/views/layouts/govuk_publishing_components/application.html.erb b/app/views/layouts/govuk_publishing_components/application.html.erb index 250bc32a1d..bb156d1483 100644 --- a/app/views/layouts/govuk_publishing_components/application.html.erb +++ b/app/views/layouts/govuk_publishing_components/application.html.erb @@ -47,7 +47,7 @@ <%= javascript_tag nonce: true do -%> - document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled'); + document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : ''); <% end -%> <%= yield :body %>