diff --git a/browser/base/content/main-popupset.inc.xhtml b/browser/base/content/main-popupset.inc.xhtml index 2469515f68c3..68728ad5e067 100644 --- a/browser/base/content/main-popupset.inc.xhtml +++ b/browser/base/content/main-popupset.inc.xhtml @@ -100,6 +100,8 @@ + + diff --git a/browser/base/content/main-popupset.js b/browser/base/content/main-popupset.js index 2d23bc97b6bd..90d86a032adc 100644 --- a/browser/base/content/main-popupset.js +++ b/browser/base/content/main-popupset.js @@ -104,6 +104,9 @@ document.addEventListener( case "context_fullscreenExit": BrowserCommands.fullScreen(); break; + case "context_toggleVerticalTabs": + SidebarController.toggleVerticalTabs(); + break; // == open-tab-group-context-menu == case "open-tab-group-context-menu_moveToNewWindow": diff --git a/browser/components/sidebar/browser-sidebar.js b/browser/components/sidebar/browser-sidebar.js index 8f31c15f47ca..fc01a0453de2 100644 --- a/browser/components/sidebar/browser-sidebar.js +++ b/browser/components/sidebar/browser-sidebar.js @@ -521,6 +521,16 @@ var SidebarController = { this.uiStateInitialized = true; }, + /** + * Toggle the vertical tabs preference. + */ + toggleVerticalTabs() { + Services.prefs.setBoolPref( + "sidebar.verticalTabs", + !this.sidebarVerticalTabsEnabled + ); + }, + /** * The handler for Services.obs.addObserver. */ diff --git a/browser/components/sidebar/tests/browser/browser_sidebar_context_menu.js b/browser/components/sidebar/tests/browser/browser_sidebar_context_menu.js index 79cd58188ed0..b03e9d248b0a 100644 --- a/browser/components/sidebar/tests/browser/browser_sidebar_context_menu.js +++ b/browser/components/sidebar/tests/browser/browser_sidebar_context_menu.js @@ -149,3 +149,41 @@ add_task(async function test_sidebar_extension_context_menu() { await extension.unload(); await BrowserTestUtils.closeWindow(win); }); + +add_task(async function test_toggle_vertical_tabs_from_tab_strip() { + await SpecialPowers.pushPrefEnv({ + set: [["sidebar.verticalTabs", false]], + }); + + info("Enable vertical tabs from the tab strip."); + const tabContextMenu = document.getElementById("tabContextMenu"); + const toggleMenuItem = document.getElementById("context_toggleVerticalTabs"); + await openAndWaitForContextMenu(tabContextMenu, gBrowser.selectedTab, () => { + Assert.deepEqual( + document.l10n.getAttributes(toggleMenuItem), + { id: "tab-context-enable-vertical-tabs", args: null }, + "Context menu item indicates that it enables vertical tabs." + ); + toggleMenuItem.click(); + }); + await TestUtils.waitForCondition( + () => gBrowser.tabContainer.verticalMode, + "Vertical tabs are enabled." + ); + + info("Disable vertical tabs from the tab strip."); + await openAndWaitForContextMenu(tabContextMenu, gBrowser.selectedTab, () => { + Assert.deepEqual( + document.l10n.getAttributes(toggleMenuItem), + { id: "tab-context-disable-vertical-tabs", args: null }, + "Context menu item indicates that it disables vertical tabs." + ); + toggleMenuItem.click(); + }); + await TestUtils.waitForCondition( + () => !gBrowser.tabContainer.verticalMode, + "Vertical tabs are disabled." + ); + + await SpecialPowers.popPrefEnv(); +}); diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js index 723eb195bf97..2ed7000c2c1e 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -8470,6 +8470,17 @@ var TabContextMenu = { : "close-tabs-to-the-end" ); + // Update context menu item for "Turn (on/off) Vertical Tabs". + const toggleVerticalTabsItem = document.getElementById( + "context_toggleVerticalTabs" + ); + document.l10n.setAttributes( + toggleVerticalTabsItem, + gBrowser.tabContainer?.verticalMode + ? "tab-context-disable-vertical-tabs" + : "tab-context-enable-vertical-tabs" + ); + // Disable "Close Tabs to the Left/Right" if there are no tabs // preceding/following it. let noTabsToStart = !gBrowser._getTabsToTheStartFrom(this.contextTab) diff --git a/browser/locales/en-US/browser/tabContextMenu.ftl b/browser/locales/en-US/browser/tabContextMenu.ftl index 7e71644d70a9..19df6bd4f86f 100644 --- a/browser/locales/en-US/browser/tabContextMenu.ftl +++ b/browser/locales/en-US/browser/tabContextMenu.ftl @@ -91,6 +91,10 @@ tab-context-close-duplicate-tabs = tab-context-share-url = .label = Share .accesskey = h +tab-context-enable-vertical-tabs = + .label = Turn on Vertical Tabs +tab-context-disable-vertical-tabs = + .label = Turn off Vertical Tabs ## Variables: ## $tabCount (Number): the number of tabs that are affected by the action.