From 63b0fa461d516f529bd61b8501c89956c2956b97 Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Thu, 21 Nov 2024 09:36:26 -0500 Subject: [PATCH] Set search bar border rounded class for number of configured search fields --- .../blacklight/search_bar_component.html.erb | 6 ++--- .../blacklight/search_bar_component.rb | 6 +++++ .../blacklight/search_bar_component_spec.rb | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/components/blacklight/search_bar_component.html.erb b/app/components/blacklight/search_bar_component.html.erb index bb9f37355d..fd7f855400 100644 --- a/app/components/blacklight/search_bar_component.html.erb +++ b/app/components/blacklight/search_bar_component.html.erb @@ -22,12 +22,12 @@ <%= f.label @query_param, scoped_t('search.label'), class: 'visually-hidden' %> <% if autocomplete_path.present? %> - - <%= f.search_field @query_param, value: @q, placeholder: scoped_t('search.placeholder'), class: "search-q q form-control rounded-#{search_fields.length > 1 ? '0' : 'left'}", autofocus: @autofocus, aria: { label: scoped_t('search.label'), autocomplete: 'list', controls: 'autocomplete-popup' } %> + + <%= f.search_field @query_param, value: @q, placeholder: scoped_t('search.placeholder'), class: "search-q q form-control #{rounded_border_class}", autofocus: @autofocus, aria: { label: scoped_t('search.label'), autocomplete: 'list', controls: 'autocomplete-popup' } %> <% else %> - <%= f.search_field @query_param, value: @q, placeholder: scoped_t('search.placeholder'), class: "search-q q form-control rounded-#{search_fields.length > 1 ? '0' : 'left'}", autofocus: @autofocus, aria: { label: scoped_t('search.label') } %> + <%= f.search_field @query_param, value: @q, placeholder: scoped_t('search.placeholder'), class: "search-q q form-control #{rounded_border_class}", autofocus: @autofocus, aria: { label: scoped_t('search.label') } %> <% end %> <%= append %> diff --git a/app/components/blacklight/search_bar_component.rb b/app/components/blacklight/search_bar_component.rb index f2a4d60b51..0039ac8303 100644 --- a/app/components/blacklight/search_bar_component.rb +++ b/app/components/blacklight/search_bar_component.rb @@ -60,6 +60,12 @@ def advanced_search_enabled? blacklight_config.advanced_search.enabled end + def rounded_border_class + return 'rounded-0' if search_fields.length > 1 + + 'rounded-start' + end + private def blacklight_config diff --git a/spec/components/blacklight/search_bar_component_spec.rb b/spec/components/blacklight/search_bar_component_spec.rb index f9c890099a..c9a5c8f27b 100644 --- a/spec/components/blacklight/search_bar_component_spec.rb +++ b/spec/components/blacklight/search_bar_component_spec.rb @@ -10,6 +10,7 @@ let(:blacklight_config) do Blacklight::Configuration.new.configure do |config| config.view = { list: nil, abc: nil } + config.add_search_field('test_field', label: 'Test Field') end end @@ -79,4 +80,28 @@ expect(render.css("input[name='bar']")).to be_present end end + + context 'with one search field' do + subject(:render) { render_inline(instance) } + + it 'sets the rounded border class' do + expect(render.css('.rounded-start')).to be_present + end + end + + context 'with multiple search fields' do + subject(:render) { render_inline(instance) } + + let(:blacklight_config) do + Blacklight::Configuration.new.configure do |config| + config.view = { list: nil, abc: nil } + config.add_search_field('test_field', label: 'Test Field') + config.add_search_field('another_field', label: 'Another Field') + end + end + + it 'sets the rounded border class' do + expect(render.css('.rounded-0')).to be_present + end + end end