From 19bdd3cb149d8fb4e3b50b358acb26d53791736c Mon Sep 17 00:00:00 2001 From: Yarn-e Date: Fri, 14 Nov 2025 10:26:13 +0100 Subject: [PATCH] feat: Add support for unlimited fieldset tabs items --- src/unfold/static/unfold/js/app.js | 20 ++++++++++---- .../unfold/helpers/fieldsets_tabs.html | 26 +++++++++++++------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/unfold/static/unfold/js/app.js b/src/unfold/static/unfold/js/app.js index 223ada32c..a7635d93b 100644 --- a/src/unfold/static/unfold/js/app.js +++ b/src/unfold/static/unfold/js/app.js @@ -10,14 +10,16 @@ window.addEventListener("load", (e) => { warnWithoutSaving(); tabNavigation(); + + tabNavigation("fieldset-"); }); /************************************************************* * Move not visible tab items to dropdown *************************************************************/ -function tabNavigation() { - const itemsDropdown = document.getElementById("tabs-dropdown"); - const itemsList = document.getElementById("tabs-items"); +function tabNavigation(prefix = "") { + const itemsDropdown = document.getElementById(prefix + "tabs-dropdown"); + const itemsList = document.getElementById(prefix + "tabs-items"); const widths = []; if (!itemsDropdown || !itemsList) { @@ -32,7 +34,7 @@ function tabNavigation() { function handleTabNavigationResize() { const contentWidth = document.getElementById("content").offsetWidth; - const tabsWidth = document.getElementById("tabs-wrapper").scrollWidth; + const tabsWidth = document.getElementById(prefix + "tabs-wrapper").scrollWidth; const availableWidth = itemsList.parentElement.offsetWidth - itemsList.offsetWidth - 48; @@ -47,7 +49,7 @@ function tabNavigation() { // If there is still not enough space, move the last item to the dropdown again if ( document.getElementById("content").offsetWidth < - document.getElementById("tabs-wrapper").scrollWidth + document.getElementById(prefix + "tabs-wrapper").scrollWidth ) { handleTabNavigationResize(); } @@ -70,6 +72,14 @@ function tabNavigation() { itemsDropdown.parentElement.classList.add("hidden"); } else { itemsDropdown.parentElement.classList.remove("hidden"); + + // After adding the dropdown item, check again if we need to move items + if ( + document.getElementById("content").offsetWidth < + document.getElementById(prefix + "tabs-wrapper").scrollWidth + ) { + handleTabNavigationResize(); + } } } } diff --git a/src/unfold/templates/unfold/helpers/fieldsets_tabs.html b/src/unfold/templates/unfold/helpers/fieldsets_tabs.html index c8a07134b..f967fe30e 100644 --- a/src/unfold/templates/unfold/helpers/fieldsets_tabs.html +++ b/src/unfold/templates/unfold/helpers/fieldsets_tabs.html @@ -3,14 +3,24 @@ {% with tabs=adminform|tabs %} {% if tabs %}
-
- +
+
+ + + +
{% for fieldset in tabs %}