Skip to content

Make site usable without any JavaScript #3030

Open

Description

@slorber

🐛 Bug Report

The site is able to work mostly fine without JS.
In such case, navigation is not SPA/history push based, but is a regular html nav (like Docusaurus v1)

But, docs have collapsible menus, and these menus won't expand without JS:

image

image

I think we should find a html/css only solution to enable the user to expand those collapsible menus. It should be possible using :focus / :focus-within, here's a random example: https://codepen.io/josy-star/pen/KymaJw

If this is done correctly, users may even be able to enter submenus by using keyboard focus navigation (using tab).

Yes, users don't disable JS anymore in 2020, yet I think this is important to support. Main reason is that users on a bad connexion may experience slow JS hydration time, and for a few seconds, the JS is not loaded. I think we should ensure the nav still work during that time.

Other important reasons here: https://kryogenix.org/code/browser/everyonehasjs.html

(useful extension: https://github.com/maximelebreton/quick-javascript-switcher)


This is a non-exhaustive list of what can be easily fixed to support a no-js mode. If you find other issues that can have a significant impact and are easy to fix, that can be nice. The purpose if probably not to make everything work without JS, but if we can have at least major features like the navigation, it's a nice win that all our users will benefit.

Note: maybe some parts of the fix would require being backported to Infima?


Related draft PR: #3237

Activity

  1. added
    bug
    status: needs triage
    mlh
    and removed
    status: needs triage
    on Jul 8, 2020
  2. anshulrgoyal commented on Jul 8, 2020

    @anshulrgoyal
    Contributor

    I am working on this.

  3. anshulrgoyal commented on Jul 8, 2020

    @anshulrgoyal
    Contributor

    @slorber Navbar dropdown work without js.
    image

  4. slorber commented on Jul 8, 2020

    @slorber
    CollaboratorAuthor

    ah yes it's :hover

    so it's probably only the collapsible doc sections that don't expand without js (here, :hover is not enough, we need to support multi-level nesting)

  5. anshulrgoyal commented on Jul 8, 2020

    @anshulrgoyal
    Contributor

    ah yes it's :hover

    so it's probably only the collapsible doc sections that don't expand without js (here, :hover is not enough, we need to support multi-level nesting)

    I am trying to use the hidden checkbox. This is a good example https://codepen.io/jboeijenga/pen/eqzal

  6. slorber commented on Jul 8, 2020

    @slorber
    CollaboratorAuthor

    hmmm, that could do the trick. Wonder what's the advantage of using something like tabindex and :focus-within ?

    Will this work if I use tab navigation to give the focus to an item for example?

    Here I used tab navigation, we can see it with the collapsible outline. In such case that should be nice to expand it automatically:

    image

    I can see how using checkboxes would be nice to give some state and keep the collapsible expanded when they lose focus, but still think it may be useful to make it work without the checkboxes ;)

  7. added
    good first issue
    on Oct 1, 2020
  8. changed the title [-]Fix nav when no JS[/-] [+]Make site usable without any JavaScript[/+] on Oct 2, 2020
  9. sarthakkundra commented on Oct 4, 2020

    @sarthakkundra
    Contributor

    @slorber The current classic template for version 2.0.0-alpha.65 doesn't seem to have a dropdown menu for the docs. The generated site does seem to have some JS but that's only to store the theme preference. Please correct me if I'm wrong in understanding the issue or if any other changes are required.

    docusaurus V-alpha  65

  10. 19 remaining items

  11. jwalton commented on Nov 19, 2021

    @jwalton

    The hidden checkbox idea is great, but a "quick and easy" alternative would be to render expandable items as links. For example, if you click on "Getting Started >" and there's no javascript, we could take the user to a page that has a list of all the catagories underneath "Getting Started". It's not as fancy, but it at least makes it so the page can be used.

  12. slorber commented on Nov 20, 2021

    @slorber
    CollaboratorAuthor

    @jwalton as part of #5830 we are adding the ability to link to a doc or an automatically generated index page (https://deploy-preview-5830--docusaurus-2.netlify.app/docs/next/category/getting-started/)

    This is however optional.

    For categories not linking to any URL, I'll link them to the first child until React is able to hydrate, so that you'd be able to click on the category if the JS fails to load (suggested in facebookincubator/infima#36 (comment))

    The only case where we you wouldn't be able to "open" the category without JS is:

    • When there is no explicit link (doc or generated index)
    • When the category has no child, or none of the child have any link (which is a weird use-case IMHO)
  13. slorber commented on Dec 1, 2021

    @slorber
    CollaboratorAuthor

    I implemented the fallback described above as part of #5830

    Now the sidebar is partially rendered on the server and we can still navigate it entirely with JS disabled.

    Test URL: https://deploy-preview-5830--docusaurus-2.netlify.app/docs/next/category/guides/
    The only edge-case where we can't navigate with JS disabled is when a category has no subitems (which is a weird use-case anyway)
    Let me know if you see any issues.

  14. Josh-Cena commented on Jan 8, 2022

    @Josh-Cena
    Collaborator

    From my tests, our website now almost works perfectly with JS disabled. However, when you navigate between pages, there's a flash of the navbar dropdown:

    Test

    Probably because we render the dropdown on SSR?

  15. slorber commented on Jan 12, 2022

    @slorber
    CollaboratorAuthor

    😅 I don't see this happening for me on the docusaurus website

    Yes, we render the dropdown on purpose: it should work without JS using :hover

  16. gordonbazeley commented on Mar 3, 2022

    @gordonbazeley

    Is there any way to specify that the site shouldn't deliver JS to the browser please? I'm looking to build a site with as small a carbon weight as possible and would rather do without JS if possible

  17. slorber commented on Mar 3, 2022

    @slorber
    CollaboratorAuthor

    @gordonbazeley we don't have such an option atm, there's only this draft PR: #3237

  18. Josh-Cena commented on Mar 25, 2022

    @Josh-Cena
    Collaborator

    @slorber Is this good to close now? I haven't observed any significant problem with using the site without JS.

  19. slorber commented on Mar 25, 2022

    @slorber
    CollaboratorAuthor

    I'd like to keep this issue open and alive forever, as a central issue to discuss and report everything related to progressive enhancements

    We still have a few things we could work on:

    • search (Algolia may implement a fallback server-side UI)
    • mobile drawer menu (looks the most important, can probably work with checkbox)
    • tabs (can probably work with radio when tabs are not lazy)
    • dark mode toggle (low ROI, but can probably work with checkbox)
    • probably other little details
  20. Josh-Cena commented on Mar 25, 2022

    @Josh-Cena
    Collaborator

    Ah, makes sense.

  21. slorber commented on Oct 20, 2022

    @slorber
    CollaboratorAuthor

    Notes to myself:

    Interesting suggestions on how to support a no-js version of the mobile drawer using recent CSS features: https://twitter.com/sebastienlorber/status/1582788081668616192
    Edit, more recently: https://twitter.com/Una/status/1729236000294174733

    No-js search can likely be implemented with a simple GET form fallback redirecting to google site search URL:
    https://www.google.fr/search?q=site:docusaurus.io&q=mdx

  22. slorber commented on Dec 8, 2022

    @slorber
    CollaboratorAuthor

    Note to self:

    The mobile drawer menu doesn't work well without JS

    When the time comes to refactor it, make sure to also take into consideration the comments from @timveld regarding keyboard/accessibility in #8207 (comment)

  23. slorber commented on Nov 25, 2023

    @slorber
    CollaboratorAuthor

    Related: when JS is disabled it should be possible to keep theme respect OS color scheme (initially reported in #9579)

  24. SethFalco commented on Nov 25, 2023

    @SethFalco
    Contributor

    when JS is disabled it should be possible to keep theme respect OS color scheme

    I've been working on this, and have a proof of concept ready. Dark mode will look the same with JavaScript disabled, except for code blocks due to Prism's inline styles.

    The proposed approach using PostCSS to retroactively replace selectors from [data-theme=…] to @media (prefers-color-scheme: …), when both prefers-color-scheme is enabled and the switch UI is disabled.

    I'll hold off on opening a PR for now so I can investigate the Prism issue further, and see how to approach tests for this.

    You can find the WIP branch here:

    This does not conditionally omit noFlashColorMode(), as Prism still depends on it for theming code blocks.

    The following screenshots are taken with JavaScript disabled:


    Alternatively, here is our plugin for Docusaurus:

    This plugin is currently in use on svgo.dev.

  25. slorber commented on Dec 12, 2023

    @slorber
    CollaboratorAuthor

    Apparently we can implement tabs without JS thanks to the new <details> name attribute and some CSS

    Source: https://twitter.com/naman34/status/1734367676536078755
    Not sure it's good for a11y, but worth exploring.


    This feature is normally meant to create accordions. Preview without tab styling:

    Tab 1 1. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam explicabo, dolore voluptatibus corrupti quia vitae iure exercitationem, incidunt eius magnam voluptates, voluptatum sit dicta cupiditate ducimus molestiae repellendus in perferendis!
    Tab 2 2. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam explicabo, dolore voluptatibus corrupti quia vitae iure exercitationem, incidunt eius magnam voluptates, voluptatum sit dicta cupiditate ducimus molestiae repellendus in perferendis!
    Tab 3 3. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam explicabo, dolore voluptatibus corrupti quia vitae iure exercitationem, incidunt eius magnam voluptates, voluptatum sit dicta cupiditate ducimus molestiae repellendus in perferendis!
    Tab 4 4. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam explicabo, dolore voluptatibus corrupti quia vitae iure exercitationem, incidunt eius magnam voluptates, voluptatum sit dicta cupiditate ducimus molestiae repellendus in perferendis!
    Tab 5 5. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam explicabo, dolore voluptatibus corrupti quia vitae iure exercitationem, incidunt eius magnam voluptates, voluptatum sit dicta cupiditate ducimus molestiae repellendus in perferendis!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions