gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Makes wiki ToC sticky

Open Eekle opened this issue 2 years ago • 6 comments

Makes ToC follows viewport on wiki pages to ease navigation.

Top of page

image

Scrolled

image

Eekle avatar Aug 02 '22 13:08 Eekle

It just occured to me that this might do exciting things if the ToC is, itself, as tall as the viewport. I don't know if that's a case we care to account for.

Eekle avatar Aug 02 '22 14:08 Eekle

Yes, sticky big TOC can get annoying because one has to scroll to the page end to scroll the TOC. For that reason, I'm undecided whether this change is a good idea.

silverwind avatar Aug 02 '22 17:08 silverwind

Yes, sticky big TOC can get annoying because one has to scroll to the page end to scroll the TOC. For that reason, I'm undecided whether this change is a good idea.

We could give the TOC a max height with a scrollbar?

Eekle avatar Aug 02 '22 18:08 Eekle

We could give the TOC a max height with a scrollbar?

No, nested scrollbars are generally confusing UX.

One solution might be to sticky only if TOC height is less than viewport height but that'll probably require some JavaScript until container queries arrive.

silverwind avatar Aug 02 '22 18:08 silverwind

Even as is, I think this is more useful than not?

At present, you always have to scroll to the top of the page to get back to the ToC. With this change, at least you only need to do it with very long ToCs.

Querying the container height in JS seems like the full package, but I am less familiar with the JS usage in the front end...

Eekle avatar Aug 02 '22 19:08 Eekle

No, I think a JS solution is probably not what we want right now. Let's see what others think about this change. I personally am undecided, pro's and con's are about equal.

silverwind avatar Aug 02 '22 19:08 silverwind

if you add _Sidebar.md which has a lot of list elements (a manually kept Index of pages for example), with this change the TOC box starts scrolling "into itself" as the Sidebar goes up, until the Sidebar reaches the top then the TOC box scrolls off screen. As soon as the Sidebar scrolls out of view, the TOC will reappear again below it. Add a _Sidebar.md with say 30 list items, a very long wiki article (pages long) and then test this change and you should see the behaviour.

tepozoa avatar Aug 22 '22 20:08 tepozoa

if you add _Sidebar.md which has a lot of list elements (a manually kept Index of pages for example), with this change the TOC box starts scrolling "into itself" as the Sidebar goes up, until the Sidebar reaches the top then the TOC box scrolls off screen. As soon as the Sidebar scrolls out of view, the TOC will reappear again below it. Add a _Sidebar.md with say 30 list items, a very long wiki article (pages long) and then test this change and you should see the behaviour.

Good catch! Perhaps in the presence of a custom sidebar, the ToC should not attempt to be sticky?

Eekle avatar Aug 22 '22 20:08 Eekle

Good catch! Perhaps in the presence of a custom sidebar, the ToC should not attempt to be sticky?

That sounds like the best idea. On mobile, the TOC/Sidebar is already really bad looking and makes the wiki document "too skinny", a scrolling TOC on mobile would make it worse. We could probably use a "hide TOC and Sidebar in Mobile mode" setting to make the content more readable, and not show/scroll the TOC at all on Mobile. (to be fair, Mobile mode on 1.17.x is a great upgrade from 1.16.x)

tepozoa avatar Aug 23 '22 13:08 tepozoa

@tepozoa Would be a good issue for a separate PR I think - style the ToC differently on Mobile so it appears above, rather than next to, the wiki.

Eekle avatar Aug 23 '22 16:08 Eekle

I think it would be good idea to make it sticky only if toc height is less than screen height by adding custom class on load with js

lafriks avatar Aug 23 '22 17:08 lafriks

@lafriks that would be the ideal UX. But I was trying to avoid a js solution because I'm not sure how to implement it in this codebase.

Eekle avatar Aug 23 '22 17:08 Eekle

@tepozoa Would be a good issue for a separate PR I think - style the ToC differently on Mobile so it appears above, rather than next to, the wiki.

Done, thanks - found an unrelated TOC+Sidebar bug while creating the demo page to report this, so we get two Issues for the price of one test document. :)

tepozoa avatar Aug 27 '22 15:08 tepozoa

Thank you for the contribution.

I can see that there are some unresolved review comments. Actually, I also have the same concern about "long TOC scrolling" problem (no idea at the moment, either).

Gitea's wiki system is far from ideal, there are too many design problems from beginning. For the TOC part, there are many issues discussing about how it should be displayed, etc, it's difficult to come to some agreements and it's difficult to improve and satisfy everyone at the moment.

So, before there is a whole good/clear design for the wiki system, I guess users could fine tune the wiki UI by using customized CSS styles/JS scripts.

Could this PR be closed? Thank you again.

wxiaoguang avatar May 10 '23 04:05 wxiaoguang