1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-30 18:24:35 +01:00

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 %} {% endif %}
{% elif not nav_item.active and "navigation.prune" in features %} {% if "navigation.sections" in features %}
{% set class = class ~ " md-nav__item--pruned" %} {% if level == 2 and nav_item.parent.active %}
{% set is_pruned = true %} {% 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 %} {% 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,17 +107,43 @@
{% 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 %}
{% set class = class ~ " md-nav__item--section" %}
{% set is_section = true %}
<!-- Determine whether to prune inactive item --> <!-- Render 1st level active item as section -->
{% elif not nav_item.active and "navigation.prune" in features %} {% if level == 1 and nav_item.active %}
{% set class = class ~ " md-nav__item--pruned" %} {% set class = class ~ " md-nav__item--section" %}
{% set is_pruned = true %} {% 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 %} {% endif %}
<!-- Nested navigation item --> <!-- Nested navigation item -->
@ -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 %}