Skip to content

Commit

Permalink
Add autocomplete to search index
Browse files Browse the repository at this point in the history
We've tried to add autocomplete to each site search input on GOV.UK.
When reviewing this we noticed that one of them was missed, the one on
https://www.gov.uk/search.

This commit corrects this by adding the component here.
  • Loading branch information
kevindew committed Dec 12, 2024
1 parent e9ca789 commit 4483a87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/views/search/_search_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
} %>
<% end %>

<%= render "govuk_publishing_components/components/search", {
<%= render "govuk_publishing_components/components/#{search_component}", {
inline_label: false,
label_text: label_text,
size: "large",
id: "search-main",
disable_corrections: true,
source_url: api_search_autocomplete_url(format: :json),
source_key: "suggestions",
} %>

<%= hidden_field_tag("filter_manual[]", params[:filter_manual]) if params[:filter_manual] %>
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,26 @@
expect(response).to redirect_to(destination)
end
end

context "when GOVUK_DISABLE_SEARCH_AUTOCOMPLETE is not set" do
it "renders the search autocomplete component" do
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: nil do
get :index

expect(response.body).to include("gem-c-search-with-autocomplete")
end
end
end

context "when GOVUK_DISABLE_SEARCH_AUTOCOMPLETE is set" do
it "renders the search component instead of the autocomplete component" do
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: "1" do
get :index

expect(response.body).not_to include("gem-c-search-with-autocomplete")
expect(response.body).to include("gem-c-search")
end
end
end
end
end

0 comments on commit 4483a87

Please sign in to comment.