-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: version selector JS #1305
fix: version selector JS #1305
Conversation
supersedes and closes #1259 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. test failures seem unrelated though (it cannot even set up the environment) |
It appeared to be a network error, I restarted the CIs and they worked this time. Remaining CI errors are unrelated and being tracked in #1307 now. I'd like to add a test that checks that styling the button works and also that highlighting the currently-being-viewed version also works. @jpfeuffer are you up for adding such a test? If not I can try to get to it later this week / early next week. |
@jpfeuffer heads up that I force-pushed to this branch. I did so because a rebase was necessary to get changes from #1320, which were needed for the new test I added to pass. @12rambau can you take another look here, it's still showing you as "changes requested" but I think that was just about the linting? @trallard I wouldn't mind your eyes on this PR too, because in order to select the version menu elements with playwright I had to add ARIA roles to them, and I want to make sure I did it correctly. I'll self-review to point you to the relevant changes. |
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html
Outdated
Show resolved
Hide resolved
{{ theme_switcher.get('version_match') }} <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div class="version-switcher__menu dropdown-menu list-group-flush py-0"> | ||
<div id="versionswitchermenu" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="menu" aria-labelledby="versionswitcherbutton"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trallard here the inner div (the thing that pops open when the button is clicked) gets an ID, role='menu'
and an aria-labelledby
(again I'm copying from MDN example, not certain I've done this optimally)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabindex=-1
: allows DOM focus on being set on the listbox container- no need for a
labelledby
aria now since it will inherit from the button above
<div id="versionswitchermenu" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="menu" aria-labelledby="versionswitcherbutton"> | |
<div id="versionswitcherlist" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="listbox" tabindex=-1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another aria
property needed here aria-activedescendant
which I assume will be related to activeVersionName
, but I am unsure how to add this (seems to be dynamically set in the JS file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another
aria
property needed herearia-activedescendant
which I assume will be related toactiveVersionName
, but I am unsure how to add this (seems to be dynamically set in the JS file)
I'm actually unsure about this. IIUC, aria-activedescendant
is about the element that has DOM focus whereas activeVersionName
is about the version of the docs that is currently loaded in the browser (regardless of which version choice the user happens to have tabbed to when preparing to switch versions). Is that right? If so / if I'm reading the w3c page correctly, we don't want to set aria-activedescendant
equal to activeVersionName
, and we don't actually need to set aria-activedescendant
at all since we set tabindex=-1
(therefore the container is not focusable). Does that sound right to you @trallard or am I misunderstanding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is used in our tests to make sure the version switcher component gets embedded correctly (prior to any JS adding the actual entries). Changes here simply mirror the changes to the template so that test still passes.
|
||
|
||
@pytest.mark.parametrize("url", switcher_files) | ||
def test_version_switcher(sphinx_build_factory, file_regression, url) -> None: | ||
def test_version_switcher_error_states( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just a rename to make the test name more specific, since I'm adding another related test.
|
||
|
||
def test_version_switcher_highlighting(page: Page, url_base: str) -> None: | ||
"""This isn't an a11y test, but needs a served site for Javascript to inject the version menu.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trallard In a follow-up PR I'd like to add a @requires_playwright
decorator so that I can move this test out of test_a11y.py
into test_build.py
. Something similar to
OK with you if this non-a11y test squats in the test_a11y.py
file for now until that gets done? (did it this way because of the importorskip
issue; didn't want to importorskip
the entire other tests file when only one test needed playwright)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, this makes sense to me
Thanks for the ping @drammock - I need to review my notes on accessible selectors and the correct ARIA use but at a quick glance, this looks like it would be best to use a Ref:
|
@drammock sorry for not answering I have a thumb tendonitis, the doctors are trying to keep me away from keyboards. That's effectciveley a legacy request I've removed it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it to the maintainers very capable hands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to stop saying "tomorrow" as I keep losing control over my schedule.
Anyway, did a review and made some suggestions + added the rationale on the changes needed
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html
Outdated
Show resolved
Hide resolved
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html
Outdated
Show resolved
Hide resolved
{{ theme_switcher.get('version_match') }} <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div class="version-switcher__menu dropdown-menu list-group-flush py-0"> | ||
<div id="versionswitchermenu" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="menu" aria-labelledby="versionswitcherbutton"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabindex=-1
: allows DOM focus on being set on the listbox container- no need for a
labelledby
aria now since it will inherit from the button above
<div id="versionswitchermenu" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="menu" aria-labelledby="versionswitcherbutton"> | |
<div id="versionswitcherlist" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="listbox" tabindex=-1> |
{{ theme_switcher.get('version_match') }} <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div class="version-switcher__menu dropdown-menu list-group-flush py-0"> | ||
<div id="versionswitchermenu" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="menu" aria-labelledby="versionswitcherbutton"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another aria
property needed here aria-activedescendant
which I assume will be related to activeVersionName
, but I am unsure how to add this (seems to be dynamically set in the JS file)
|
||
|
||
def test_version_switcher_highlighting(page: Page, url_base: str) -> None: | ||
"""This isn't an a11y test, but needs a served site for Javascript to inject the version menu.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, this makes sense to me
Also, I'd like to point out that the version selector component is not currently keyboard focusable and operable. I tried fixing / testing by setting The desired behaviours would be as follows: Collapsed select - menu button
Expanded list
|
Co-authored-by: Tania Allard <[email protected]>
fixes #1304
fixes #1128