From fa5ccd39d2107ed7f118c9b7fdd4583b046359bd Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:52:44 +0000 Subject: [PATCH] BREAKING: Use component wrapper on search component Breaking as it: - Renames the `id` option to `label_id` - Renames `data_attributes` to `button_data_attributes` --- CHANGELOG.md | 1 + .../components/_search.html.erb | 38 +++++++++---------- .../components/docs/search.yml | 4 +- .../components/layout_header/_search.html.erb | 2 +- spec/components/search_spec.rb | 21 +--------- 5 files changed, 22 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 394a714feb..a0c8ed5c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * **BREAKING** Change devolved nations component type option ([PR #4535](https://github.com/alphagov/govuk_publishing_components/pull/4535)) * **BREAKING** Add component wrapper helper to intervention component ([PR #4378](https://github.com/alphagov/govuk_publishing_components/pull/4378)) * **BREAKING** Add component wrapper helper to the list component ([PR #4441](https://github.com/alphagov/govuk_publishing_components/pull/4441)) +* **BREAKING** Add component wrapper helper to the search component ([PR #4540](https://github.com/alphagov/govuk_publishing_components/pull/4540)) * Use component wrapper on subscription links ([PR #4525](https://github.com/alphagov/govuk_publishing_components/pull/4525)) * Use component wrapper on success alert component ([PR #4527](https://github.com/alphagov/govuk_publishing_components/pull/4527)) * Use component wrapper on summary card component ([PR #4528](https://github.com/alphagov/govuk_publishing_components/pull/4528)) diff --git a/app/views/govuk_publishing_components/components/_search.html.erb b/app/views/govuk_publishing_components/components/_search.html.erb index 9f63d3fe6a..c1156a4afa 100644 --- a/app/views/govuk_publishing_components/components/_search.html.erb +++ b/app/views/govuk_publishing_components/components/_search.html.erb @@ -7,7 +7,7 @@ aria_controls ||= nil button_text ||= t("components.search_box.search_button") correction_value = "off" if local_assigns[:disable_corrections] - id ||= "search-main-" + SecureRandom.hex(4) + label_id ||= "search-main-" + SecureRandom.hex(4) wrap_label_in_a_heading ||= false label_margin_bottom ||= nil label_size ||= nil @@ -19,21 +19,17 @@ size ||= "" value ||= "" - data_attributes ||= {} - - classes = %w[gem-c-search govuk-!-display-none-print] - classes << shared_helper.get_margin_top - classes << shared_helper.get_margin_bottom if local_assigns[:margin_bottom] - classes << "gem-c-search--large" if size == "large" - classes << "gem-c-search--large-on-mobile" if size == "large-mobile" - classes << "gem-c-search--homepage" if homepage - classes << "gem-c-search--no-border" if no_border - if local_assigns[:on_govuk_blue].eql?(true) - classes << "gem-c-search--on-govuk-blue" - else - classes << "gem-c-search--on-white" - end - classes << "gem-c-search--separate-label" if local_assigns.include?(:inline_label) or local_assigns.include?(:label_size) + component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) + component_helper.add_data_attribute({ module: "gem-toggle-input-class-on-focus" }) + component_helper.add_class("gem-c-search govuk-!-display-none-print") + component_helper.add_class(shared_helper.get_margin_top) + component_helper.add_class("gem-c-search--large") if size == "large" + component_helper.add_class("gem-c-search--large-on-mobile") if size == "large-mobile" + component_helper.add_class("gem-c-search--homepage") if homepage + component_helper.add_class("gem-c-search--no-border") if no_border + component_helper.add_class("gem-c-search--on-govuk-blue") if local_assigns[:on_govuk_blue].eql?(true) + component_helper.add_class("gem-c-search--on-white") unless local_assigns[:on_govuk_blue].eql?(true) + component_helper.add_class("gem-c-search--separate-label") if local_assigns.include?(:inline_label) or local_assigns.include?(:label_size) label_classes = [] if (shared_helper.valid_heading_size?(label_size)) @@ -46,12 +42,12 @@ label_classes << label_custom_class if label_custom_class tag_label = capture do - tag.label(for: id, class: label_classes) do + tag.label(for: label_id, class: label_classes) do label_text end end %> -