Problem/Motivation

Menu items with nolink paths / links are rendered as empty a href="" links but they should be rendered without the a href, with just spans. The same issue came up in the USWDS Base theme - https://www.drupal.org/project/uswds_base/issues/3252489 - not sure if that solution would work here but I'll starting looking through the menu twig templates. This will be take me a long time so I'd happily accept any support offered to speed things along.

CommentFileSizeAuthor
#7 after.png58.03 KBsayan_k_dutta
#7 before.png68.48 KBsayan_k_dutta

Issue fork uswds-3488501

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

stevenovy created an issue. See original summary.

debrup’s picture

Assigned: Unassigned » debrup

Working on it.

debrup’s picture

Fixed the issue by modifying the twig files.

- Added checks to see if the url has a link or no link at all.
- Modified few manual 'a' tags to the drupal twig link() filter for better code optimization and automatic handling of the given issue :)

Please review the changes and check if the issue has been fixed or not.

Note: Since drupal twigs link() filter does not allow extra html tags in its text, so I have not changed those links which have other html tags inside the 'span' tags.

debrup’s picture

Assigned: debrup » Unassigned
Status: Active » Needs review
stevenovy’s picture

Installed and reviewed the changes, looks good, works well.

sayan_k_dutta’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new68.48 KB
new58.03 KB

Reviewed the changes. Looks Good. Attaching screenshot of the same and moving to RTBC.

jrglasgow made their first commit to this issue’s fork.

  • jrglasgow committed fbbe4346 on 3.x authored by debrup
    Resolved #3488501: Menu entries with <nolink> paths are rendered as...
jrglasgow’s picture

Status: Reviewed & tested by the community » Fixed
simplyshipley’s picture

It appears that this MR introduced a bug when creating the links in the menu--sidebar_first.html.yml and menu--sidebar_second.html.yml files. The new code creates a link, but uses item.text instead of item.title which was previously used. This causes the links to be created without a label.

Updated code:

      <li class="usa-sidenav__item">
        {{ link(item.text, item.url, create_attribute({'class': classes})) }}

Previous code:

      <li class="usa-sidenav__item">
        <a href="{{ item.url }}"{% if item.in_active_trail %} class="usa-current"{% endif %}>
          <span>{{ item.title }}</span>
        </a>

Status: Fixed » Closed (fixed)

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