Skip to content

Commit 97f939b

Browse files
gabalafoudrammock12rambaugresavagetgresavage
authored
Keyboard handlers to open and close mobile sidebars (#1585)
* Consistent focus ring (first pass) (#1549) * wip * Style focus state in header nav * update focus ring style on all focussable elements * simplify * fix links in mobile sidebar overlay * put focus rings around a few more focusable elements * polish * update comment * review * better align focus ring on collapsible admonitions * comment and simplify sphinx-togglebutton focus ring * make css override more explicit * Fix SD link-card focus ring and on homepage, bring links inside card * Update docs/index.md --------- Co-authored-by: Daniel McCloy <[email protected]> * Resolve current sidebar link notch and focus ring (#1561) * Fix sidebar current notch * focus-ring-radius * missed a spot 0.125rem * keep focus ring on top * Restyle Sphinx Design tabs (#1555) * restyle sphinx design tabs * increase panel border radius * increase line height, zero padding-y * use shadow variable * Update src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss * Update src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss * Fix tabbed panel colors (#1567) * update feature focus (#1569) * docs: add instructions for custom SVG icons (#1490) * docs: add instructions for custom SVG icons * docs: minor tweaks in SVG icon instructions * docs: some more tweaks to SVG icon instructions * Update docs/user_guide/header-links.rst Co-authored-by: Rambaud Pierrick <[email protected]> * Change literalinclude to code-block in header links * Update docs/user_guide/header-links.rst Co-authored-by: Daniel McCloy <[email protected]> * Update docs/user_guide/header-links.rst * Update docs/user_guide/header-links.rst * Update docs/user_guide/header-links.rst * Update docs/user_guide/header-links.rst * Update docs/user_guide/header-links.rst --------- Co-authored-by: tgresavage <[email protected]> Co-authored-by: Rambaud Pierrick <[email protected]> Co-authored-by: Daniel McCloy <[email protected]> * fix: make table background transparent (#1546) * fix: make table background transparent * fix: make table background transparent * fix: add color-theme option to html tag (#1536) * Silence warnings (#1542) * avoid webpack warning during asset compile * avoid frozen modules warning during import * try to make jupyterlite quieter * add config option to silence warnings * fix tests * add docs * hide conditional warning logic in utils * bump: 0.14.2 → 0.14.3 * chore: back to dev * docs: add the list of component using a directive (#1476) * fix: create the component list automatically * fix: read the first comment as documentation * docs: add disclaimer on .html suffix * docs: document every component with a simple one liner * fix: use regex to identify comments * update component branch (#15) * Change default logo alt text (#1472) * Default logo alt text only if no extra text * change default logo * use docstitle as default logo alt text * update docs to reflect change * Apply suggestions from code review Co-authored-by: Daniel McCloy <[email protected]> * use string formatting operator * Update docs/user_guide/branding.rst * docs fixes * Update docs/user_guide/branding.rst * add test * Update pyproject.toml * revert to original --------- Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: Rambaud Pierrick <[email protected]> * chore(i18n) catalan (#1488) i18n: Translate sphinx.po in ca 100% translated source file: 'sphinx.po' on 'ca'. Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com> * Build(deps): Bump postcss and css-loader (#1494) Bumps [postcss](https://github.com/postcss/postcss) to 8.4.31 and updates ancestor dependency [css-loader](https://github.com/webpack-contrib/css-loader). These dependencies need to be updated together. Updates `postcss` from 8.4.21 to 8.4.31 - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](postcss/postcss@8.4.21...8.4.31) Updates `css-loader` from 3.6.0 to 6.8.1 - [Release notes](https://github.com/webpack-contrib/css-loader/releases) - [Changelog](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md) - [Commits](webpack-contrib/css-loader@v3.6.0...v6.8.1) --- updated-dependencies: - dependency-name: postcss dependency-type: indirect - dependency-name: css-loader dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Revert "Build(deps): Bump postcss and css-loader" (#1509) Revert "Build(deps): Bump postcss and css-loader (#1494)" This reverts commit 185a37a. * Update pst docs buttons (#1502) * call them button-links * copy edit * docs: link back to GitHub from PyPI metadata (#1504) This will add a "Source" link in the PyPI page. * navigation_with_keys = False (#1503) * navigation_with_keys = False * None -> False * Apply suggestions from code review --------- Co-authored-by: Daniel McCloy <[email protected]> * fix: convert "stable" to actual version number (#1512) * convert "stable" to actual version number * fix tests re: navigation_with_keys * try bumping autoapi * refactor: use nbsphinx as the default execution lib (#1482) * refactor: use nbsphinx as the default execution lib * add nbstripout to the pre-commits' * add pandoc to the readthedocs deps * refactor: clean the notebook * move the example to the correct folder * fix: solve link issue * install pandoc in the test environment * fix: display of large table in executed cells * avoid Userwarnings from matplotlib * hide the matplotlib wrning management cell * Update readthedocs.yml * build: use pandoc_binary to install pandoc * docs: add reference to pandoc in the setup * update docs * remove pypandoc_binary * Update pyproject.toml Co-authored-by: gabalafou <[email protected]> * ci: use back setup-pandoc * Trigger CI build --------- Co-authored-by: Gabriel Fouasnon <[email protected]> * BUG - Clear alt_text in conf.py (#1471) * comment out alt_text in conf.py * set alt_text to empty string * remove alt_text from conf.py * fix: use 12rambau fork until it's merged with nikeee repo (#1517) * deps: drop support for Sphinx 5 (#1516) * remove ref to myst-nb * update minimal supported version of sphinx * Fix: (webpack.config.js) css-loader API change (#1508) * Fix: (webpack.config.js) css-loader API change The build was broken in <https://github.com/pydata/pydata-sphinx-theme/commit/185a37aa36820f77bffa4c87a772092e9e7cc380>/<https://github.com/pydata/pydata-sphinx-theme/pull/1494>. This change fixes the build, and it seems to be in accordance with the current API as described at <https://github.com/webpack-contrib/css-loader/blob/c6f36cf91ac61743a70e81cfb077faa0f8730ebe/README.md#boolean>. Closes <#1507>. * dedup * restore version bump --------- Co-authored-by: Daniel McCloy <[email protected]> * Fix duplicate HTML IDs (#1425) * Fix duplicate HTML IDs * fix tests * Do not animate the version admonitions colors. (#1424) Otherwise a delay has to be added to the accessibility color contrast checks, to wait for the colors to fully transition. * BUG - Remove redundant ARIA in breadcrumb navigation (#1426) * style(i18n): French Typo fixed (#1430) * Add the ability to add a center section to the footer (#1432) * Add a center section for the footer * Add docs for footer_center * Add a test site for the center footer * test it in our own docs * remove new test site * add footer test --------- Co-authored-by: Daniel McCloy <[email protected]> * Build(deps): Bump actions/checkout from 3 to 4 (#1433) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add dropdown_text argument to generate_header_nav_html (#1423) * Add dropdown_text argument to generate_header_nav_html * Add a test, fix typo in theme.conf and remove header_dropdown_text from docs/conf.py * fixed? --------- Co-authored-by: Daniel McCloy <[email protected]> * fix: rollback ref and Id changes (#1438) * bump: version 0.13.3 → 0.14.0 (#1440) * bump version * update version switcher * back to dev * fix: change the z-index of the dropdown (#1442) In order to be on top of the primary sidebar on small screens. * fix: set the same background for dark/light (#1443) * fix: set the same background for dark/light et the same background color for all state of the search field. It is currently only applied when hovered * fix: wrong css selector * Update src/pydata_sphinx_theme/assets/styles/components/_search.scss * Update src/pydata_sphinx_theme/assets/styles/components/_search.scss * Fix duplicate HTML IDs * fix tests * unique_html_id * backwards-compat generate_header_nav_html * feedback review * update fixture * ughhhh...caching * code cleanup * fix test snapshot * put comment inside def --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Denis Bitouzé <[email protected]> Co-authored-by: Stuart Mumford <[email protected]> Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alenka Frim <[email protected]> Co-authored-by: Rambaud Pierrick <[email protected]> * chore: build the devcontainer automatically in codespace (#1483) * chore: build the devcontainer automaticallyin codespace * refactor: lint * add pandoc to the environment * Fix font color in search input box (#1524) * Fix color * Use --pst-color-text-base * docs: add DecentralChain (#1528) Co-authored-by: jourlez <[email protected]> * Updates for file src/pydata_sphinx_theme/locale/en/LC_MESSAGES/sphinx.po in ru [Manual Sync] (#1527) i18n: Translate sphinx.po in ru [Manual Sync] 96% of minimum 20% translated source file: 'sphinx.po' on 'ru'. Sync of partially translated files: untranslated content is included with an empty translation or source language content depending on file format Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com> * ignore transient errors in windows build CI (#1520) * use warning list * clean up notebook * refactor to pass on all platforms? * simplify * fix logic * iterate backwards * fix plaform detection? also don't log unnecessarily�[H * ignore empty string warnings * remove notebook metawarning * Revert "remove notebook metawarning" This reverts commit 42f4672. * try again * debug the mysterious empty warning * escape color codes * import * triage by intermittency, not by platform; better var names * simplify * fix list.remove * undo what I broke * Update tests/utils/check_warnings.py * refactor: remove extention on component set-up (#1529) * use event.key for search shortcut (#1525) * use event.key for search shortcut * suggestions from review * caps lock --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: gabalafou <[email protected]> Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ned Batchelder <[email protected]> Co-authored-by: Adam Porter <[email protected]> Co-authored-by: Denis Bitouzé <[email protected]> Co-authored-by: Stuart Mumford <[email protected]> Co-authored-by: Alenka Frim <[email protected]> Co-authored-by: Harutaka Kawamura <[email protected]> Co-authored-by: jourlez <[email protected]> * fix: use a directive instead of raw html * fix: make links externals * fix: set reference in paragraphs * fix: missing parameter * fix: use the stem for the component name * refactor: remove never used variables * standardize component descriptions --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: gabalafou <[email protected]> Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ned Batchelder <[email protected]> Co-authored-by: Adam Porter <[email protected]> Co-authored-by: Denis Bitouzé <[email protected]> Co-authored-by: Stuart Mumford <[email protected]> Co-authored-by: Alenka Frim <[email protected]> Co-authored-by: Harutaka Kawamura <[email protected]> Co-authored-by: jourlez <[email protected]> * fix: primer link in docs (#1556) * docs: add data-content (#1559) Reproduce the change made in Sphinx 7 sphinx-doc/sphinx@8e730ae#diff-a5066e933cbf65adc46e0d1ab9a0b44e0a53ca64cc95dca7e6aa902aed6bd468R105 * Obviate background-from-color-variable (#1558) * Obviate background-from-color-variable * backwards compatibility --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: gresavage <[email protected]> Co-authored-by: tgresavage <[email protected]> Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: gabalafou <[email protected]> Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ned Batchelder <[email protected]> Co-authored-by: Adam Porter <[email protected]> Co-authored-by: Denis Bitouzé <[email protected]> Co-authored-by: Stuart Mumford <[email protected]> Co-authored-by: Alenka Frim <[email protected]> Co-authored-by: Harutaka Kawamura <[email protected]> Co-authored-by: jourlez <[email protected]> Co-authored-by: Chris Holdgraf <[email protected]> * Keyboard handlers to open and close mobile sidebars * Update src/pydata_sphinx_theme/__init__.py --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Daniel McCloy <[email protected]> Co-authored-by: Rambaud Pierrick <[email protected]> Co-authored-by: gresavage <[email protected]> Co-authored-by: tgresavage <[email protected]> Co-authored-by: transifex-integration[bot] <43880903+transifex-integration[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ned Batchelder <[email protected]> Co-authored-by: Adam Porter <[email protected]> Co-authored-by: Denis Bitouzé <[email protected]> Co-authored-by: Stuart Mumford <[email protected]> Co-authored-by: Alenka Frim <[email protected]> Co-authored-by: Harutaka Kawamura <[email protected]> Co-authored-by: jourlez <[email protected]> Co-authored-by: Chris Holdgraf <[email protected]>
1 parent 0711d15 commit 97f939b

File tree

5 files changed

+104
-18
lines changed

5 files changed

+104
-18
lines changed

src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js

+84
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,89 @@ if (hasVersionsJSON && (hasSwitcherMenu || wantsWarningBanner)) {
562562
}
563563
}
564564

565+
/*******************************************************************************
566+
* Add keyboard functionality to mobile sidebars.
567+
*
568+
* Wire up the hamburger-style buttons using the click event which (on buttons)
569+
* handles both mouse clicks and the space and enter keys.
570+
*/
571+
function setupMobileSidebarKeyboardHandlers() {
572+
// These are hidden checkboxes at the top of the page whose :checked property
573+
// allows the mobile sidebars to be hidden or revealed via CSS.
574+
const primaryToggle = document.getElementById("pst-primary-sidebar-checkbox");
575+
const secondaryToggle = document.getElementById(
576+
"pst-secondary-sidebar-checkbox"
577+
);
578+
const primarySidebar = document.querySelector(".bd-sidebar-primary");
579+
const secondarySidebar = document.querySelector(".bd-sidebar-secondary");
580+
581+
// Toggle buttons -
582+
//
583+
// These are the hamburger-style buttons in the header nav bar. When the user
584+
// clicks, the button transmits the click to the hidden checkboxes used by the
585+
// CSS to control whether the sidebar is open or closed.
586+
const primaryClickTransmitter = document.querySelector(".primary-toggle");
587+
const secondaryClickTransmitter = document.querySelector(".secondary-toggle");
588+
[
589+
[primaryClickTransmitter, primaryToggle, primarySidebar],
590+
[secondaryClickTransmitter, secondaryToggle, secondarySidebar],
591+
].forEach(([clickTransmitter, toggle, sidebar]) => {
592+
if (!clickTransmitter) {
593+
return;
594+
}
595+
clickTransmitter.addEventListener("click", (event) => {
596+
event.preventDefault();
597+
event.stopPropagation();
598+
toggle.checked = !toggle.checked;
599+
600+
// If we are opening the sidebar, move focus to the first focusable item
601+
// in the sidebar
602+
if (toggle.checked) {
603+
// Note: this selector is not exhaustive, and we may need to update it
604+
// in the future
605+
const tabStop = sidebar.querySelector("a, button");
606+
// use setTimeout because you cannot move focus synchronously during a
607+
// click in the handler for the click event
608+
setTimeout(() => tabStop.focus(), 100);
609+
}
610+
});
611+
});
612+
613+
// Escape key -
614+
//
615+
// When sidebar is open, user should be able to press escape key to close the
616+
// sidebar.
617+
[
618+
[primarySidebar, primaryToggle, primaryClickTransmitter],
619+
[secondarySidebar, secondaryToggle, secondaryClickTransmitter],
620+
].forEach(([sidebar, toggle, transmitter]) => {
621+
if (!sidebar) {
622+
return;
623+
}
624+
sidebar.addEventListener("keydown", (event) => {
625+
if (event.key === "Escape") {
626+
event.preventDefault();
627+
event.stopPropagation();
628+
toggle.checked = false;
629+
transmitter.focus();
630+
}
631+
});
632+
});
633+
634+
// When the <label> overlay is clicked to close the sidebar, return focus to
635+
// the opener button in the nav bar.
636+
[
637+
[primaryToggle, primaryClickTransmitter],
638+
[secondaryToggle, secondaryClickTransmitter],
639+
].forEach(([toggle, transmitter]) => {
640+
toggle.addEventListener("change", (event) => {
641+
if (!event.currentTarget.checked) {
642+
transmitter.focus();
643+
}
644+
});
645+
});
646+
}
647+
565648
/*******************************************************************************
566649
* Call functions after document loading.
567650
*/
@@ -571,3 +654,4 @@ documentReady(scrollToActive);
571654
documentReady(addTOCInteractivity);
572655
documentReady(setupSearchButtons);
573656
documentReady(initRTDObserver);
657+
documentReady(setupMobileSidebarKeyboardHandlers);

src/pydata_sphinx_theme/assets/styles/sections/_header.scss

+4-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@
176176

177177
// Hide the header items on mobile
178178
.bd-header {
179-
// Toggle labels
180-
label {
179+
// Toggle buttons
180+
button {
181181
&.sidebar-toggle {
182182
display: flex;
183183
cursor: pointer;
@@ -186,6 +186,8 @@
186186
color: var(--pst-color-muted);
187187
margin-bottom: 0;
188188
padding-bottom: 0.25rem;
189+
background-color: inherit;
190+
border: none;
189191
}
190192

191193
&.primary-toggle {

src/pydata_sphinx_theme/assets/styles/sections/_sidebar-toggle.scss

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ label.overlay {
2828

2929
input {
3030
// Show the correct overlay when its input is checked
31-
&#__primary:checked + label.overlay.overlay-primary,
32-
&#__secondary:checked + label.overlay.overlay-secondary {
31+
&#pst-primary-sidebar-checkbox:checked + label.overlay.overlay-primary,
32+
&#pst-secondary-sidebar-checkbox:checked + label.overlay.overlay-secondary {
3333
height: 100vh;
3434
width: 100vw;
3535
}
3636

3737
// Primary sidebar slides in from the left
38-
&#__primary:checked ~ .bd-container .bd-sidebar-primary {
38+
&#pst-primary-sidebar-checkbox:checked ~ .bd-container .bd-sidebar-primary {
3939
visibility: visible;
4040
margin-left: 0;
4141
}
4242

4343
// Secondary sidebar slides in from the right
44-
&#__secondary:checked ~ .bd-container .bd-sidebar-secondary {
44+
&#pst-secondary-sidebar-checkbox:checked
45+
~ .bd-container
46+
.bd-sidebar-secondary {
4547
visibility: visible;
4648
margin-right: 0;
4749
}
@@ -82,11 +84,11 @@ input {
8284

8385
// Primary sidebar hides/shows at earlier widths
8486
@include media-breakpoint-up($breakpoint-sidebar-primary) {
85-
label.sidebar-toggle.primary-toggle {
87+
.sidebar-toggle.primary-toggle {
8688
display: none;
8789
}
8890

89-
input#__primary {
91+
input#pst-primary-sidebar-checkbox {
9092
&:checked + label.overlay.overlay-primary {
9193
height: 0;
9294
width: 0;

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html

+4-6
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@
6767
{# checkbox to toggle primary sidebar #}
6868
<input type="checkbox"
6969
class="sidebar-toggle"
70-
name="__primary"
71-
id="__primary"/>
72-
<label class="overlay overlay-primary" for="__primary"></label>
70+
id="pst-primary-sidebar-checkbox"/>
71+
<label class="overlay overlay-primary" for="pst-primary-sidebar-checkbox"></label>
7372
{# Checkboxes to toggle the secondary sidebar #}
7473
<input type="checkbox"
7574
class="sidebar-toggle"
76-
name="__secondary"
77-
id="__secondary"/>
78-
<label class="overlay overlay-secondary" for="__secondary"></label>
75+
id="pst-secondary-sidebar-checkbox"/>
76+
<label class="overlay overlay-secondary" for="pst-secondary-sidebar-checkbox"></label>
7977
{# A search field pop-up that will only show when the search button is clicked #}
8078
<div class="search-button__wrapper">
8179
<div class="search-button__overlay"></div>

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/header.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% if theme_navbar_start or theme_navbar_center or theme_navbar_end or theme_navbar_persistent %}
22
<div class="bd-header__inner bd-page-width">
3-
<label class="sidebar-toggle primary-toggle" for="__primary">
3+
<button class="sidebar-toggle primary-toggle" aria-label="{{ _('Site navigation') }}">
44
<span class="fa-solid fa-bars"></span>
5-
</label>
5+
</button>
66
{% set navbar_start, navbar_class, navbar_align = navbar_align_class() %}
77
{% if theme_navbar_start %}
88
<div class="{{ navbar_start }} navbar-header-items__start">
@@ -40,9 +40,9 @@
4040
{% endfor %}
4141

4242
{% if not remove_sidebar_secondary %}
43-
<label class="sidebar-toggle secondary-toggle" for="__secondary" tabindex="0">
43+
<button class="sidebar-toggle secondary-toggle" aria-label="{{ _('On this page') }}">
4444
<span class="fa-solid fa-outdent"></span>
45-
</label>
45+
</button>
4646
{% endif %}
4747
</div>
4848
{% endif %}

0 commit comments

Comments
 (0)