Skip to content

Commit

Permalink
feat(sub-navigation): allow adding HTML classes to sub-navigation items
Browse files Browse the repository at this point in the history
  • Loading branch information
ushkarev committed Mar 29, 2022
1 parent 541c91e commit 81b60cb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/moj/components/sub-navigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This component accepts the following arguments.
|text|string|Yes|If `html` is set, this is not required. Text to use within the anchor. If `html` is provided, the `text` argument will be ignored.|
|html|string|Yes|If `text` is set, this is not required. HTML to use within the anchor. If `html` is provided, the `text` argument will be ignored.|
|active|boolean|No|Flag to mark the navigation item as active or not. Defaults to `false`.|
|classes|string|No|Classes to add to the list `li` item.|
|attributes|object|No|HTML attributes (for example data attributes) to add to the navigation item anchor.|

*Warning: If you’re using Nunjucks macros in production be aware that using HTML arguments, or ones ending with `.html` can be at risk from [cross-site scripting](https://en.wikipedia.org/wiki/Cross-site_scripting) attacks. More information about security vulnerabilities can be found in the [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#user-defined-templates-warning).*
2 changes: 1 addition & 1 deletion src/moj/components/sub-navigation/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ul class="moj-sub-navigation__list">

{%- for item in params.items %}
<li class="moj-sub-navigation__item">
<li class="moj-sub-navigation__item {{- ' ' + item.classes if item.classes}}">
<a class="moj-sub-navigation__link" {{ 'aria-current="page"' | safe if item.active }} href="{{ item.href }}" {%- for attribute, value in item.attributes -%} {{ attribute }}="{{ value }}"{% endfor %}>
{{- item.html | safe if item.html else item.text -}}
</a>
Expand Down

0 comments on commit 81b60cb

Please sign in to comment.