Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract a SkipLinkItemComponent #3478

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading