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 %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% set tabs = "navigation.tabs" in features %} {% if "navigation.tabs" in features %}
{% set sections = "navigation.sections" in features %} {% if level == 1 and nav_item.active %}
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
{% set class = class ~ " md-nav__item--section" %} {% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %} {% set is_section = true %}
{% elif not nav_item.active and "navigation.prune" in features %} {% 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 class = class ~ " md-nav__item--pruned" %}
{% set is_pruned = true %} {% set is_pruned = true %}
{% endif %} {% endif %}
{% endif %}
<li class="{{ class }} md-nav__item--nested"> <li class="{{ class }} md-nav__item--nested">
{% if not is_pruned %} {% if not is_pruned %}
{% set checked = "checked" if nav_item.active %} {% set checked = "checked" if nav_item.active %}
{% set is_expanded = "navigation.expand" in features %} {% if "navigation.expand" in features and not checked %}
{% if is_expanded and not checked %}
{% set indeterminate = "md-toggle--indeterminate" %} {% set indeterminate = "md-toggle--indeterminate" %}
{% endif %} {% endif %}
<input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}> <input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}>

View File

@ -107,18 +107,44 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<!-- Determine whether to render item as a section --> <!-- Navigation tabs -->
{% set tabs = "navigation.tabs" in features %} {% if "navigation.tabs" in features %}
{% set sections = "navigation.sections" in features %}
{% if tabs and level == 1 or sections and tabs >= level - 1 %} <!-- Render 1st level active item as section -->
{% if level == 1 and nav_item.active %}
{% set class = class ~ " md-nav__item--section" %} {% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %} {% set is_section = true %}
{% endif %}
<!-- Determine whether to prune inactive item --> <!-- Navigation tabs + sections -->
{% elif not nav_item.active and "navigation.prune" in features %} {% 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 class = class ~ " md-nav__item--pruned" %}
{% set is_pruned = true %} {% set is_pruned = true %}
{% endif %} {% endif %}
{% endif %}
<!-- Nested navigation item --> <!-- Nested navigation item -->
<li class="{{ class }} md-nav__item--nested"> <li class="{{ class }} md-nav__item--nested">
@ -126,8 +152,7 @@
{% set checked = "checked" if nav_item.active %} {% set checked = "checked" if nav_item.active %}
<!-- Determine checked and indeterminate state --> <!-- Determine checked and indeterminate state -->
{% set is_expanded = "navigation.expand" in features %} {% if "navigation.expand" in features and not checked %}
{% if is_expanded and not checked %}
{% set indeterminate = "md-toggle--indeterminate" %} {% set indeterminate = "md-toggle--indeterminate" %}
{% endif %} {% endif %}