Feature #90994
closedAdd "active" class to current page to the default fluid_styled_content menu_pages, menu_sitemap_pages etc.
100%
Description
The data is already in the template, just the default templates would need to be changed.
Updated by Riccardo De Contardi over 4 years ago
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.
Updated by Jonas Eberle over 4 years ago
@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.
Updated by Riccardo De Contardi over 3 years ago
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/
Updated by Benni Mack almost 3 years ago
- Status changed from New to Needs Feedback
- Assignee deleted (
Benjamin Kott)
How to proceed here? Jonas, do you want to create a patch?
Updated by Jonas Eberle almost 3 years ago
Yes, I can do that.
Did we agree on a simple `<li class="is-active">` and integrators can go from there?
Updated by Benni Mack almost 3 years ago
Jonas Eberle wrote in #note-5:
Yes, I can do that.
Did we agree on a simple `<li class="is-active">` and integrators can go from there?
Sure, why not...
Updated by Gerrit Code Review almost 3 years ago
- Status changed from Needs Feedback to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Gerrit Code Review almost 3 years ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Gerrit Code Review almost 3 years ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Michael Telgkamp almost 3 years ago
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 <a> Tag, not on the link, but that should not be a problem.
Updated by Jonas Eberle almost 3 years ago
Thanks.
I am changing it to
<li> <a aria-current="page">...</a> </li>
Updated by Jonas Eberle almost 3 years ago
In order to allow styling of the <li> 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>
Updated by Michael Telgkamp almost 3 years ago
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).
Updated by Gerrit Code Review almost 3 years ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Gerrit Code Review almost 3 years ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Gerrit Code Review almost 3 years ago
Patch set 6 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Gerrit Code Review almost 3 years ago
Patch set 7 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73048
Updated by Anonymous almost 3 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset ea7cca56f7936fa0c2fe8a25dd82961d7837dd50.