From cd66d8fd1832b8c8609ef4031b19e50a39391b8d Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 23 Nov 2026 11:40:02 +0700 Subject: [PATCH] Open sidebar host settings with one click (#10562) * Keep the host settings action out of the host row's pressable The gear sat in the row's trailing slot, which ComboboxItem renders inside its own pressable, so the row was a button containing a button. HTML forbids that: React aborts the press handling, which is why the first click on the host picker produced a hydration error and only the second one opened anything. ComboboxItem gains a trailingAction slot that renders beside the row's pressable instead of inside it. The split row carries the hover and active background, the pressable keeps the row's padding, and the action column sits outside the click target, so the gear reaches host settings on the first click. (cherry picked from commit ccff20dae74e7cb6f10612e39bf3b192c0ad00b7) * fix(sidebar): let Enter activate the focused host gear Combobox Enter handling was taking precedence over the focused trailing button. Leave Enter to that control so keyboard and pointer input open the same host Overview. Cover both paths through the desktop sidebar in Playwright. * fix(sidebar): give the host gear priority over Enter shortcuts Let the browser activate a focused host gear while the combobox keeps Enter out of the app shortcut dispatcher. Make the gear button fill its column so the highlighted edge opens settings too. --------- Co-authored-by: ShalokShalom --- .../e2e/browser/settings-navigation.spec.ts | 25 +++++ packages/app/e2e/support/helpers/settings.ts | 37 +++++++ .../app/src/components/hosts/host-picker.tsx | 23 ++--- packages/app/src/components/ui/combobox.tsx | 98 +++++++++++++++++-- 4 files changed, 162 insertions(+), 21 deletions(-) diff --git a/packages/app/e2e/browser/settings-navigation.spec.ts b/packages/app/e2e/browser/settings-navigation.spec.ts index 054a91318..1e9805bef 100644 --- a/packages/app/e2e/browser/settings-navigation.spec.ts +++ b/packages/app/e2e/browser/settings-navigation.spec.ts @@ -64,6 +64,11 @@ import { expectSettingsHostPickerLabel, openSettingsHostSection, removeCurrentHostFromSettings, + openSidebarHostPicker, + sidebarHostSettingsButton, + expectStandaloneSidebarHostSettingsButton, + activateSidebarHostSettingsWithKeyboard, + bindCommandCenterToEnter, } from "../support/helpers/settings"; import { getServerId } from "../support/helpers/server-id"; import { expectAppRoute } from "../support/helpers/route-assertions"; @@ -187,6 +192,26 @@ test.describe("Settings sidebar scroll position", () => { }); test.describe("Settings sidebar navigation", () => { + test("the sidebar host gear opens Overview in one click", async ({ page, withWorkspace }) => { + const workspace = await withWorkspace({ prefix: "sidebar-host-settings-" }); + await openWorkspace(page, workspace); + await openSidebarHostPicker(page); + await expectStandaloneSidebarHostSettingsButton(page); + await sidebarHostSettingsButton(page).click(); + + await expectAppRoute(page, buildSettingsHostSectionRoute(getServerId(), "host")); + }); + + test("Enter opens the focused sidebar host gear", async ({ page, withWorkspace }) => { + await bindCommandCenterToEnter(page); + const workspace = await withWorkspace({ prefix: "keyboard-host-settings-" }); + await openWorkspace(page, workspace); + await openSidebarHostPicker(page); + await activateSidebarHostSettingsWithKeyboard(page); + + await expectAppRoute(page, buildSettingsHostSectionRoute(getServerId(), "host")); + }); + test("opening Settings closes the composer model selector until it is opened again", async ({ page, withWorkspace, diff --git a/packages/app/e2e/support/helpers/settings.ts b/packages/app/e2e/support/helpers/settings.ts index ee8bab1b4..96e4a5b28 100644 --- a/packages/app/e2e/support/helpers/settings.ts +++ b/packages/app/e2e/support/helpers/settings.ts @@ -12,6 +12,43 @@ const DISABLE_DEFAULT_SEED_ONCE_KEY = "@paseo:e2e-disable-default-seed-once"; const SEED_NONCE_KEY = "@paseo:e2e-seed-nonce"; const REGISTRY_KEY = "@paseo:daemon-registry"; +export async function openSidebarHostPicker(page: Page) { + await page.getByRole("button", { name: "Hosts", exact: true }).click(); +} + +export function sidebarHostSettingsButton(page: Page) { + return page.getByRole("button", { name: `Open ${TEST_HOST_LABEL} settings`, exact: true }); +} + +export async function bindCommandCenterToEnter(page: Page) { + await page.addInitScript(() => { + localStorage.setItem( + "@paseo:keyboard-shortcut-overrides", + JSON.stringify({ + "command-center-toggle-cmd-k-mac": "Enter", + "command-center-toggle-ctrl-k-non-mac": "Enter", + }), + ); + }); +} + +export async function expectStandaloneSidebarHostSettingsButton(page: Page) { + const gear = sidebarHostSettingsButton(page); + await expect(gear).toBeVisible(); + expect(await gear.evaluate((button) => button.parentElement?.closest("button") === null)).toBe( + true, + ); +} + +export async function activateSidebarHostSettingsWithKeyboard(page: Page) { + const host = page.getByRole("button", { name: TEST_HOST_LABEL, exact: true }); + await expect(host).toBeFocused(); + await page.keyboard.press("ArrowDown"); + await page.keyboard.press("Tab"); + await expect(sidebarHostSettingsButton(page)).toBeFocused(); + await page.keyboard.press("Enter"); +} + interface SavedSettingsHostInput { serverId: string; label: string; diff --git a/packages/app/src/components/hosts/host-picker.tsx b/packages/app/src/components/hosts/host-picker.tsx index ced0be3d5..c8a7c0060 100644 --- a/packages/app/src/components/hosts/host-picker.tsx +++ b/packages/app/src/components/hosts/host-picker.tsx @@ -1,6 +1,5 @@ import { useCallback, useMemo, type ReactElement, type ReactNode } from "react"; import { Pressable, View } from "react-native"; -import type { GestureResponderEvent } from "react-native"; import { Plus, Server, Settings } from "lucide-react-native"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { HostStatusDot } from "@/components/host-status-dot"; @@ -80,19 +79,15 @@ export function HostPickerOption({ ? formatActiveConnectionLabel(activeConnection) : undefined; const leadingSlot = useMemo(() => , [serverId]); - const handleSettingsPress = useCallback( - (event: GestureResponderEvent) => { - event.stopPropagation(); - onOpenHostSettings?.(serverId); - }, - [onOpenHostSettings, serverId], - ); - const trailingSlot = useMemo(() => { + const handleSettingsPress = useCallback(() => { + onOpenHostSettings?.(serverId); + }, [onOpenHostSettings, serverId]); + const trailingAction = useMemo(() => { if (!onOpenHostSettings) return undefined; return ( @@ -112,7 +107,7 @@ export function HostPickerOption({ label={label} description={connectionLabel} leadingSlot={leadingSlot} - trailingSlot={trailingSlot} + trailingAction={trailingAction} selected={selected} active={active} onPress={onPress} @@ -319,6 +314,12 @@ export function HostPicker({ } const styles = StyleSheet.create((theme) => ({ + settingsAction: { + flex: 1, + justifyContent: "center", + paddingLeft: theme.spacing[1], + paddingRight: theme.spacing[3], + }, statusDotSlot: { width: theme.iconSize.sm, height: theme.iconSize.sm, diff --git a/packages/app/src/components/ui/combobox.tsx b/packages/app/src/components/ui/combobox.tsx index ef3e76bc9..c6c60b2c4 100644 --- a/packages/app/src/components/ui/combobox.tsx +++ b/packages/app/src/components/ui/combobox.tsx @@ -72,6 +72,7 @@ import { buildDesktopFrameStyle } from "./combobox-frame-style"; export { buildDesktopFrameStyle } from "./combobox-frame-style"; const IS_WEB = isWeb; +const TRAILING_ACTION_DATASET = { comboboxTrailingAction: true }; export type ComboboxOption = ComboboxOptionModel; export type ComboboxDesktopPlacement = "top-start" | "bottom-start"; @@ -235,6 +236,11 @@ export interface ComboboxItemProps { kind?: "directory" | "file"; leadingSlot?: ReactNode; trailingSlot?: ReactNode; + /** + * A button shown outside the row's own pressable. The button owns its spacing + * and hit area. + */ + trailingAction?: ReactNode; selected?: boolean; active?: boolean; disabled?: boolean; @@ -252,6 +258,7 @@ export function ComboboxItem({ kind, leadingSlot, trailingSlot, + trailingAction, selected, active, disabled, @@ -300,15 +307,29 @@ export function ComboboxItem({ [labelPrefix], ); - return ( - + const [hovered, setHovered] = useState(false); + const handleHoverIn = useCallback(() => setHovered(true), []); + const handleHoverOut = useCallback(() => setHovered(false), []); + const splitPressableStyle = useCallback( + ({ pressed }: PressableStateCallbackType) => [ + styles.comboboxItemSplitPressable, + pressed && (elevated ? styles.comboboxItemPressedElevated : styles.comboboxItemPressed), + ], + [elevated], + ); + const splitRowStyle = useMemo( + () => [ + styles.comboboxItem, + styles.comboboxItemSplitRow, + hovered && (elevated ? styles.comboboxItemHoveredElevated : styles.comboboxItemHovered), + active && styles.comboboxItemActive, + disabled && styles.comboboxItemDisabled, + ], + [active, disabled, elevated, hovered], + ); + + const content = ( + <> {leadingContent} {labelPrefix ? ( @@ -333,7 +354,40 @@ export function ComboboxItem({ {trailingSlot} ) : null} - + + ); + + if (!trailingAction) { + return ( + + {content} + + ); + } + + return ( + + + {content} + + + {trailingAction} + + ); } @@ -898,6 +952,10 @@ function dispatchDesktopKey( return true; } if (key === "Enter") { + // Consume the shortcut but keep the browser's default button activation. + if (isWeb && document.activeElement?.matches("[data-combobox-trailing-action] button")) { + return true; + } if (input.orderedVisibleOptions.length === 0) return false; event?.preventDefault(); handleDesktopEnterKey(input); @@ -1742,6 +1800,26 @@ const styles = StyleSheet.create((theme) => ({ marginBottom: theme.spacing[1], }), }, + // Share the highlight while each control owns its padding and hit area. + comboboxItemSplitRow: { + gap: 0, + paddingHorizontal: 0, + paddingVertical: 0, + }, + comboboxItemSplitPressable: { + flex: 1, + alignSelf: "stretch", + minWidth: 0, + flexDirection: "row", + alignItems: "center", + gap: theme.spacing[2], + paddingLeft: theme.spacing[3], + paddingRight: theme.spacing[1], + paddingVertical: theme.spacing[2], + }, + comboboxItemActionSlot: { + alignSelf: "stretch", + }, comboboxItemHovered: { backgroundColor: theme.colors.surface1, },