Skip to content

Commit

Permalink
Add component wrapper helper to date input component
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Jan 8, 2025
1 parent f4b230b commit 612ce50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
Expand All @@ -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", {
Expand All @@ -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", {
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 612ce50

Please sign in to comment.