Skip to content

Commit

Permalink
A11Y: Add title attribute to theme switcher
Browse files Browse the repository at this point in the history
This will add a `<title>` attribute to the SVG generated by font
awesome, which will in turn update the Accessibility tree, which will
now be

  - button "light/dark" focusable: true focused: bool
     - image: $title-text

Should fix Quansight-Labs/czi-scientific-python-mgmt#76
  • Loading branch information
Carreau committed Aug 20, 2024
1 parent 26fd0fb commit c133db0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{# Displays an icon to switch between light mode, dark mode, and auto (use browser's setting). #}
{# As the theme switcher will only work when JavaScript is enabled, we hide it with `pst-js-only`. #}
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" title="{{ _('light/dark') }}" aria-label="{{ _('light/dark') }}" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i>
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="{{ _('Color mode') }}" data-bs-title="{{ _('Color mode') }}" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="{{ _('Light') }}"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="{{ _('Dark') }}"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="{{ _('System Settings') }}"></i>
</button>
10 changes: 9 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,15 @@ def test_translations(sphinx_build_factory) -> None:
assert "Modifier sur GitHub" in str(sidebar_secondary)

header = index.select(".bd-header")[0]
assert "clair/sombre" in str(header)
## TODO: update once translataion up to date
# assert "clair/sombre" in str(header)
# Text of theme switcher button have been changed,
# "light/dark" has been updated to "Color mode" and does not have a translation yet.
if "Color mode" not in str(header):
pytest.xfail(
"Please update test_build.py::test_translations now that new translation are available."
)
# End TODO

footer = index.select(".bd-footer")[0]
assert "Copyright" in str(footer)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_build/navbar_theme.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<button aria-label="light/dark" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" data-bs-placement="bottom" data-bs-toggle="tooltip" title="light/dark">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light">
<button aria-label="Color mode" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" data-bs-placement="bottom" data-bs-title="Color mode" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light">
</i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark">
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark">
</i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto">
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings">
</i>
</button>
8 changes: 4 additions & 4 deletions tests/test_build/sidebar_subpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<button aria-label="light/dark" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" data-bs-placement="bottom" data-bs-toggle="tooltip" title="light/dark">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light">
<button aria-label="Color mode" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" data-bs-placement="bottom" data-bs-title="Color mode" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light">
</i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark">
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark">
</i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto">
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings">
</i>
</button>
</div>
Expand Down

0 comments on commit c133db0

Please sign in to comment.