diff --git a/mkdocs_section_index/rewrites.py b/mkdocs_section_index/rewrites.py
index 2d46da1..26ac44a 100644
--- a/mkdocs_section_index/rewrites.py
+++ b/mkdocs_section_index/rewrites.py
@@ -60,6 +60,10 @@ def _transform_material_nav_item_template(src: str) -> str:
def _transform_material_tabs_item_template(src: str) -> str:
+ src = src.replace(
+ "{% if nav_item.children %}", "{% if nav_item.children and not nav_item.url %}"
+ )
+ # The above only for versions > 6.1.7, the below only for versions <= 6.1.7.
return src.replace(
"(nav_item.children | first).url",
"(nav_item.url or (nav_item.children | first).url)",
diff --git a/tests/rewrites/material-nav-item-3.yml b/tests/rewrites/material-nav-item-3.yml
new file mode 100644
index 0000000..f19dbe4
--- /dev/null
+++ b/tests/rewrites/material-nav-item-3.yml
@@ -0,0 +1,152 @@
+# https://github.com/squidfunk/mkdocs-material/blob/d754bd9a7172e8afbfdcb505180776caf7c3c839/material/partials/nav-item.html
+input: |
+ {#-
+ This file was automatically generated - do not edit
+ -#}
+ {% set features = config.theme.features or [] %}
+ {% set class = "md-nav__item" %}
+ {% if nav_item.active %}
+ {% set class = class ~ " md-nav__item--active" %}
+ {% endif %}
+ {% if nav_item.children %}
+ {% if "navigation.sections" in features and level == 1 + (
+ "navigation.tabs" in features
+ ) %}
+ {% set class = class ~ " md-nav__item--section" %}
+ {% endif %}
+
+ {% set checked = "checked" if nav_item.active %}
+ {% if "navigation.expand" in features and not checked %}
+
+ {% else %}
+
+ {% endif %}
+
+
+
+ {% elif nav_item == page %}
+
+ {% set toc = page.toc %}
+
+ {% if toc | first is defined and "\x3ch1 id=" in page.content %}
+ {% set toc = (toc | first).children %}
+ {% endif %}
+ {% if toc | first is defined %}
+
+ {% endif %}
+
+ {{ nav_item.title }}
+
+ {% if toc | first is defined %}
+ {% include "partials/toc.html" %}
+ {% endif %}
+
+ {% endif %}
+output: |
+ {#-
+ This file was automatically generated - do not edit
+ -#}
+ {% set features = config.theme.features or [] %}
+ {% set class = "md-nav__item" %}
+ {% if nav_item.active %}
+ {% set class = class ~ " md-nav__item--active" %}
+ {% endif %}
+ {% if nav_item.children %}
+ {% if "navigation.sections" in features and level == 1 + (
+ "navigation.tabs" in features
+ ) %}
+ {% set class = class ~ " md-nav__item--section" %}
+ {% endif %}
+
+ {% set checked = "checked" if nav_item.active %}
+ {% if "navigation.expand" in features and not checked %}
+
+ {% else %}
+
+ {% endif %}
+
+
+
+ {% elif nav_item == page %}
+
+ {% set toc = page.toc %}
+
+ {% if toc | first is defined and "\x3ch1 id=" in page.content %}
+ {% set toc = (toc | first).children %}
+ {% endif %}
+ {% if toc | first is defined %}
+
+ {% endif %}
+
+ {{ nav_item.title }}
+
+ {% if toc | first is defined %}
+ {% include "partials/toc.html" %}
+ {% endif %}
+
+ {% endif %}
diff --git a/tests/rewrites/material-tabs-item-2.yml b/tests/rewrites/material-tabs-item-2.yml
new file mode 100644
index 0000000..943fb72
--- /dev/null
+++ b/tests/rewrites/material-tabs-item-2.yml
@@ -0,0 +1,59 @@
+# https://github.com/squidfunk/mkdocs-material/blob/d754bd9a7172e8afbfdcb505180776caf7c3c839/material/partials/tabs-item.html
+input: |
+ {#-
+ This file was automatically generated - do not edit
+ -#}
+ {% if not class %}
+ {% set class = "md-tabs__link" %}
+ {% if nav_item.active %}
+ {% set class = class ~ " md-tabs__link--active" %}
+ {% endif %}
+ {% endif %}
+ {% if nav_item.children %}
+ {% set title = title | d(nav_item.title) %}
+ {% set nav_item = nav_item.children | first %}
+ {% if nav_item.children %}
+ {% include "partials/tabs-item.html" %}
+ {% else %}
+
+ {% endif %}
+output: |
+ {#-
+ This file was automatically generated - do not edit
+ -#}
+ {% if not class %}
+ {% set class = "md-tabs__link" %}
+ {% if nav_item.active %}
+ {% set class = class ~ " md-tabs__link--active" %}
+ {% endif %}
+ {% endif %}
+ {% if nav_item.children and not nav_item.url %}
+ {% set title = title | d(nav_item.title) %}
+ {% set nav_item = nav_item.children | first %}
+ {% if nav_item.children and not nav_item.url %}
+ {% include "partials/tabs-item.html" %}
+ {% else %}
+