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

Disable scrolling and interation with main page when ToC is open on mobile #155

Open
david-christiansen opened this issue Nov 18, 2024 · 8 comments
Labels
ASAP To be done as soon as possible HTML/CSS Problems with the HTML or CSS of the manual

Comments

@david-christiansen
Copy link
Collaborator

It would be great if opening the ToC menu on narrow screens would cause the rest of the page to get grayed out and disabled, to prevent accidental scrolling or clicks.

@jakobvase, what's the canonical way to do this?

@david-christiansen david-christiansen added ASAP To be done as soon as possible HTML/CSS Problems with the HTML or CSS of the manual labels Nov 18, 2024
@david-christiansen
Copy link
Collaborator Author

Also, clicking outside of the ToC should close it, rather than just the X doing that.

@jakobvase
Copy link

Here we're going to need javascript.

Add a <div class="toc-backdrop" onclick="document.getElementById('toggle-toc-click')?.click()"></div> as the first child of div.with-toc, just before the nav#toc. On desktop, add display: none to .toc-backdrop. On mobile, when the toc is visible, add position: fixed; inset: 0; background-color: #aaa8; z-index: 1; to it. That covers the graying out and the closing, and no links are active.

For preventing scrolling, the best way is to add overflow: hidden to html when the toc is open. Only on mobile.

The last thing we should do is add the attribute inert="" to main (prevents things like 'find in page' for the inert content, tab doesn't move focus there). But that's more tricky so I wouldn't do it in this case. The simplest way is probably a something like a 200ms javascript loop that checks if the conditions are there (mobile, toc open) and adds it if they are and removes it otherwise. That way we won't have to deal with listening to window resize events and add it to all the places that need it and someone forgets later and the page breaks. But as I said I don't think it's worth it in this case.

@jakobvase
Copy link

Conditional attributes is one of the reasons people use react for web programming. But it comes with a ot of strings attached and definitely doesn't fit your use case.

@david-christiansen
Copy link
Collaborator Author

david-christiansen commented Nov 19, 2024

This is a huge help - thanks! Would have taken me hours to figure this part out.

One minor issue: on my desktop browser, the overflow:hidden on html makes the scroll bar disappear, which causes a minor text reflow. Do you know a workaround for this?

Edit: screenshots (look at the words on the ends of the lines in the intro paragraph - they differ)

Screenshot 2024-11-19 at 09 36 09 Screenshot 2024-11-19 at 09 36 17

@david-christiansen
Copy link
Collaborator Author

(this is when I drag the window to be super narrow, which I think most desktop users won't do, but it might in principle happen...)

@david-christiansen
Copy link
Collaborator Author

As far as the inert property goes, what about MediaQueryList's change event? That seems to promise to be a simple way to "follow what the CSS does".

@david-christiansen
Copy link
Collaborator Author

I went ahead and merged the work so far, but it would be nice to fix the reflow issue, so this can stay open.

@david-christiansen
Copy link
Collaborator Author

Thanks again @jakobvase, by the way!

david-christiansen added a commit that referenced this issue Nov 19, 2024
This should fix horizontal scrolling on mobile phones.

Closes #138 and most of #155.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASAP To be done as soon as possible HTML/CSS Problems with the HTML or CSS of the manual
Projects
None yet
Development

No branches or pull requests

2 participants