Skip to content

Commit

Permalink
Add a skip link to the admin interface
Browse files Browse the repository at this point in the history
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
waiting-for-dev committed Jul 21, 2023
1 parent 2f45e3e commit 381c51b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
24 changes: 24 additions & 0 deletions admin/app/components/solidus_admin/skip_link/component.rb
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
2 changes: 2 additions & 0 deletions admin/app/components/solidus_admin/skip_link/component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en:
skip_link: Skip to content
3 changes: 2 additions & 1 deletion admin/app/views/layouts/solidus_admin/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>

<body>
<%= render component("skip_link").new(href: "#main") %>
<div class="fixed right-3 bottom-3 flex flex-col gap-3" role="alert">
<% flash.each do |key, message| %>
<%= render component("ui/toast").new(text: message, scheme: key == :error ? :error : :default) %>
Expand All @@ -22,7 +23,7 @@
">
<%= render component("sidebar").new(store: current_store) %>

<main class="
<main id="main" class="
col-start-2 col-end-4
lg:col-start-3 lg:col-end-12
py-6 px-4
Expand Down
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
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

0 comments on commit 381c51b

Please sign in to comment.