Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional navigation items #238

Merged
merged 2 commits into from
Jul 9, 2024
Merged

Conversation

paulrobertlloyd
Copy link
Contributor

@paulrobertlloyd paulrobertlloyd commented Jul 9, 2024

Makes it possible to add conditions to navigation items:

{{ xGovukSecondaryNavigation({
  classes: "nhsuk-u-margin-bottom-6",
  items: [
    {
      text: "Apples",
      href: "/apples/"
    } if role == "juicer",
    {
      text: "Bananas",
      href: "/bananas/"
    },
    {
      text: "Oranges",
      href: "/oranges/"
    } if role == "juicer"
  ]
}) }}

Without this change, an empty object is returned, which in turn creates an empty HTML list item.

The Primary navigation component previously checked for the presence of item.href, but have made this consistent so that only item need be present.

Also updated the indentation to be a bit more consistent across the navigation components, see edbb9f6 for the actual changes.

Copy link
Contributor

@frankieroberto frankieroberto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I always forget about that inline condition trick! Nice. Might be worth documenting somewhere too?

Hard to review as you changed all the indentation at the same time 😛, but looks good. Thanks!

@paulrobertlloyd
Copy link
Contributor Author

Hard to review as you changed all the indentation at the same time 😛

Cough:

Also updated the indentation to be a bit more consistent across the navigation components, see edbb9f6 for the actual changes.

@paulrobertlloyd paulrobertlloyd merged commit 65ce48f into main Jul 9, 2024
2 checks passed
@paulrobertlloyd paulrobertlloyd deleted the conditional-navigation-items branch July 9, 2024 21:57
@frankieroberto
Copy link
Contributor

@paulrobertlloyd heh, I somehow missed that last para and went straight to the Files changed tab... 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants