Skip to content

Commit

Permalink
Fixed navigation pruning when tabs + sections are active
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Feb 9, 2024
1 parent 1698fd8 commit 292d563
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
33 changes: 23 additions & 10 deletions material/templates/partials/nav-item.html
Expand Up @@ -53,20 +53,33 @@
{% endif %}
{% endfor %}
{% endif %}
{% set tabs = "navigation.tabs" in features %}
{% set sections = "navigation.sections" in features %}
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% elif not nav_item.active and "navigation.prune" in features %}
{% set class = class ~ " md-nav__item--pruned" %}
{% set is_pruned = true %}
{% if "navigation.tabs" in features %}
{% if level == 1 and nav_item.active %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% endif %}
{% if "navigation.sections" in features %}
{% if level == 2 and nav_item.parent.active %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% endif %}
{% endif %}
{% elif "navigation.sections" in features %}
{% if level == 1 %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% endif %}
{% endif %}
{% if "navigation.prune" in features %}
{% if not is_section and not nav_item.active %}
{% set class = class ~ " md-nav__item--pruned" %}
{% set is_pruned = true %}
{% endif %}
{% endif %}
<li class="{{ class }} md-nav__item--nested">
{% if not is_pruned %}
{% set checked = "checked" if nav_item.active %}
{% set is_expanded = "navigation.expand" in features %}
{% if is_expanded and not checked %}
{% if "navigation.expand" in features and not checked %}
{% set indeterminate = "md-toggle--indeterminate" %}
{% endif %}
<input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}>
Expand Down
51 changes: 38 additions & 13 deletions src/templates/partials/nav-item.html
Expand Up @@ -107,17 +107,43 @@
{% endfor %}
{% endif %}

<!-- Determine whether to render item as a section -->
{% set tabs = "navigation.tabs" in features %}
{% set sections = "navigation.sections" in features %}
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}

<!-- Determine whether to prune inactive item -->
{% elif not nav_item.active and "navigation.prune" in features %}
{% set class = class ~ " md-nav__item--pruned" %}
{% set is_pruned = true %}
<!-- Navigation tabs -->
{% if "navigation.tabs" in features %}

<!-- Render 1st level active item as section -->
{% if level == 1 and nav_item.active %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% endif %}

<!-- Navigation tabs + sections -->
{% if "navigation.sections" in features %}

<!-- Render 2nd level items with nested items as sections -->
{% if level == 2 and nav_item.parent.active %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% endif %}
{% endif %}

<!-- Navigation sections -->
{% elif "navigation.sections" in features %}

<!-- Render 1st level items with nested items as sections -->
{% if level == 1 %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
{% endif %}
{% endif %}

<!-- Navigation pruning -->
{% if "navigation.prune" in features %}

<!-- Prune item if it is not a section and not active -->
{% if not is_section and not nav_item.active %}
{% set class = class ~ " md-nav__item--pruned" %}
{% set is_pruned = true %}
{% endif %}
{% endif %}

<!-- Nested navigation item -->
Expand All @@ -126,8 +152,7 @@
{% set checked = "checked" if nav_item.active %}

<!-- Determine checked and indeterminate state -->
{% set is_expanded = "navigation.expand" in features %}
{% if is_expanded and not checked %}
{% if "navigation.expand" in features and not checked %}
{% set indeterminate = "md-toggle--indeterminate" %}
{% endif %}

Expand Down

0 comments on commit 292d563

Please sign in to comment.