-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a skip link to the admin interface
This fulfills WCAG 2.0 guideline 2.4.1 (Bypass Blocks) [1] for the sidebar navigation in the admin interface, jumping to the main content area. [1] https://www.w3.org/TR/2008/REC-WCAG20-20081211/#navigation-mechanisms-skip
- Loading branch information
1 parent
2f45e3e
commit 381c51b
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# Skip to content link | ||
class SolidusAdmin::SkipLink::Component < SolidusAdmin::BaseComponent | ||
# @param href [String] the href attribute for the skip link | ||
def initialize(href:) | ||
@href = href | ||
end | ||
|
||
def call | ||
link_to t(".skip_link"), | ||
@href, | ||
class: %{ | ||
sr-only | ||
focus:not-sr-only | ||
inline-block | ||
focus:p-2 | ||
focus:absolute | ||
body-small | ||
text-white | ||
bg-black | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
en: | ||
skip_link: Skip to content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
admin/spec/components/previews/solidus_admin/skip_link/component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
# @component "skip_link" | ||
class SolidusAdmin::SkipLink::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
# Click on the "Preview" window area and press "Tab" to see the skip link | ||
def overview | ||
render current_component.new(href: "#") | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
admin/spec/components/solidus_admin/skip_link/component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::SkipLink::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
end |