-
Notifications
You must be signed in to change notification settings - Fork 55
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
Unability to navigate collapsed menu without JS #36
Comments
How would you implement this behavior without JS though? In that case maybe the current behavior where nothing is collapsed on initial load (when JS is disabled) isn't too bad? 😂 I don't see how we can address this, D1's sidebar needs JS as well for collapsing and expanding. |
It is likely possible to implement a tree structure with foldable nodes by expanding them on :focus / :focus-within https://blogs.igalia.com/mrego/2017/05/03/adding-focus-within-selector-to-chromium/ https://blogs.igalia.com/mrego/files/2017/05/focus-within-menu.html If you press tab, you'll see the menu values just by using tab and focusing the items. And clicking on a collapsed category gives it focus so... I think it's definitively possible without JS :) |
Hi, I discovered Docusaurus v2 a week ago and also discovered this project as well. I couldn't help but to comment on this. I also don't think it is possible to implement tree view collapsible menu without JS. Please take a look at https://www.w3.org/TR/wai-aria-practices-1.1/#TreeView where they need JS. I think it would be better to just display an expanded tree view if JS is disabled. The user will not be able to expand/collapse menus, but they can still navigate the menu. |
Related to facebook/docusaurus#3030 I made a demo without js, using focus-within here: facebook/docusaurus#3642 (comment)
We don't want to force the user to have all users with an expanded tree view by default. This should rather only affect users that were not able to load our JS properly (network error, disabled js, older browser...) |
There are tradeoffs to either displaying an expanded tree view or using |
I'd like to see this handled too. A pattern I've used is to default to all expanded, and then collapse the menus only when JS is available. One way to do this is with a <ul id="nav">
<script>
document.getElementById("nav").classList.add("collapsed");
</script>
<!-- the rest of the menu markup follows here... --> This prevents a flash of changing styles, because the browser applies the collapsed styles very early in the rendering process. Here's a full example on CodeSandbox. Another alternative might be using The downside to both of these approaches - they do nothing to help against network errors or JS errors in the app code. |
@m-allanson the goal for me is not really to handle the case for users having disabled the JS, but rather being able to have a decent UI even before JS loads and React hydrates. I want to somehow make the React hydration process a progressive enhancement of the experience instead of being a hard requirement, maybe deferring the JS loading to a lower priority, leverage progressive hydration, and obtain a better perf profile. My goal is in the same way a Gatsby link can be clicked even before the React hydration and can still navigate. So I don't think your solution would work apart for users with JS disabled. Related: https://kryogenix.org/code/browser/everyonehasjs.html |
@slorber That's a fair point.
This is great, bookmarked! |
What if the That would make all parts of the site navigable without JS, and wouldn't change any functionality once the JS is running. Once you've navigated to a sublist page, the sidebar already displays other pages in that category. <ul class="menu__list">
<li class="menu__list-item">
- <a class="menu__link menu__link--sublist menu__link--active" href="#!"
+ <a class="menu__link menu__link--sublist menu__link--active" href="/docs/next/api/plugins"
>Plugins</a
>
<ul class="menu__list">
<li class="menu__list-item">
<a
aria-current="page"
class="menu__link menu__link--active active"
tabindex="0"
href="/docs/next/api/plugins"
>Plugins overview</a
>
</li>
<li class="menu__list-item">
<a
class="menu__link"
tabindex="0"
href="/docs/next/api/plugins/@docusaurus/plugin-content-docs"
>📦 plugin-content-docs</a
>
</li>
</ul>
</li>
</ul> For example try browsing the Docusaurus Plugins pages without JS. That part works well, but you can't get to the Themes section. This change would enable navigating through to a different category. |
That's definitively a behavior that would allow navigating to category subitems. We have an issue to support that: facebook/docusaurus#2643 Let's figure if this issue is still useful after we support that feature. This is a different sidebar behavior UX, and I think we could support both it possible. |
My thought was to make the clientside JS restore the So the proposed change would only apply when JS failed to load. |
That looks like a nice trick, didn't think of that, worth giving it a try ;) |
As we now render "lazy/partial sidebars" on Docusaurus SSR, I think this will never be implemented in Infima so I'm closing See my comment here facebook/docusaurus#3030 (comment) |
I implemented your suggestion as part of facebook/docusaurus#5830 @m-allanson |
Lovely stuff, thank you 🙏 It works great from this side. |
Currently on D2 it's not possible to "navigate" to a collapsed menu without JS enabled.
This is probably not the most impactful enhancement we could make, but I think I read it's a goal to make the site usable without JS (or before js hydration).
We could probably expand a collapsed menu item on :focus / :focus-within
The text was updated successfully, but these errors were encountered: