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).

Comments

danchadwick created an issue. See original summary.

deepali sardana’s picture

Assigned: Unassigned »
deepali sardana’s picture

Assigned: » Unassigned
StatusFileSize
new668 bytes

I have created the patch please review it

deepali sardana’s picture

Status: Active » Needs review
danchadwick’s picture

Status: Needs review » Needs work

Thanks 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.

  • danchadwick committed 5a51ae2c on 6.0.x
    Issue #3494018 by danchadwick: Local tasks link missing nav-link class'.
    
danchadwick’s picture

Status: Needs work » Fixed

I resolved this by preprocessing the menu local tasks, rather than relying on the bug in core being fixed. This circumvents the core bug.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.