diff --git a/packages/app/src/components/hosts/host-picker.browser.test.tsx b/packages/app/src/components/hosts/host-picker.browser.test.tsx new file mode 100644 index 0000000000..c1e8aa47f7 --- /dev/null +++ b/packages/app/src/components/hosts/host-picker.browser.test.tsx @@ -0,0 +1,42 @@ +import React, { act } from "react"; +import { createRoot } from "react-dom/client"; +import { expect, it } from "vitest"; +import { HostPickerOption } from "./host-picker"; + +const actions: string[] = []; +function select() { + actions.push("select"); +} +function openSettings() { + actions.push("settings"); +} + +it("keeps host selection and settings as separate accessible buttons", () => { + const container = document.createElement("div"); + document.body.appendChild(container); + const root = createRoot(container); + actions.length = 0; + act(() => + root.render( + , + ), + ); + const host = container.querySelector('button[aria-label="Host A"]'); + const settings = container.querySelector('button[aria-label="Open Host A settings"]'); + expect(host).not.toBeNull(); + expect(settings).not.toBeNull(); + expect(host?.contains(settings!)).toBe(false); + act(() => (settings as HTMLElement).click()); + expect(actions).toEqual(["settings"]); + act(() => (host as HTMLElement).click()); + expect(actions).toEqual(["settings", "select"]); + act(() => root.unmount()); + container.remove(); +}); diff --git a/packages/app/src/components/hosts/host-picker.tsx b/packages/app/src/components/hosts/host-picker.tsx index ced0be3d55..e8bae7bcb2 100644 --- a/packages/app/src/components/hosts/host-picker.tsx +++ b/packages/app/src/components/hosts/host-picker.tsx @@ -8,6 +8,7 @@ import { Combobox, ComboboxItem, type ComboboxProps } from "@/components/ui/comb import { useLocalDaemonServerId } from "@/hooks/use-is-local-daemon"; import { useHostRuntimeSnapshot, type ActiveConnection } from "@/runtime/host-runtime"; import { orderHostsLocalFirst } from "@/types/host-connection"; +import { isWeb } from "@/constants/platform"; import { ADD_HOST_OPTION_ID, ALL_HOSTS_OPTION_ID, @@ -89,35 +90,33 @@ export function HostPickerOption({ ); const trailingSlot = useMemo(() => { if (!onOpenHostSettings) return undefined; - return ( - - - - ); - }, [ - handleSettingsPress, - label, - onOpenHostSettings, - theme.colors.foregroundMuted, - theme.iconSize.sm, - ]); + return ; + }, [onOpenHostSettings]); return ( - + + + {onOpenHostSettings ? ( + + + + ) : null} + ); } @@ -319,6 +318,15 @@ export function HostPicker({ } const styles = StyleSheet.create((theme) => ({ + optionContainer: { position: "relative" }, + settingsSlot: { width: theme.iconSize.sm, height: theme.iconSize.sm }, + settingsAction: { + position: "absolute", + right: theme.spacing[3] + (isWeb ? 0 : theme.spacing[1]), + top: 0, + bottom: 0, + justifyContent: "center", + }, statusDotSlot: { width: theme.iconSize.sm, height: theme.iconSize.sm,