GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(ui): switch submenus without blinking and keep them open on the w… · dshaw/opencode@f352f5e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bun.lock
  • package.json
  • packages
    • app
      • e2e/regression
        • tabs.spec.ts
      • src/shell/titlebar
        • sidebar-view-menu.tsx
    • ui/src/navigation/menu
      • menu.css
      • menu.tsx
      • submenu-machine.test.ts
      • submenu-machine.ts
  • patches
    • @kobalte%[email protected]
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
"[email protected]": "patches/[email protected]",
175175
"@pierre/[email protected]": "patches/@pierre%[email protected]",
176176
"@brendonovich/[email protected]": "patches/@brendonovich%[email protected]",
177-
"@modelcontextprotocol/[email protected]": "patches/@modelcontextprotocol%[email protected]"
177+
"@modelcontextprotocol/[email protected]": "patches/@modelcontextprotocol%[email protected]",
178+
"@kobalte/[email protected]": "patches/@kobalte%[email protected]"
178179
}
179180
}
Collapse file

‎packages/app/e2e/regression/tabs.spec.ts‎

Copy file name to clipboardExpand all lines: packages/app/e2e/regression/tabs.spec.ts
+82Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,88 @@ test("the Windows titlebar menu pastes through the desktop edit action", async (
18621862
await expect(page.getByRole("status", { name: "Desktop menu actions" })).toHaveText("edit.paste")
18631863
})
18641864

