Skip to content

Commit 2e1cfab

Browse files
12rambaucholdgraf
andauthored
ENH: Add skip to main content button for a11y (#1019)
Co-authored-by: Chris Holdgraf <[email protected]>
1 parent 299d974 commit 2e1cfab

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/pydata_sphinx_theme/assets/styles/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $grid-breakpoints: (
3333
@import "./base/base";
3434

3535
// Major theme layout, skeleton, and whitespace
36+
@import "./sections/skip-link";
3637
@import "./sections/container";
3738
@import "./sections/announcement";
3839
@import "./sections/article";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************************
2+
* Rules for the UX/UI of skip navigation link btn. It's only visible to people
3+
* navigating with keyboard for accecibility purposes
4+
* ref: https://www.youtube.com/watch?v=VUR0I5mqq7I
5+
*/
6+
.skip-link {
7+
position: fixed;
8+
top: 0;
9+
left: 0;
10+
right: 0;
11+
text-align: center;
12+
background-color: var(--pst-color-background);
13+
color: var(--pst-color-link);
14+
padding: 0.5rem;
15+
translate: 0 -100%;
16+
transition: translate 150ms ease-in-out;
17+
z-index: $zindex-modal;
18+
border-bottom: 1px solid var(--pst-color-border);
19+
20+
&:focus {
21+
translate: 0;
22+
}
23+
}

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
{# set up with scrollspy to update the toc as we scroll #}
4747
{# ref: https://getbootstrap.com/docs/4.0/components/scrollspy/ #}
4848
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="180" data-default-mode="{{ default_mode }}">
49+
50+
{# A button hidden by default to help assistive devices quickly jump to main content #}
51+
{# ref: https://www.youtube.com/watch?v=VUR0I5mqq7I #}
52+
<a class="skip-link" href="#main-content">{{ _("Skip to main content") }}</a>
53+
4954
{%- endblock %}
5055

5156
{%- block content %}
@@ -84,7 +89,7 @@
8489
<div class="bd-sidebar-primary bd-sidebar{% if not sidebars %} hide-on-wide{% endif %}">
8590
{% include "sections/sidebar-primary.html" %}
8691
</div>
87-
<main class="bd-main">
92+
<main id="main-content" class="bd-main">
8893
{# Main content area #}
8994
{% block docs_main %}
9095
<div class="bd-content">

0 commit comments

Comments
 (0)