Skip to content

Commit af64304

Browse files
Bug 2052330 - Don't let the launcher overflow observer hide tool buttons in horizontal tabs r=sclements
Differential Revision: https://phabricator.services.mozilla.com/D311147
1 parent 9d91db7 commit af64304

3 files changed

Lines changed: 135 additions & 12 deletions

File tree

browser/components/sidebar/sidebar-main.mjs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ export default class SidebarMain extends MozLitElement {
170170
createToolsObservers() {
171171
this._toolsIntersectionObserver = new IntersectionObserver(
172172
entries => {
173+
// In horizontal tabs mode while the launcher is collapsed or hidden, every
174+
// button is considered non-intersecting by the intersection observer which
175+
// can cause visibility issues once the sidebar is shown again. We should
176+
// return early here if horizontal tabs are enabled to prevent this.
177+
if (!window.SidebarController.sidebarVerticalTabsEnabled) {
178+
return;
179+
}
173180
this.shouldShowOverflowButton = entries.some(
174181
entry =>
175182
!entry.isIntersecting &&
@@ -649,26 +656,40 @@ export default class SidebarMain extends MozLitElement {
649656
}
650657

651658
updated() {
659+
const isExpandOnHover =
660+
window.SidebarController.sidebarRevampVisibility === "expand-on-hover";
661+
652662
if (
653-
window.SidebarController.sidebarRevampVisibility !== "expand-on-hover"
663+
!isExpandOnHover &&
664+
window.SidebarController.sidebarVerticalTabsEnabled
654665
) {
655666
for (const buttonEl of this.allButtons) {
656667
if (buttonEl.hasAttribute("view")) {
657668
this._toolsIntersectionObserver.observe(buttonEl);
658669
}
659670
}
660-
661671
this._toolsResizeObserver.observe(this.buttonGroup);
662-
} else {
663-
this.shouldShowOverflowButton = !this.expanded;
664-
for (const buttonEl of this.allButtons) {
665-
if (buttonEl.style.visibility === "hidden") {
666-
buttonEl.style.visibility = "visible";
667-
}
672+
return;
673+
}
674+
675+
// In expand-on-hover or horizontal tabs mode we don't track tool overflow,
676+
// so restore any previously overflown/hidden tool buttons and stop
677+
// observing. In horizontal tabs mode we also clear the overflow panel
678+
// copies that were populated while in vertical tabs.
679+
this.shouldShowOverflowButton = isExpandOnHover ? !this.expanded : false;
680+
const overflowList = isExpandOnHover
681+
? null
682+
: document.getElementById("tools-overflow-list");
683+
for (const buttonEl of this.allButtons) {
684+
if (buttonEl.style.visibility === "hidden") {
685+
buttonEl.style.visibility = "visible";
668686
}
669-
this._toolsIntersectionObserver.disconnect();
670-
this._toolsResizeObserver.disconnect();
687+
overflowList
688+
?.querySelector(`[view='${buttonEl.getAttribute("view")}']`)
689+
?.remove();
671690
}
691+
this._toolsIntersectionObserver.disconnect();
692+
this._toolsResizeObserver.disconnect();
672693
}
673694

674695
getEntrypointValues(action) {

browser/components/sidebar/tests/browser/browser_customize_sidebar.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,41 @@ add_task(async function test_open_tools_from_sidebar_horizontal() {
319319
"Unchecking turns on the panel switcher dropdown (hide-launcher)."
320320
);
321321

322-
info("Re-check to place tools back in the launcher.");
322+
// Let the launcher's overflow IntersectionObserver run while the
323+
// launcher is hidden and ensure we aren't left with a sidebar
324+
// with unexpectedly hidden buttons
325+
const { sidebarMain } = window.SidebarController;
326+
await sidebarMain.updateComplete;
327+
await waitForRepaint();
328+
for (const button of sidebarMain.toolButtons) {
329+
isnot(
330+
button.style.visibility,
331+
"hidden",
332+
`Tool button ${button.getAttribute("view")} isn't hidden while the ` +
333+
`launcher is hidden.`
334+
);
335+
}
336+
323337
input.click();
324338
await panel.updateComplete;
325339
ok(input.checked, "Open tools from sidebar is checked again.");
326340
is(
327341
Services.prefs.getStringPref(SIDEBAR_VISIBILITY_PREF),
328342
"hide-on-close",
329-
"Checking places tools in the launcher (hide-on-close)."
343+
"Checking 'Open tools from sidebar' option places tool buttons back in the launcher."
330344
);
331345

346+
await sidebarMain.updateComplete;
347+
await waitForRepaint();
348+
ok(sidebarMain.toolButtons.length, "Launcher still has tool buttons.");
349+
for (const button of sidebarMain.toolButtons) {
350+
is(
351+
window.getComputedStyle(button).visibility,
352+
"visible",
353+
`Tool button ${button.getAttribute("view")} is visible in the launcher.`
354+
);
355+
}
356+
332357
Services.prefs.clearUserPref(SIDEBAR_VISIBILITY_PREF);
333358
await SpecialPowers.popPrefEnv();
334359
});

browser/components/sidebar/tests/browser/browser_tools_overflow.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,83 @@ add_task(async function test_overflow_menu_with_keyboard() {
294294
}
295295
});
296296

297+
add_task(
298+
async function test_overflowing_buttons_restored_switching_to_horizontal() {
299+
await SidebarController.updateUIState({
300+
launcherExpanded: false,
301+
});
302+
303+
await SpecialPowers.pushPrefEnv({
304+
set: [
305+
["sidebar.main.tools", "aichat,passwords,syncedtabs,history,bookmarks"],
306+
],
307+
});
308+
309+
const sidebar = SidebarController.sidebarMain;
310+
await resetToolsHeight();
311+
312+
info("Resize the tools container to force overflow.");
313+
await resizeTools(600);
314+
await sidebar.updateComplete;
315+
await SidebarController.waitUntilStable();
316+
await BrowserTestUtils.waitForMutationCondition(
317+
sidebar.buttonsWrapper,
318+
{ attributes: true, attributeFilter: ["overflowing"] },
319+
() => sidebar.shouldShowOverflowButton
320+
);
321+
322+
await BrowserTestUtils.waitForMutationCondition(
323+
sidebar.buttonsWrapper,
324+
{ attributes: true, attributeFilter: ["style"], subtree: true },
325+
() =>
326+
Array.from(sidebar.toolButtons).some(
327+
button => button.style.visibility === "hidden"
328+
),
329+
"At least one tool button is hidden while overflowing in vertical tabs."
330+
);
331+
332+
info("Switch to horizontal tabs.");
333+
await SpecialPowers.pushPrefEnv({ set: [[VERTICAL_TABS_PREF, false]] });
334+
await sidebar.updateComplete;
335+
await SidebarController.waitUntilStable();
336+
337+
await BrowserTestUtils.waitForMutationCondition(
338+
sidebar.buttonsWrapper,
339+
{ attributes: true, attributeFilter: ["style"], subtree: true },
340+
() =>
341+
Array.from(sidebar.toolButtons).every(
342+
button => button.style.visibility !== "hidden"
343+
),
344+
"No tool buttons remain hidden after switching to horizontal tabs."
345+
);
346+
for (const button of sidebar.toolButtons) {
347+
is(
348+
window.getComputedStyle(button).visibility,
349+
"visible",
350+
`Tool button ${button.getAttribute("view")} is visible in horizontal tabs.`
351+
);
352+
}
353+
ok(
354+
!sidebar.shouldShowOverflowButton,
355+
"Overflow button is not shown in horizontal tabs."
356+
);
357+
is(
358+
document.getElementById("tools-overflow-list").childElementCount,
359+
0,
360+
"Overflow panel copies were cleared."
361+
);
362+
363+
info("Switch back to vertical tabs.");
364+
await SpecialPowers.popPrefEnv();
365+
await sidebar.updateComplete;
366+
await resetToolsHeight();
367+
368+
while (gBrowser.tabs.length > 1) {
369+
BrowserTestUtils.removeTab(gBrowser.tabs.at(-1));
370+
}
371+
}
372+
);
373+
297374
add_task(async function test_tools_overflow() {
298375
const sidebar = document.querySelector("sidebar-main");
299376
ok(sidebar, "Sidebar is shown.");

0 commit comments

Comments
 (0)