Nav Item

template 2 required7 optional2 slots1 a11y rule

Preview

active
python
nav_item(label='Home', url='#', active=True)

Usage

views.py
python
from djust import LiveView


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.label = 'Home'
my_template.html
django
{% load theme_components %}
{% theme_nav_item label=label url='#' active=True %}

Props

NameTypeRequiredDefault
labelstrrequired
urlstrrequired
iconOptional[str]
activeOptional[bool]
badgeOptional[str]
css_prefixstr
attrsdict
slot_iconstr
slot_badgestr

Accessibility

RequirementElementAttributeValue
Active nav item must have aria-current=pageaaria-currentpage

Slots

slot_icon slot_badge
Source & styles
FilePathNotes
templatedjust_theming/components/nav_item.htmlCopy it to the same path in your project, or per theme under djust_theming/themes/<theme>/components/.
cssdjust_theming/catalogue.cssDefines 2 of this component's classes at line 42, 44. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/scaffold.cssDefines 2 of this component's classes at line 132, 147. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/components.cssDefines 1 of this component's classes at line 342. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_components/components.cssDefines 1 of this component's classes at line 245. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
Template source — nav_item.html
django
<a href="{{ url }}"
   class="{{ css_prefix }}nav-link{% if is_active %} active{% endif %} {% if attrs.class %}{{ attrs.class }}{% endif %}"
   {% if is_active %}aria-current="page"{% endif %}
   {% if attrs.id %}id="{{ attrs.id }}"{% endif %}
   {% if attrs.navigate and url %}dj-navigate="{{ url }}"{% endif %}>
    {% if slot_icon %}{{ slot_icon|safe }}{% elif icon %}<span class="{{ css_prefix }}nav-link-icon">{{ icon }}</span>{% endif %}
    <span class="{{ css_prefix }}nav-link-label">{{ label }}</span>
    {% if slot_badge %}{{ slot_badge|safe }}{% elif badge %}<span class="{{ css_prefix }}nav-link-badge">{{ badge }}</span>{% endif %}
</a>