Skip to content

Commit

Permalink
Merge pull request #3166 from projectblacklight/search-element
Browse files Browse the repository at this point in the history
Add search element
  • Loading branch information
marlo-longley authored Jun 4, 2024
2 parents 8a2c866 + c9031f2 commit 93be335
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
14 changes: 8 additions & 6 deletions app/components/blacklight/search/sidebar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<% facet_group_names.each do |groupname| %>
<% fields = facet_fields_in_group(groupname) %>
<%= render group_component_class.new(id: groupname, fields: fields, response: response) do |component| %>
<% component.with_body do %>
<%= render Blacklight::FacetComponent.with_collection(fields, response: response) %>
<search>
<% facet_group_names.each do |groupname| %>
<% fields = facet_fields_in_group(groupname) %>
<%= render group_component_class.new(id: groupname, fields: fields, response: response) do |component| %>
<% component.with_body do %>
<%= render Blacklight::FacetComponent.with_collection(fields, response: response) %>
<% end %>
<% end %>
<% end %>
<% end %>
</search>
70 changes: 36 additions & 34 deletions app/components/blacklight/search_bar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
<%= form_with url: @url, local: true, method: @method, class: @classes.join(' '), scope: @prefix, role: 'search', **@form_options do |f| %>
<%= render Blacklight::HiddenSearchStateComponent.new(params: @params) %>
<% if search_fields.length > 1 %>
<%= f.label :search_field, scoped_t('search_field.label'), class: 'sr-only visually-hidden' %>
<% end %>
<% before_input_groups.each do |input_group| %>
<%= input_group %>
<% end %>
<div class="input-group">
<%= prepend %>
<search>
<%= form_with url: @url, local: true, method: @method, class: @classes.join(' '), scope: @prefix, role: 'search', **@form_options do |f| %>
<%= render Blacklight::HiddenSearchStateComponent.new(params: @params) %>
<% if search_fields.length > 1 %>
<%= f.select(:search_field,
options_for_select(search_fields, h(@search_field)),
{},
title: scoped_t('search_field.title'),
class: "custom-select form-select search-field") %>
<% elsif search_fields.length == 1 %>
<%= f.hidden_field :search_field, value: search_fields.first.last %>
<%= f.label :search_field, scoped_t('search_field.label'), class: 'sr-only visually-hidden' %>
<% end %>
<%= f.label @query_param, scoped_t('search.label'), class: 'sr-only visually-hidden' %>
<% if autocomplete_path.present? %>
<auto-complete src="<%= autocomplete_path %>" for="autocomplete-popup" class="search-autocomplete-wrapper">
<%= 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' } %>
<ul id="autocomplete-popup" role="listbox" aria-label="<%= scoped_t('search.label') %>" hidden></ul>
</auto-complete>
<% 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') } %>
<% before_input_groups.each do |input_group| %>
<%= input_group %>
<% end %>
<div class="input-group">
<%= prepend %>
<%= append %>
<%= search_button || render(Blacklight::SearchButtonComponent.new(id: "#{@prefix}search", text: scoped_t('submit'))) %>
</div>
<% end %>
<% if search_fields.length > 1 %>
<%= f.select(:search_field,
options_for_select(search_fields, h(@search_field)),
{},
title: scoped_t('search_field.title'),
class: "custom-select form-select search-field") %>
<% elsif search_fields.length == 1 %>
<%= f.hidden_field :search_field, value: search_fields.first.last %>
<% end %>
<% if advanced_search_enabled? %>
<%= link_to t('blacklight.advanced_search.more_options'), @advanced_search_url, class: 'advanced_search btn btn-secondary'%>
<% end %>
<%= f.label @query_param, scoped_t('search.label'), class: 'sr-only visually-hidden' %>
<% if autocomplete_path.present? %>
<auto-complete src="<%= autocomplete_path %>" for="autocomplete-popup" class="search-autocomplete-wrapper">
<%= 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' } %>
<ul id="autocomplete-popup" role="listbox" aria-label="<%= scoped_t('search.label') %>" hidden></ul>
</auto-complete>
<% 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') } %>
<% end %>
<%= append %>
<%= search_button || render(Blacklight::SearchButtonComponent.new(id: "#{@prefix}search", text: scoped_t('submit'))) %>
</div>
<% end %>
<% if advanced_search_enabled? %>
<%= link_to t('blacklight.advanced_search.more_options'), @advanced_search_url, class: 'advanced_search btn btn-secondary'%>
<% end %>
</search>

0 comments on commit 93be335

Please sign in to comment.