From 45c1f9356237d7217de82c76a068407c640b839b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 29 Sep 2023 22:30:34 +0200 Subject: [PATCH] Add a link to skip to the main content While people using screen readers already have keyboard shortcuts to jump to the
tag, there are people who navigate the page with the keyboard using just the tab key, and for them, this link provides a way to save time and start reading the main content instead of having to manually go through all the navigation links every time a new page is loaded. Note that we had to add an additional `width: 0` rule because Foundation's `element-invisible` would apply `1px` and the test checking for `visible: :hidden` would faile. --- .../layout/skip_to_main_content.scss | 22 +++++++++++++++++++ .../skip_to_main_content_component.html.erb | 3 +++ .../layout/skip_to_main_content_component.rb | 2 ++ app/views/layouts/admin.html.erb | 3 ++- app/views/layouts/application.html.erb | 3 ++- app/views/layouts/dashboard.html.erb | 3 ++- app/views/layouts/devise.html.erb | 3 ++- app/views/layouts/management.html.erb | 3 ++- config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + public/403.html | 2 +- public/404.html | 2 +- public/422.html | 2 +- public/500.html | 2 +- spec/rails_helper.rb | 2 ++ spec/system/home_spec.rb | 16 ++++++++++++++ 16 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 app/assets/stylesheets/layout/skip_to_main_content.scss create mode 100644 app/components/layout/skip_to_main_content_component.html.erb create mode 100644 app/components/layout/skip_to_main_content_component.rb diff --git a/app/assets/stylesheets/layout/skip_to_main_content.scss b/app/assets/stylesheets/layout/skip_to_main_content.scss new file mode 100644 index 000000000..dcfc3db78 --- /dev/null +++ b/app/assets/stylesheets/layout/skip_to_main_content.scss @@ -0,0 +1,22 @@ +.skip-to-main-content { + @include grid-column-gutter; + + a { + &:not(:focus) { + @include element-invisible; + width: 0 !important; + } + + &:focus { + @include body-colors; + + $outline-size: $focus-inner-width + $focus-middle-width + $focus-outer-width; + + padding: 0.4rem; + position: absolute; + $global-left: $outline-size; + top: $outline-size; + z-index: 1000; + } + } +} diff --git a/app/components/layout/skip_to_main_content_component.html.erb b/app/components/layout/skip_to_main_content_component.html.erb new file mode 100644 index 000000000..e22492693 --- /dev/null +++ b/app/components/layout/skip_to_main_content_component.html.erb @@ -0,0 +1,3 @@ +
+ <%= link_to t("layouts.skip_to_main_content"), "#main" %> +
diff --git a/app/components/layout/skip_to_main_content_component.rb b/app/components/layout/skip_to_main_content_component.rb new file mode 100644 index 000000000..2cd600df3 --- /dev/null +++ b/app/components/layout/skip_to_main_content_component.rb @@ -0,0 +1,2 @@ +class Layout::SkipToMainContentComponent < ApplicationComponent +end diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index c84b71711..182fabd69 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -7,6 +7,7 @@ + <%= render Layout::SkipToMainContentComponent.new %> <%= render Layout::AdminHeaderComponent.new(current_user) %>