1865+
// #63095: hovering down the parent items left every submenu open, stacked on top of each other. Closing each one as
1866+
// soon as the pointer left it then showed no submenu until the next opened, so the menu blinked on every item.
1867+
test("the Windows titlebar menu swaps one submenu for the next as the pointer moves down its parent items", async ({
1868+
page,
1869+
}) => {
1870+
await page.clock.install()
1871+
await mockWorkspace(page, { name: "WindowsMenu", sessions: [] })
1872+
await page.goto(`/e2e/utils/windows-menu.html?${new URLSearchParams({ server: SERVER })}`)
1873+
await page.getByRole("button", { name: "OpenCode menu", exact: true }).click()
1874+
const parents = ["File", "Edit", "View"].map((name) => page.getByRole("menuitem", { name, exact: true }))
1875+
const submenus = page.locator('[role="menu"].desktop-app-menu-sub')
1876+
1877+
for (const [index, parent] of parents.entries()) {
1878+
const box = (await parent.boundingBox())!
1879+
// Down and to the left, away from the open submenu, so the pointer isn't heading for it.
1880+
await page.mouse.move(box.x + box.width / 2 - index * 20, box.y + box.height / 2, { steps: 4 })
1881+
await expect(parent).toHaveAttribute("data-highlighted", "")
1882+
1883+
if (index > 0) await expect(parents[index - 1]).toHaveAttribute("aria-expanded", "true")
1884+
await expect(parent).toHaveAttribute("aria-expanded", "false")
1885+
// Kobalte's hover delay.
1886+
await page.clock.runFor(100)
1887+
await expect(parent).toHaveAttribute("aria-expanded", "true")
1888+
await expect(submenus).toHaveCount(1)
1889+
}
1890+
})
1891+
1892+
// #59613: crossing the other parent items on the way to a submenu's lower items closed it and opened theirs.
1893+
test("the Windows titlebar menu keeps a submenu open while the pointer crosses other parent items to reach it", async ({
1894+
page,
1895+
}) => {
1896+
await page.clock.install()
1897+
await mockWorkspace(page, { name: "WindowsMenu", sessions: [] })
1898+
await page.goto(`/e2e/utils/windows-menu.html?${new URLSearchParams({ server: SERVER })}`)
1899+
await page.getByRole("button", { name: "OpenCode menu", exact: true }).click()
1900+
const file = page.getByRole("menuitem", { name: "File", exact: true })
1901+
const fileBox = (await file.boundingBox())!
1902+
const from = { x: fileBox.x + fileBox.width / 2, y: fileBox.y + fileBox.height / 2 }
1903+
await page.mouse.move(from.x, from.y, { steps: 4 })
1904+
await page.clock.runFor(100)
1905+
const closeWindow = page.getByRole("menuitem", { name: /^Close Window/ })
1906+
const target = (await closeWindow.boundingBox())!
1907+
const to = { x: target.x + 20, y: target.y + target.height / 2 }
1908+
const steps = Math.ceil(Math.hypot(to.x - from.x, to.y - from.y) / 4)
1909+
1910+
// A slow, straight move at 125px a second: it stays longer than the hover delay on each item it crosses, and the
1911+
// whole trip takes longer than the 300ms that Kobalte keeps the way to a submenu open.
1912+
for (let step = 1; step <= steps; step++) {
1913+
await page.mouse.move(from.x + ((to.x - from.x) * step) / steps, from.y + ((to.y - from.y) * step) / steps)
1914+
await page.clock.runFor(32)
1915+
}
1916+
1917+
await expect(closeWindow).toHaveAttribute("data-highlighted", "")
1918+
await expect(file).toHaveAttribute("aria-expanded", "true")
1919+
await expect(page.locator('[role="menu"].desktop-app-menu-sub')).toHaveCount(1)
1920+
})
1921+
1922+
// Moving down the parent items while drifting right kept the way to the open submenu alive, so the highlight stayed on
1923+
// the item that opened it while the pointer crossed the next ones.
1924+
test("the Windows titlebar menu highlights each parent item the pointer drifts down across", async ({ page }) => {
1925+
await page.clock.install()
1926+
await mockWorkspace(page, { name: "WindowsMenu", sessions: [] })
1927+
await page.goto(`/e2e/utils/windows-menu.html?${new URLSearchParams({ server: SERVER })}`)
1928+
await page.getByRole("button", { name: "OpenCode menu", exact: true }).click()
1929+
const view = page.getByRole("menuitem", { name: "View", exact: true })
1930+
const box = (await view.boundingBox())!
1931+
const from = { x: box.x + box.width / 2, y: box.y + box.height / 2 }
1932+
await page.mouse.move(from.x, from.y, { steps: 4 })
1933+
await page.clock.runFor(100)
1934+
await expect(view).toHaveAttribute("aria-expanded", "true")
1935+
const go = page.getByRole("menuitem", { name: "Go", exact: true })
1936+
const target = (await go.boundingBox())!
1937+
1938+
// 1px right for every 4px down, a frame at a time, until the pointer is a few pixels inside Go.
1939+
for (let step = 1; from.y + step * 4 < target.y + 8; step++) {
1940+
await page.mouse.move(from.x + step, from.y + step * 4)
1941+
await page.clock.runFor(16)
1942+
}
1943+
1944+
await expect(go).toHaveAttribute("data-highlighted", "")
1945+
})
1946+
18651947
test("the Windows menu shares the vertical sidebar's icon lane", async ({ page }) => {
18661948
await mockWorkspace(page, {
18671949
name: "WindowsMenu",
Collapse file

‎packages/app/src/shell/titlebar/sidebar-view-menu.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/shell/titlebar/sidebar-view-menu.tsx
+5-37Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { For, Show, type JSX } from "solid-js"
2-
import { createStore } from "solid-js/store"
32
import { Icon } from "@opencode/ui/icon"
43
import { IconButton } from "@opencode/ui/icon-button"
54
import { Menu } from "@opencode/ui/menu"
@@ -43,15 +42,8 @@ export function SidebarViewMenu(props: {
4342
const groupings = () =>
4443
SIDEBAR_GROUPINGS.filter((value) => multiServer() || (value !== "server" && value !== "server-project"))
4544

46-
// Kobalte closes a submenu only when focus leaves it, and hovering a sibling trigger keeps focus in the parent
47-
// menu, so without this every submenu hovered stays open on top of the next.
48-
const [menu, setMenu] = createStore<{ sub: string | undefined }>({ sub: undefined })
49-
50-
const toggleSub = (key: string, open: boolean) =>
51-
setMenu("sub", (current) => (open ? key : current === key ? undefined : current))
52-
5345
return (
54-
<Menu gutter={4} modal={false} placement="bottom-start" onOpenChange={(open) => !open && setMenu("sub", undefined)}>
46+
<Menu gutter={4} modal={false} placement="bottom-start">
5547
<Menu.Trigger
5648
as={IconButton}
5749
variant="ghost-muted"
@@ -61,13 +53,7 @@ export function SidebarViewMenu(props: {
6153
/>
6254
<Menu.Portal>
6355
<Menu.Content class="min-w-[200px]">
64-
<Menu.Sub
65-
gutter={4}
66-
overflowPadding={16}
67-
overlap
68-
open={menu.sub === "grouping"}
69-
onOpenChange={(open) => toggleSub("grouping", open)}
70-
>
56+
<Menu.Sub gutter={4} overflowPadding={16} overlap>
7157
<SubTrigger label={language.t("sidebar.view.grouping")}>
7258
{language.t(`sidebar.view.grouping.${props.state.grouping}`)}
7359
</SubTrigger>
@@ -90,13 +76,7 @@ export function SidebarViewMenu(props: {
9076
</Menu.SubContent>
9177
</Menu.Portal>
9278
</Menu.Sub>
93-
<Menu.Sub
94-
gutter={4}
95-
overflowPadding={16}
96-
overlap
97-
open={menu.sub === "ordering"}
98-
onOpenChange={(open) => toggleSub("ordering", open)}
99-
>
79+
<Menu.Sub gutter={4} overflowPadding={16} overlap>
10080
<SubTrigger label={language.t("sidebar.view.ordering")}>
10181
{language.t(`sidebar.view.ordering.${props.state.ordering}`)}
10282
</SubTrigger>
@@ -123,13 +103,7 @@ export function SidebarViewMenu(props: {
123103
</Menu.SubContent>
124104
</Menu.Portal>
125105
</Menu.Sub>
126-
<Menu.Sub
127-
gutter={4}
128-
overflowPadding={16}
129-
overlap
130-
open={menu.sub === "show"}
131-
onOpenChange={(open) => toggleSub("show", open)}
132-
>
106+
<Menu.Sub gutter={4} overflowPadding={16} overlap>
133107
<SubTrigger label={language.t("sidebar.view.show")} />
134108
<Menu.Portal>
135109
<Menu.SubContent class="w-max min-w-[172px]">
@@ -146,13 +120,7 @@ export function SidebarViewMenu(props: {
146120
<Menu.Separator />
147121
<For each={filterKinds()}>
148122
{(kind) => (
149-
<Menu.Sub
150-
gutter={4}
151-
overflowPadding={16}
152-
overlap
153-
open={menu.sub === `filter:${kind}`}
154-
onOpenChange={(open) => toggleSub(`filter:${kind}`, open)}
155-
>
123+
<Menu.Sub gutter={4} overflowPadding={16} overlap>
156124
<SubTrigger label={language.t(`sidebar.view.filter.${kind}`)}>
157125
<Show when={props.state.filters[kind].length > 0}>{props.state.filters[kind].length}</Show>
158126
</SubTrigger>
Collapse file

‎packages/ui/src/navigation/menu/menu.css‎

Copy file name to clipboardExpand all lines: packages/ui/src/navigation/menu/menu.css
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
}
161161
}
162162

163+
/* Like a native menu, an item stays highlighted while the pointer is in the submenu it opened. */
164+
[data-component="menu-v2-content"]:not(:has([data-highlighted])) [data-component="menu-v2-item"][data-expanded] {
165+
background: var(--menu-v2-hover);
166+
}
167+
163168
[data-slot="menu-v2-separator"] {
164169
height: 1px;
165170
width: calc(100% + 4px);
@@ -257,6 +262,10 @@
257262
}
258263
}
259264

265+
&:not(:has([data-highlighted])) [data-component="menu-v2-item"][data-expanded] {
266+
background: var(--surface-raised-base-hover);
267+
}
268+
260269
[data-slot="menu-v2-separator"] {
261270
width: calc(100% + 8px);
262271
height: 1px;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.