commit 551971937e49864c9ad0d2999e3e89560b804fde
parent 567626f5db0de0fba86122d94f77670489275c4b
Author: Jeremy Swinarton <jswinarton@mozilla.com>
Date: Tue, 2 Dec 2025 18:00:17 +0000
Bug 1997096: Automatically expand tab groups when adding new tabs to them r=sthompson,tabbrowser-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D272932
Diffstat:
3 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
@@ -4430,6 +4430,13 @@
tabContainer.insertBefore(tab, itemAfter);
}
+ if (tab.group?.collapsed) {
+ // Bug 1997096: automatically expand the group if we are adding a new
+ // tab to a collapsed group, and that tab does not have automatic focus
+ // (i.e. if the user right clicks and clicks "Open in New Tab")
+ tab.group.collapsed = false;
+ }
+
this._updateTabsAfterInsert();
if (pinned) {
diff --git a/browser/components/tabbrowser/test/browser/tabs/browser_tab_groups.js b/browser/components/tabbrowser/test/browser/tabs/browser_tab_groups.js
@@ -1297,3 +1297,35 @@ add_task(async function test_bug1969925_adoptLastTabGroupFromWindow() {
await removeTabGroup(groupAfterAdopt);
});
+
+/*
+ * Tests that if a new tab is opened via right click from the active tab in a collapsed group,
+ * the group auto-uncollapses so you can see the tab that was just opened.
+ */
+add_task(async function test_bug1997096_autoUncollapseOnRightClick() {
+ let groupedTab = await addTabTo(gBrowser);
+ let group = gBrowser.addTabGroup([groupedTab]);
+ gBrowser.selectedTab = groupedTab;
+ group.collapsed = true;
+
+ let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
+
+ await BrowserTestUtils.synthesizeMouseAtCenter(
+ "a",
+ { type: "contextmenu", button: 2 },
+ groupedTab.linkedBrowser
+ );
+ document.getElementById("context-openlinkintab").click();
+
+ let newTab = await newTabPromise;
+
+ Assert.ok(newTab, "New tab opened via right click");
+ Assert.ok(
+ !group.collapsed,
+ "Group is automatically uncollapsed when opening tab via right click"
+ );
+
+ document.querySelector("#contentAreaContextMenu").hidePopup();
+ BrowserTestUtils.removeTab(newTab);
+ BrowserTestUtils.removeTab(groupedTab);
+});
diff --git a/browser/components/tabbrowser/test/browser/tabs/browser_tab_preview.js b/browser/components/tabbrowser/test/browser/tabs/browser_tab_preview.js
@@ -820,11 +820,17 @@ add_task(async function tabGroupPanelUpdatesTests() {
"Panel toolbarbutton has updated label"
);
+ await closeGroupPreviews();
+
info("Test that adding a tab to the group adds the tab to the group's panel");
let TabOpenEvent = BrowserTestUtils.waitForEvent(group, "TabOpen");
let newTab = await addTabTo(gBrowser, "about:robots", { tabGroup: group });
await TabOpenEvent;
+ // Re-collapse the group, which was uncollapsed when the new tab was added
+ group.collapsed = true;
+ await openGroupPreview(group);
+
Assert.equal(
panelContent.children.length,
2,