diff --git a/app/components/arclight/search_bar_component.html.erb b/app/components/arclight/search_bar_component.html.erb index ab1c8cbf8..13ecf9239 100644 --- a/app/components/arclight/search_bar_component.html.erb +++ b/app/components/arclight/search_bar_component.html.erb @@ -1,6 +1,8 @@ <%= render(Blacklight::SearchBarComponent.new( **@kwargs, - params: @params.merge(f: (@params[:f] || {}).except(:collection)))) do |c| %> + params: @params.merge(f: (@params[:f] || {}).except(:collection)), + q: @q, + search_field: @search_field)) do |c| %> <% c.with_before_input_group do %>
diff --git a/app/components/arclight/search_bar_component.rb b/app/components/arclight/search_bar_component.rb index a15a6712a..0114f26f1 100644 --- a/app/components/arclight/search_bar_component.rb +++ b/app/components/arclight/search_bar_component.rb @@ -25,7 +25,7 @@ def within_collection_options end def collection_name - @collection_name ||= Array(@params.dig(:f, :collection)).first || + @collection_name ||= Array(@params.dig(:f, :collection)).reject(&:empty?).first || helpers.current_context_document&.collection_name end end diff --git a/spec/features/fielded_search_results_spec.rb b/spec/features/fielded_search_results_spec.rb index baf601e3a..3ce6c8089 100644 --- a/spec/features/fielded_search_results_spec.rb +++ b/spec/features/fielded_search_results_spec.rb @@ -129,4 +129,11 @@ end end end + + describe 'search box scope retention' do + it 'retains the selected field on the search results page' do + visit search_catalog_path q: 'root', search_field: 'name' + expect(page).to have_select 'search_field', selected: 'Name' + end + end end diff --git a/spec/features/search_results_spec.rb b/spec/features/search_results_spec.rb index b713c3ee9..d1ff1bfec 100644 --- a/spec/features/search_results_spec.rb +++ b/spec/features/search_results_spec.rb @@ -9,6 +9,11 @@ expect(page).to have_css '.index_title', text: /A brief account/ end + it 'retains the search query in the search box' do + visit search_catalog_path q: 'papers', search_field: 'all_fields' + expect(page).to have_css 'input#q[value="papers"]' + end + it 'renders the expected metadata for a collection' do visit search_catalog_path q: '', search_field: 'all_fields'