Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: keep backend tray popover open on icon left-click (#538)

Hiep Le397b7c06e331
diff --git a/__tests__/components/features/sidebar/sidebar.test.tsx b/__tests__/components/features/sidebar/sidebar.test.tsx
index a7cae7901e..e3cd2f00f5 100644
--- a/__tests__/components/features/sidebar/sidebar.test.tsx
+++ b/__tests__/components/features/sidebar/sidebar.test.tsx
@@ -383,6 +383,38 @@ describe("Sidebar", () => {
).toBeInTheDocument();
});
+ it("does not bubble mouse events to window when the collapsed backend icon is clicked, so the downshift-driven popover is not torn down mid-hover", () => {
+ // Bug: while the popover was open, left-clicking the tray icon closed
+ // the dropdown menu because downshift attaches its outside-click logic
+ // to window-level mousedown/mouseup. The tray icon is a sibling of the
+ // Dropdown (not one of its tracked elements), so the event reached
+ // downshift and was treated as "outside". The fix stops propagation on
+ // the button so neither event reaches the window listeners that close
+ // the menu.
+ window.localStorage.setItem("openhands-sidebar-collapsed", "true");
+ const windowMouseDown = vi.fn();
+ const windowMouseUp = vi.fn();
+ window.addEventListener("mousedown", windowMouseDown);
+ window.addEventListener("mouseup", windowMouseUp);
+
+ try {
+ renderSidebar("/conversations");
+ const trigger = screen.getByTestId("collapsed-backend-selector-link");
+ const wrapper = trigger.parentElement;
+ if (!wrapper) throw new Error("Popover wrapper not found");
+ fireEvent.mouseEnter(wrapper);
+
+ fireEvent.mouseDown(trigger);
+ fireEvent.mouseUp(trigger);
+
+ expect(windowMouseDown).not.toHaveBeenCalled();
+ expect(windowMouseUp).not.toHaveBeenCalled();
+ } finally {
+ window.removeEventListener("mousedown", windowMouseDown);
+ window.removeEventListener("mouseup", windowMouseUp);
+ }
+ });
+
it("renders icons for every top-level nav item so they remain meaningful in the collapsed rail", () => {
renderSidebar("/conversations");
diff --git a/src/components/features/sidebar/sidebar.tsx b/src/components/features/sidebar/sidebar.tsx
index 2b959f8a21..269dd77d3a 100644
--- a/src/components/features/sidebar/sidebar.tsx
+++ b/src/components/features/sidebar/sidebar.tsx
@@ -363,6 +363,20 @@ export function Sidebar() {
data-testid="collapsed-backend-selector-link"
aria-label={t(I18nKey.BACKEND$MANAGE)}
aria-expanded={collapsedBackendPopoverOpen}
+ // The popover this button anchors mounts a downshift-driven
+ // Dropdown that attaches window-level mousedown/mouseup
+ // listeners; on mouseup with a target outside its own
+ // input/menu/toggle it calls handleBlur and closes the menu.
+ // This button is a sibling of the Dropdown β€” not one of those
+ // tracked elements β€” so without stopping propagation, clicking
+ // the tray icon would close the popover the user is still
+ // hovering. preventDefault on mousedown also keeps focus from
+ // shifting off anything currently focused inside the dropdown.
+ onMouseDown={(event) => {
+ event.preventDefault();
+ event.stopPropagation();
+ }}
+ onMouseUp={(event) => event.stopPropagation()}
className={cn(
"relative inline-flex items-center justify-center w-10 h-10 p-0 mx-auto rounded-md transition-colors",
collapsedBackendPopoverOpen
@@ -378,7 +392,7 @@ export function Sidebar() {
</button>
{collapsedBackendPopoverOpen ? (
<div
- className="absolute bottom-0 left-full pl-2 z-40 w-[272px]"
+ className="absolute bottom-[-4px] left-full pl-2 z-40 w-[272px]"
// Stop click propagation so dropdown option clicks
// (rendered as <li role="option">, which the rail's
// collapse handler does not match against `button/a`)