Problem/Motivation
Radix v6 runs afoul of a core bug. In radix, the local tasks are displayed using the nav-item component. nav-item.twig contains:
{{ link|add_class('nav-link', is_active ? 'active' : '') }}
The problem arises when visiting the page for a secondary local task. Core add a "is-active" CSS class to the link in the primary tab, using $element['#options']['attributes']['class'], as is standard for a link render element.
However the above add_class() twig filter add the 'nav-link' (and possibly 'active') classes to $element['#attributes']. The Link render element combines these attributes, but (incorrectly) does not merge the classes. The result is a loss of the classes added via twig for the active primary tab.
I have posted a patch in the parent issue to fix this in core. To avoid this issue in radix, you could unset the classes in #options in a preprocess function for local tasks primary and secondary. Still, there could be other uses of the nav-link component which would trigger the issue
Steps to reproduce
Create a page with primary and secondary local tasks. Visit a page for a secondary tasks. Observe that the primary tab is displayed without the "nav-link" class.
Proposed resolution
Option 1: Document that the patch in the related issue be installed when using radix v6 if you have secondary local tasks.
Option 2: Move the attributes from $element['#options']['attributes'] to $element['#attributes'] in a preprocess function for local tasks (primary and secondary).
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Local-tasks-link-missing-nav-link-class-3494018.patch | 668 bytes | deepali sardana |
Comments
Comment #2
deepali sardana commentedComment #3
deepali sardana commentedI have created the patch please review it
Comment #4
deepali sardana commentedComment #5
danchadwick commentedThanks for the patch, but that does not address the issue. The issue lies in the merging of the classes as described in #3494015. The add_class() twig function will have the same issue whether it passes the classes as two strings or as an array.
The fix is either to patch core or avoid the issue in the preprocess function. I'm not sure which path the maintainers prefer.
Comment #7
danchadwick commentedI resolved this by preprocessing the menu local tasks, rather than relying on the bug in core being fixed. This circumvents the core bug.