From 612ce50557349138d04e8cf3429043feb071ec0f Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:05:37 +0000 Subject: [PATCH] Add component wrapper helper to date input component --- .../components/_date_input.html.erb | 13 ++++++++----- .../components/docs/date_input.yml | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/views/govuk_publishing_components/components/_date_input.html.erb b/app/views/govuk_publishing_components/components/_date_input.html.erb index 38a76668ea..214b9c96cf 100644 --- a/app/views/govuk_publishing_components/components/_date_input.html.erb +++ b/app/views/govuk_publishing_components/components/_date_input.html.erb @@ -16,9 +16,7 @@ describedby ||= nil has_error ||= error_message || error_items.any? - css_classes = %w(gem-c-date-input govuk-date-input) - form_group_css_classes = %w(govuk-form-group) - form_group_css_classes << "govuk-form-group--error" if has_error + date_css_classes = %w(gem-c-date-input govuk-date-input) hint_id = "hint-#{SecureRandom.hex(4)}" error_id = "error-#{SecureRandom.hex(4)}" @@ -31,9 +29,14 @@ aria_described_by << describedby if describedby aria_described_by = aria_described_by.join(" ") end + + component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) + component_helper.add_class("govuk-form-group") + component_helper.add_class("govuk-form-group--error") if has_error + %> -<%= content_tag :div, class: form_group_css_classes do %> +<%= tag.div(**component_helper.all_attributes) do %> <% fieldset_content = capture do %> <% if hint %> <%= render "govuk_publishing_components/components/hint", { @@ -51,7 +54,7 @@ } %> <% end %> - <%= tag.div class: css_classes, id: id do %> + <%= tag.div class: date_css_classes, id: id do %> <% items.each do |item| %> <%= tag.div class: "govuk-date-input__item" do %> <%= render "govuk_publishing_components/components/input", { diff --git a/app/views/govuk_publishing_components/components/docs/date_input.yml b/app/views/govuk_publishing_components/components/docs/date_input.yml index 2039682b85..cd44c86b49 100644 --- a/app/views/govuk_publishing_components/components/docs/date_input.yml +++ b/app/views/govuk_publishing_components/components/docs/date_input.yml @@ -1,5 +1,6 @@ name: Form date input description: Use the date input component to help users enter a memorable date or one they can easily look up. +uses_component_wrapper_helper: true accessibility_criteria: | Inputs in the component must: