Fixed navigation pruning when tabs + sections are active

This commit is contained in:
squidfunk 2024-02-09 13:30:31 +07:00
parent 1698fd8172
commit 292d563cb4
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
2 changed files with 60 additions and 22 deletions

View File

@ -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 }}>

View File

@ -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 %}
<!-- Navigation tabs -->
{% if "navigation.tabs" in features %}
<!-- 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 %}
<!-- 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 -->
@ -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 %}