Skip to content

Commit 292d563

Browse files
committed
Fixed navigation pruning when tabs + sections are active
1 parent 1698fd8 commit 292d563

File tree

2 files changed

+61
-23
lines changed

2 files changed

+61
-23
lines changed

material/templates/partials/nav-item.html

+23-10
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,33 @@
5353
{% endif %}
5454
{% endfor %}
5555
{% endif %}
56-
{% set tabs = "navigation.tabs" in features %}
57-
{% set sections = "navigation.sections" in features %}
58-
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
59-
{% set class = class ~ " md-nav__item--section" %}
60-
{% set is_section = true %}
61-
{% elif not nav_item.active and "navigation.prune" in features %}
62-
{% set class = class ~ " md-nav__item--pruned" %}
63-
{% set is_pruned = true %}
56+
{% if "navigation.tabs" in features %}
57+
{% if level == 1 and nav_item.active %}
58+
{% set class = class ~ " md-nav__item--section" %}
59+
{% set is_section = true %}
60+
{% endif %}
61+
{% if "navigation.sections" in features %}
62+
{% if level == 2 and nav_item.parent.active %}
63+
{% set class = class ~ " md-nav__item--section" %}
64+
{% set is_section = true %}
65+
{% endif %}
66+
{% endif %}
67+
{% elif "navigation.sections" in features %}
68+
{% if level == 1 %}
69+
{% set class = class ~ " md-nav__item--section" %}
70+
{% set is_section = true %}
71+
{% endif %}
72+
{% endif %}
73+
{% if "navigation.prune" in features %}
74+
{% if not is_section and not nav_item.active %}
75+
{% set class = class ~ " md-nav__item--pruned" %}
76+
{% set is_pruned = true %}
77+
{% endif %}
6478
{% endif %}
6579
<li class="{{ class }} md-nav__item--nested">
6680
{% if not is_pruned %}
6781
{% set checked = "checked" if nav_item.active %}
68-
{% set is_expanded = "navigation.expand" in features %}
69-
{% if is_expanded and not checked %}
82+
{% if "navigation.expand" in features and not checked %}
7083
{% set indeterminate = "md-toggle--indeterminate" %}
7184
{% endif %}
7285
<input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}>

src/templates/partials/nav-item.html

+38-13
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,43 @@
107107
{% endfor %}
108108
{% endif %}
109109

110-
<!-- Determine whether to render item as a section -->
111-
{% set tabs = "navigation.tabs" in features %}
112-
{% set sections = "navigation.sections" in features %}
113-
{% if tabs and level == 1 or sections and tabs >= level - 1 %}
114-
{% set class = class ~ " md-nav__item--section" %}
115-
{% set is_section = true %}
116-
117-
<!-- Determine whether to prune inactive item -->
118-
{% elif not nav_item.active and "navigation.prune" in features %}
119-
{% set class = class ~ " md-nav__item--pruned" %}
120-
{% set is_pruned = true %}
110+
<!-- Navigation tabs -->
111+
{% if "navigation.tabs" in features %}
112+
113+
<!-- Render 1st level active item as section -->
114+
{% if level == 1 and nav_item.active %}
115+
{% set class = class ~ " md-nav__item--section" %}
116+
{% set is_section = true %}
117+
{% endif %}
118+
119+
<!-- Navigation tabs + sections -->
120+
{% if "navigation.sections" in features %}
121+
122+
<!-- Render 2nd level items with nested items as sections -->
123+
{% if level == 2 and nav_item.parent.active %}
124+
{% set class = class ~ " md-nav__item--section" %}
125+
{% set is_section = true %}
126+
{% endif %}
127+
{% endif %}
128+
129+
<!-- Navigation sections -->
130+
{% elif "navigation.sections" in features %}
131+
132+
<!-- Render 1st level items with nested items as sections -->
133+
{% if level == 1 %}
134+
{% set class = class ~ " md-nav__item--section" %}
135+
{% set is_section = true %}
136+
{% endif %}
137+
{% endif %}
138+
139+
<!-- Navigation pruning -->
140+
{% if "navigation.prune" in features %}
141+
142+
<!-- Prune item if it is not a section and not active -->
143+
{% if not is_section and not nav_item.active %}
144+
{% set class = class ~ " md-nav__item--pruned" %}
145+
{% set is_pruned = true %}
146+
{% endif %}
121147
{% endif %}
122148

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

128154
<!-- Determine checked and indeterminate state -->
129-
{% set is_expanded = "navigation.expand" in features %}
130-
{% if is_expanded and not checked %}
155+
{% if "navigation.expand" in features and not checked %}
131156
{% set indeterminate = "md-toggle--indeterminate" %}
132157
{% endif %}
133158

0 commit comments

Comments
 (0)