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

Can use with other tab libraries #95

Merged
merged 1 commit into from
Aug 18, 2024
Merged

Conversation

AWhetter
Copy link
Contributor

Since creating the original issue I've stopped using sphinx-tabs and moved onto using sphinx-design. To remove the reliance on any one tab library, I've opted to add a :http:example-block: directive for translating and rendering a HTTP request or response anywhere,
including in tab directives from other Sphinx extensions.

Closes #25

If you would like me to make httpexample use sphinx-tabs in addition to this change, I've got a working example of that (AWhetter@8769655) but I'll need to change it to work with this new directive.

@stevepiercy
Copy link
Member

Is this compatible with, or a replacement for, #94?

I use sphinx-design in almost all my documentation projects, and I think consistent design would be a nice touch.

@AWhetter
Copy link
Contributor Author

This is indeed compatible with #94. The usage of other tab libraries is done independently of the automatic generation of a tabs by httpexample.

Added a :http:example-block: directive for translating and rendering
a HTTP request or response anywhere,
including in tab directives from other Sphinx extensions.

Closes collective#25
@datakurre
Copy link
Collaborator

@stevepiercy @AWhetter Thank you! This is interesting.

Is sphinx-design + sphinx-inline-tabs the same as this https://sphinx-inline-tabs.readthedocs.io/en/latest/

It does not look accessible (no aria-attributes or keyboard navigation support).

But sphinx-tabs looks accessible https://sphinx-tabs.readthedocs.io/en/latest/

Maybe I am missing something here?

So, sphinx-tabs is not compatible with sphinx-design? I am sorry for not being very up-to-date with the current Sphinx extension trends. Dropping custom tabbing would be nice, but I'd like to do it without requiring source syntax change (by using the chosen tabbing directives implicitly).

In any case, I should probably first release a version without jQuery requirement and then look into this.

Sorry about the test setup. The test failure are probably just missing deps in https://github.com/collective/sphinxcontrib-httpexample/tree/master/nix where I have collection of Poetry lock files for deterministic tests on Python 3 and a custom thing for Python 2.7.

@stevepiercy
Copy link
Member

@datakurre there are numerous tab projects, and they're all intertwingled. Various Sphinx theme and extension authors have collaborated over the last 3 years to improve accessibility, usability, and features. executablebooks and pradyunsg are two key developers.

sphinx-design (SD) is the most widely used tab package of these three (https://pypistats.org/packages/sphinx-design), and is used in the following major Sphinx themes:

You can check out the tab demos in each of those themes.


As far as accessibility, I looked at demos of both:

They are both accessible. They both use <input type="radio"> to activate each tab. The difference is that there is a lack of CSS in SD to indicate that you have tabbed onto the radio button, whereas PST has styling. In SD, try tabbing around until it seems that nothing got selected, then use the right and left arrow keys.

Copy link
Member

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

It would be cool to have different theme demos, like sphinx-design does. See my comment #95 (comment). I think that it would be outside the scope of this PR, but would be a really nice addition.

@datakurre
Copy link
Collaborator

As far as accessibility, I looked at demos of both:

* https://sphinx-design.readthedocs.io/en/latest/tabs.html#tabbed-code-examples
* https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/web-components.html#tabs

When I look them, both are missing aria-attributes and the first one does not have any default styles to indicate that keyboard focus is within tab list.

I'd guess something implementing this would be ideal: https://www.w3.org/WAI/ARIA/apg/patterns/tabs/examples/tabs-automatic/

What would you recommend? Should I keep the custom tabbing (and maybe review and enhance its accessibility too)? Should I only support tabbing provided by some specific themes / add-ons? Should I try to sniff the available add-on or should there be configuration options for this?

Of course, perfect is the enemy of good. Automatic support sphinx-design tabs maybe? And keep custom tabbing implementation when sphinx-design is not available (or would configuration option be the only safe option?).

@datakurre
Copy link
Collaborator

Or maybe the way this pull is implemented after all? Keep the current behavior for existing uses, but provide the new directive for sphinx-design-tabbing.

@stevepiercy How would you like the proposed support in this pull, where you need to define every tab in source?

@stevepiercy
Copy link
Member

@datakurre if I understand this PR correctly, it adds support for reStructuredText or MyST markup for sphinx-design and sphinx-inline-tabs, while keeping the current implementation.

I prefer the less verbose markup and the aria attributes that the current implementation of sphinxcontrib-httpexample provides, even though they are injected by JavaScript. I prefer the design of and lack of JavaScript in sphinx-design.

In a perfect world, either a theme or extension would insert appropriate aria attributes using Python and without JavaScript. If that is done in sphinxcontrib-httpexample, it would be portable to other themes.

I could open an issue to start a conversation with the SD maintainers to see if they are interested in including aria attributes in the tabs. I don't think it is on their radar, but if we bring it up, then I bet they would like to add it. It would make all the other theme authors who care about a11y very happy.

As far as details, which attributes would you like to see? I see that sphinxcontrib-httpexample uses these attributes with example values, which SD lacks.

role="tab"
tabindex="0"
aria-label="http"
aria-controls="id1"
aria-selected="true"

@datakurre
Copy link
Collaborator

I didn't know that sphinx-design had implemented tabs without JavaScript. That's almost too clever markup + css. I'm not sure if dynamic aria-attributes are achievable that way, though.

I guess, simply merging and releasing this pull is the best compromise for now.

I am also sorry for still not wanting to drop Python 2.7 support, so I'll do some refactoring to make the docs build when the those new tab extensions are not available.

Thanks!

@stevepiercy
Copy link
Member

You're correct, only JavaScript can change the ARIA attributes in the DOM. I actually did not realize that sphinxcontrib-httpexample changed them, but now I see why it is necessary. I take back my preference against modifying them via JavaScript in this use case.

I started an "idea" discussion with the SD folks about adding ARIA attributes. I'm curious why they don't include them, but perhaps the requirement of JavaScript to have dynamic ARIA attributes is the reason. Maybe they'll adapt this JavaScript. 😁

@stevepiercy
Copy link
Member

I agree that merging this PR would be a good compromise.

@datakurre datakurre merged commit 4016da1 into collective:master Aug 18, 2024
0 of 17 checks passed
@AWhetter AWhetter deleted the gh25 branch August 18, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visual consistency with sphinx_tabs
3 participants