Skip to content
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

Closed
wants to merge 10 commits into from
Closed

fix: version selector JS #1305

wants to merge 10 commits into from

Conversation

jpfeuffer
Copy link
Contributor

@jpfeuffer jpfeuffer commented Apr 24, 2023

fixes #1304
fixes #1128

@jpfeuffer jpfeuffer changed the title fixes #1304 fix: version selector JS Apr 24, 2023
@jpfeuffer
Copy link
Contributor Author

supersedes and closes #1259

Copy link
Collaborator

@12rambau 12rambau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first, nice catch, I think it was already identified by @drammock at some point and then long forgotten (here). Could you apply the format pre-commit to allow the tests to run ?

@jpfeuffer
Copy link
Contributor Author

thanks. test failures seem unrelated though (it cannot even set up the environment)

@drammock
Copy link
Collaborator

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.

@drammock
Copy link
Collaborator

@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.

{{ 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">
Copy link
Collaborator

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)

Copy link
Collaborator

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
Suggested change
<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>

Copy link
Collaborator

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)

Copy link
Collaborator

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)

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?

Copy link
Collaborator

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(
Copy link
Collaborator

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."""
Copy link
Collaborator

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

https://github.com/mne-tools/mne-python/blob/68e4f89763135637110859ee0e05e594955815f1/mne/utils/_testing.py#L67-L81

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)

Copy link
Collaborator

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

@trallard
Copy link
Collaborator

trallard commented May 15, 2023

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 <select> or more specifically a combobox widget. Or a menu button.
I shall have time tomorrow morning to do an in-depth review + suggestions

Ref:

@12rambau
Copy link
Collaborator

@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

Copy link
Collaborator

@12rambau 12rambau left a 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

Copy link
Collaborator

@trallard trallard left a 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

{{ 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">
Copy link
Collaborator

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
Suggested change
<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>

tests/test_build/navbar_switcher.html Outdated Show resolved Hide resolved
tests/test_build/navbar_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">
Copy link
Collaborator

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."""
Copy link
Collaborator

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

@trallard
Copy link
Collaborator

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 tabindex="0" on the parent <div> with no success, so I will need to spend more time debugging/fixing this behaviour.

The desired behaviours would be as follows:

Collapsed select - menu button

  • TAB Focuses the selector button
  • Space / Enter opens the list and moves focus to the current option
  • Down and Up arrows expand the list

Expanded list

  • Up and Down arrows move through options, changing the highlighted option (do not change selection).
  • Space does nothing
  • Enter closes the menu, keeping the currently highlighted option selected
  • Escape closes the menu, keeping the currently highlighted option selected, and sets focus to the button

drammock and others added 2 commits May 26, 2023 13:07
Co-authored-by: Tania Allard <taniar.allard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants