diff --git a/app/assets/builds/blacklight.css b/app/assets/builds/blacklight.css index 336544e85..bdfb0af8e 100644 --- a/app/assets/builds/blacklight.css +++ b/app/assets/builds/blacklight.css @@ -409,12 +409,6 @@ main { background: transparent url('data:image/svg+xml,%3csvg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash-square" viewBox="0 0 16 16"%3e%3cpath d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z" /%3e%3cpath d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8z" /%3e%3c/svg%3e') center/1em auto no-repeat; } -/* Facet browse pages & modals --------------------------------------------------- */ -.facet-filters:not(:has(*)) { - display: none; -} - /* Search History */ .search-history { --bl-history-filter-name-color: var(--bs-secondary-color); diff --git a/app/assets/stylesheets/blacklight/_facets.scss b/app/assets/stylesheets/blacklight/_facets.scss index d8445ac46..82caf7dd1 100644 --- a/app/assets/stylesheets/blacklight/_facets.scss +++ b/app/assets/stylesheets/blacklight/_facets.scss @@ -205,9 +205,3 @@ $facet-toggle-height: $facet-toggle-width !default; $facet-toggle-width auto no-repeat; } } - -/* Facet browse pages & modals --------------------------------------------------- */ -.facet-filters:not(:has(*)) { - display: none; -} diff --git a/app/components/blacklight/search/facet_filters_component.html.erb b/app/components/blacklight/search/facet_filters_component.html.erb new file mode 100644 index 000000000..b1ac1acf3 --- /dev/null +++ b/app/components/blacklight/search/facet_filters_component.html.erb @@ -0,0 +1,4 @@ +
+ <%= render Blacklight::Search::FacetSuggestInput.new(facet: facet, presenter: presenter) %> + <%= render 'facet_index_navigation' if render_index_navigation? %> +
diff --git a/app/components/blacklight/search/facet_filters_component.rb b/app/components/blacklight/search/facet_filters_component.rb new file mode 100644 index 000000000..31e62d3e0 --- /dev/null +++ b/app/components/blacklight/search/facet_filters_component.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Blacklight::Search + class FacetFiltersComponent < Blacklight::Component + # @param [Blacklight::FacetFieldPresenter] presenter + def initialize(presenter:, classes: 'facet-filters card card-body bg-light p-3 mb-3 border-0') + @presenter = presenter + @classes = classes + end + + def facet + @presenter.facet_field + end + + attr_reader :classes, :presenter + + delegate :display_facet, to: :presenter + + def render? + facet.suggest != false || render_index_navigation? + end + + def render_index_navigation? + facet.index_range && display_facet.index? + end + end +end diff --git a/app/views/catalog/facet.html.erb b/app/views/catalog/facet.html.erb index 3b6640a68..3ace5ba39 100644 --- a/app/views/catalog/facet.html.erb +++ b/app/views/catalog/facet.html.erb @@ -1,10 +1,7 @@ <%= render Blacklight::System::ModalComponent.new do |component| %> <% component.with_title { facet_field_label(@facet.key) } %> -
- <%= render Blacklight::Search::FacetSuggestInput.new(facet: @facet, presenter: @presenter) %> - <%= render partial: 'facet_index_navigation' if @facet.index_range && @display_facet.index? %> -
+ <%= render Blacklight::Search::FacetFiltersComponent.new(presenter: @presenter) %>
<%= render :partial=>'facet_pagination' %> diff --git a/spec/views/catalog/facet.html.erb_spec.rb b/spec/views/catalog/facet.html.erb_spec.rb index bdb981543..ead6fd4f7 100644 --- a/spec/views/catalog/facet.html.erb_spec.rb +++ b/spec/views/catalog/facet.html.erb_spec.rb @@ -5,13 +5,15 @@ let(:blacklight_config) { Blacklight::Configuration.new } let(:component) { instance_double(Blacklight::FacetComponent) } let(:facet_suggest_input) { instance_double(Blacklight::Search::FacetSuggestInput) } + let(:facet_filters) { instance_double(Blacklight::Search::FacetFiltersComponent) } before do allow(Blacklight::FacetComponent).to receive(:new).and_return(component) - allow(Blacklight::Search::FacetSuggestInput).to receive(:new).and_return(facet_suggest_input) + allow(Blacklight::Search::FacetFiltersComponent).to receive(:new).and_return(facet_filters) + allow(view).to receive(:render).and_call_original allow(view).to receive(:render).with(component) - allow(view).to receive(:render).with(facet_suggest_input) + allow(view).to receive(:render).with(facet_filters) blacklight_config.add_facet_field 'xyz', label: "Facet title" allow(view).to receive(:blacklight_config).and_return(blacklight_config) @@ -25,9 +27,9 @@ expect(rendered).to have_css 'h1', text: "Facet title" end - it "renders the facet suggest input" do + it "renders the facet filters" do render - expect(view).to have_received(:render).with(facet_suggest_input) + expect(view).to have_received(:render).with(facet_filters) end it "renders facet pagination" do