Skip to content

Commit

Permalink
Extract a SkipLinkItemComponent (#3478)
Browse files Browse the repository at this point in the history
So that all skip links can use the same css classes

Fixes #3477
  • Loading branch information
jcoyne authored Jan 7, 2025
1 parent a386094 commit dcd30e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/components/blacklight/skip_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module Blacklight
class SkipLinkComponent < Blacklight::Component
def link_to_search
link_to t('blacklight.skip_links.search_field'), search_id, class: link_classes
render skip_link_item_component.new(text: t('blacklight.skip_links.search_field'), href: search_id)
end

def link_to_main
link_to t('blacklight.skip_links.main_content'), '#main-container', class: link_classes
render skip_link_item_component.new(text: t('blacklight.skip_links.main_content'), href: '#main-container')
end

def search_id
Expand All @@ -16,7 +16,11 @@ def search_id
'#q'
end

delegate :blacklight_config, to: :helpers
delegate :skip_link_item_component, to: :blacklight_config

def link_classes
Blacklight.deprecation.warn("Use SkipLinkItemComponent instead")
'visually-hidden-focusable rounded-bottom py-2 px-3'
end
end
Expand Down
18 changes: 18 additions & 0 deletions app/components/blacklight/skip_link_item_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Blacklight
class SkipLinkItemComponent < Blacklight::Component
def initialize(text:, href:)
@text = text
@href = href
end

def call
link_to @text, @href, class: link_classes
end

def link_classes
'd-inline-flex py-2 px-3'
end
end
end
2 changes: 1 addition & 1 deletion app/views/catalog/_search_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<% end %>

<% content_for(:skip_links) do -%>
<%= link_to t('blacklight.skip_links.first_result'), '#documents', class: 'd-inline-flex p-2 m-1' %>
<%= render Blacklight::SkipLinkItemComponent.new(text: t('blacklight.skip_links.first_result'), href: '#documents') %>
<% end %>

<% content_for(:container_header) do -%>
Expand Down
1 change: 1 addition & 0 deletions lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def initialized_default_configuration?
default_configuration do
property :logo_link, default: nil
property :skip_link_component, default: Blacklight::SkipLinkComponent
property :skip_link_item_component, default: Blacklight::SkipLinkItemComponent
property :header_component, default: Blacklight::HeaderComponent
property :full_width_layout, default: false

Expand Down

0 comments on commit dcd30e8

Please sign in to comment.