From 3f00c923b34ead15c87c068cb18d090ccf2d4c09 Mon Sep 17 00:00:00 2001 From: Clayton Date: Tue, 13 Jan 2026 08:20:29 -0600 Subject: [PATCH 1/3] fix: auto-expand parent Section Break when nested item is active --- frappe/public/js/frappe/ui/sidebar/sidebar.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/frappe/public/js/frappe/ui/sidebar/sidebar.js b/frappe/public/js/frappe/ui/sidebar/sidebar.js index 4dbee57dbb..b283454b69 100644 --- a/frappe/public/js/frappe/ui/sidebar/sidebar.js +++ b/frappe/public/js/frappe/ui/sidebar/sidebar.js @@ -155,6 +155,38 @@ frappe.ui.Sidebar = class Sidebar { set_active_workspace_item() { if (this.is_route_in_sidebar()) { this.active_item.addClass("active-sidebar"); + this.expand_parent_section_if_needed(); + } + } + + expand_parent_section_if_needed() { + if (!this.active_item) return; + + // Check if the active item is inside a nested container (child of a Section Break) + // active_item is .standard-sidebar-item, we need to check its container + const $item_container = this.active_item.closest(".sidebar-item-container"); + if ($item_container.length === 0) return; + + const $nested_container = $item_container.parent(".nested-container"); + if ($nested_container.length === 0) return; + + // Find the parent Section Break container + const $section_break_container = $nested_container.closest(".section-item"); + if ($section_break_container.length === 0) return; + + // Find the Section Break item instance that contains this nested item + const section_label = $section_break_container.attr("item-name"); + if (!section_label) return; + + // Find the SectionBreakSidebarItem instance + for (let item of this.items) { + if (item.item && item.item.type === "Section Break" && item.item.label === section_label) { + // Expand the section break if it's collapsed + if (item.collapsed) { + item.open(); + } + break; + } } } From 1429632791e2103220c05558e9cbb42e881ea0c0 Mon Sep 17 00:00:00 2001 From: Clayton Date: Tue, 13 Jan 2026 10:45:43 -0600 Subject: [PATCH 2/3] fix: prettier --- frappe/public/js/frappe/ui/sidebar/sidebar.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/ui/sidebar/sidebar.js b/frappe/public/js/frappe/ui/sidebar/sidebar.js index b283454b69..c28fc69890 100644 --- a/frappe/public/js/frappe/ui/sidebar/sidebar.js +++ b/frappe/public/js/frappe/ui/sidebar/sidebar.js @@ -180,7 +180,11 @@ frappe.ui.Sidebar = class Sidebar { // Find the SectionBreakSidebarItem instance for (let item of this.items) { - if (item.item && item.item.type === "Section Break" && item.item.label === section_label) { + if ( + item.item && + item.item.type === "Section Break" && + item.item.label === section_label + ) { // Expand the section break if it's collapsed if (item.collapsed) { item.open(); From c41ba40c6297cb861cf7e8995016e2e9a3542ab4 Mon Sep 17 00:00:00 2001 From: sokumon Date: Wed, 14 Jan 2026 00:12:00 +0530 Subject: [PATCH 3/3] refactor: sidebar expand when active element is inside it --- frappe/public/js/frappe/ui/sidebar/sidebar.js | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/frappe/public/js/frappe/ui/sidebar/sidebar.js b/frappe/public/js/frappe/ui/sidebar/sidebar.js index c28fc69890..3a1ebcaf36 100644 --- a/frappe/public/js/frappe/ui/sidebar/sidebar.js +++ b/frappe/public/js/frappe/ui/sidebar/sidebar.js @@ -155,41 +155,33 @@ frappe.ui.Sidebar = class Sidebar { set_active_workspace_item() { if (this.is_route_in_sidebar()) { this.active_item.addClass("active-sidebar"); - this.expand_parent_section_if_needed(); + this.expand_parent_section(); } } - expand_parent_section_if_needed() { + expand_parent_section() { if (!this.active_item) return; + let active_section; + $(".section-item").each((index, element) => { + if (element.contains(this.active_item.get(0))) { + active_section = element.dataset.id; + } + }); - // Check if the active item is inside a nested container (child of a Section Break) - // active_item is .standard-sidebar-item, we need to check its container - const $item_container = this.active_item.closest(".sidebar-item-container"); - if ($item_container.length === 0) return; - - const $nested_container = $item_container.parent(".nested-container"); - if ($nested_container.length === 0) return; - - // Find the parent Section Break container - const $section_break_container = $nested_container.closest(".section-item"); - if ($section_break_container.length === 0) return; - - // Find the Section Break item instance that contains this nested item - const section_label = $section_break_container.attr("item-name"); - if (!section_label) return; - - // Find the SectionBreakSidebarItem instance - for (let item of this.items) { - if ( - item.item && - item.item.type === "Section Break" && - item.item.label === section_label - ) { - // Expand the section break if it's collapsed - if (item.collapsed) { - item.open(); + if (active_section) { + let section = this.get_item(active_section); + if (section) { + if (section.collapsed) { + section.open(); } - break; + } + } + } + + get_item(name) { + for (let item of this.items) { + if (item.item.label === name) { + return item; } } }