Issue Feature Closed

#90994Add "active" class to current page to the default fluid_styled_content menu_pages, menu_sitemap_pages etc.

Jonas Eberle 04/10/20, 13:24 updated 10/04/22, 14:00

Description

The data is already in the template, just the default templates would need to be changed.

Reviews 1

History 1320

  1. Riccardo De Contardi commented 04/10/20, 16:44

    I’d vote for

    - put class on the <li> tag
    - use separate classes for active and current states

    [additional, opinionated]

    would be nice maybe to have BEM classes, like

    - .t3-menu on the <ul> tag
    - .t3-menu__item on each menu item
    - .t3-menu__item--active and .t3-menu__item--current for the states

    [warning]

    It is very likely that if you want to use a framework like Bootstrap or Foundation you’ll have to do additional work in rewriting everything!

    Framework menu ( <ul> ) class menu item ( <li> ) class anchor ( <a> ) class active state class current state class
    Twitter Bootstrap nav nav-item nav-link active (on <a> ) none
    Zurb Foundation menu none none is-active (on <li> ) none

    This topic requires carefulness… honestly I’d prefer to keep TYPO3 on frontend agnostic from frameworks, and let the integrators use which one they prefer.

  2. Jonas Eberle commented 04/10/20, 18:39

    @Riccardo: Sorry, our research overlapped here ;) I didn’t check for new posts before.

    I checked these:
    Foundation .vertical.menu on the <li> – https://get.foundation/sites/docs/menu.html#vertical-menu
    Bootstrap 3 .nav-pills on the <li> – https://getbootstrap.com/docs/3.4/components/#nav
    Bootstrap 4 nav components put it on the <a> but need additional markup anyways: https://getbootstrap.com/docs/4.4/components/navs/#vertical (why?…)

    — so I would also favor <li>

    Undecided about BEM – useful yes, but very cluttery and should not be introduced for a single default content IMHO but if, then for all.

    I would like to hear Benji about it, too.
    I hope we’ll talk about it in the next call of the rendering group of the structured content initiative.

    This is how I currently integrate menu_sitemap_pages with Bootstrap 3:

    // (scss)
    .frame-type-menu_sitemap_pages {
        ul {
            @extend .nav;
            @extend .nav-pills;
            @extend .nav-stacked;
            list-style: none;
            padding-left: 0;
    
            ul {
                padding-left: 30px;
            }
        }
    }

    This covers the base already for a directory structure.
    It produces some unnecessary CSS, but saves me from adapting default templates which I think is a big plus for maintainability.

  3. Riccardo De Contardi commented 04/10/21, 21:49

    Just to write something again on this topic: another nice suggestion is using the “namespaced CSS” convention

    in this convention

    - the menu should be a component so the prefix would be c- (IMHO, I would head some other opinions) or, as on my previous post, we could just imagine a t3- namespace
    - the active state is just is-active (Foundation already follows it)

    <ul class="c-menu">
       <li class="is-active">....</li>
    </ul>

    or if you prefer the anchor being “active”:

    <ul class="c-menu">
       <li><a class="is-active">....</a></li>
    </ul>

    some articles:

    https://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces/
    https://css-tricks.com/combining-the-powers-of-sem-and-bio-for-improving-css/

  4. Benni Mack commented and changed status New Needs Feedback removed the assignee 01/06/22, 12:33

    How to proceed here? Jonas, do you want to create a patch?

  5. Jonas Eberle commented 01/13/22, 14:52

    Yes, I can do that.

    Did we agree on a simple `

  6. ` and integrators can go from there?
  • Benni Mack commented 01/13/22, 20:34

    Jonas Eberle wrote in #note-5:
    > Yes, I can do that.
    >
    > Did we agree on a simple `

  • ` and integrators can go from there?
  • Sure, why not…

  • Gerrit Code Review pushed patch set 1 for main to change 73048 status Needs Feedback Under Review 01/17/22, 21:11

  • Gerrit Code Review pushed patch set 2 for main to change 73048 02/01/22, 06:03

  • Gerrit Code Review pushed patch set 3 for main to change 73048 02/01/22, 07:51

  • Michael Telgkamp commented 02/01/22, 07:56

    The accessible way to mark the current page is adding `aria-current=“page”` so I would like this to be used.

    It can also be used to style the link using the selector [aria-current=“page”]. It is important to have the class on the Tag, not on the link, but that should not be a problem.

  • Jonas Eberle commented 02/01/22, 08:06

    Thanks.
    I am changing it to

      <li>
        <a aria-current="page">...</a>
      </li>
  • Jonas Eberle commented 02/01/22, 08:15

    In order to allow styling of the

  • as well, would you prefer to add some CSS classes, too? (not an accessiblity question)
  • The problem being that we still do not have a selector like `li:has([aria-current=page])` as far as I know.

    Like

    <li class="is-active">
      <a aria-current="page">...</a>
    </li>

    And while we are at it, should we implement that for nested trees (used in the CE “Sitemap” for example) as well?

    <ul>
      <li class="has-active">
        <a href=...>...</a>
        <ul>
          <li class="is-active">
            <a aria-current="page" href=...>...</a>
          </li>
        </ul>
      </li>
    </ul>
  • Michael Telgkamp commented 02/01/22, 16:48

    I would like to suggest to use active (or is-active ) as class name for an li in the rootline and current (or is-current ) as class for the li for the current page (to also keep it in line with the `aria-current` naming).

  • Jonas Eberle commented 02/01/22, 18:02

    I agree.

  • Gerrit Code Review pushed patch set 4 for main to change 73048 02/04/22, 17:30

  • Gerrit Code Review pushed patch set 5 for main to change 73048 02/09/22, 16:23

  • Gerrit Code Review pushed patch set 6 for main to change 73048 02/09/22, 16:36

  • Gerrit Code Review pushed patch set 7 for main to change 73048 02/09/22, 16:39

  • Anonymous commented and changed status Under Review Resolved done 0 % 100 % 02/10/22, 07:40

    Applied in changeset commit:ea7cca56f7936fa0c2fe8a25dd82961d7837dd50.

  • Benni Mack changed status Resolved Closed 10/04/22, 14:00