Page MenuHomePhabricator

Collapsed elements should expand when the browser tries to scroll to a child
Closed, ResolvedPublic

Description

Steps to reproduce:

or

Expected results:

  • The collapsed content expands and the browser scrolls to the heading

Actual results:

  • Nothing changes except the string in the address bar (and the color of the link)

Event Timeline

I've figured this is achievable by attaching a handler to the hashchange event. Would that interfere with something (or be overkill)?

It seems like a good idea to me, if you want to work on this. I'm surprised that I can't find an existing request for this.

There are many other things that use fragment links and hashchange events (e.g. media viewer), but it should be possible to implement this in a way that doesn't interfere with them.

Change 670014 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Nardog):
[mediawiki/core@master] makeCollapsible: Expand collapsed elements when the browser tries to scroll to a child

https://gerrit.wikimedia.org/r/670014

Change 670014 merged by jenkins-bot:
[mediawiki/core@master] Expand collapsed elements when the browser tries to scroll to a child

https://gerrit.wikimedia.org/r/670014

matmarex assigned this task to Nardog.

Thank you for the patch!

@matmarex Thank you for the review and the notes! Really appreciate the patience with which you've allowed me to learn the ropes.

I wanted to make sure it worked on the test wiki before I added this – and it does.

@Nardog Just to make sure I understand this correctly, something like this for Tech News:

Sections can be collapsed so you have to click on them to see the content. When you click on a link to a collapsed section the browser will scroll down to the heading and the collapsed section will expand so you can read it. Before this you had to manually scroll down and click on it to expand it.

@Johan Thanks for the heads-up! Pretty much, here's my attempt with minor copy-editing:

Content can be collapsed so you have to click on a toggle to see it. When you click a link to a section inside collapsed content, the content will now expand to reveal the section and the browser will scroll down to the section. Previously such links didn't work unless you manually expanded the content.

@Nardog Thanks, added to next issue. I did some minor simplification edits, to help all the en-2 or en-1 readers who don't get a translation.

I was so confused by this news. Isn't it a template that can be collapsed (which contains sections), rather than actually collapsing sections?

@Ainali The news doesn't mention collapsing sections. Any part of a page can be collapsed by putting it in e.g. <div class="mw-collapsible mw-collapsed">...</div>. Templates like {{Collapse}} are mere shorthands for that.

I don't disagree that phrasing in Tech News is often confusing (and I'm speaking as a speaker of English as a foreign language, for whom the style is apparently supposed to cater according to Johan above), but I'm afraid I fail to see what your confusion is in this particular case.