TypeScript
fix(web): make sidebar project actions reachable by keyboard and screen reader (#5521)
Andrew Johnson7f8cf30ca479
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 2e962810d62..77b7b0abf0a 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -2223,10 +2223,18 @@ export default function Sidebar() {},[isMobile, router, setOpenMobile],);+ // Safari can send a click after Ctrl+click opens settings. Ignore that one+ // selection, then clear the guard when the picker opens again.+ const suppressNextScopeChangeRef = useRef(false);+ const highlightedProjectScopeKeyRef = useRef<string | null>(null);const handleProjectSettings = useCallback(- (event: ReactMouseEvent<HTMLButtonElement>, projectGroup: SidebarProjectSnapshot) => {+ (+ event: ReactMouseEvent<HTMLElement> | ReactKeyboardEvent<HTMLInputElement>,+ projectGroup: SidebarProjectSnapshot,+ ) => {event.preventDefault();event.stopPropagation();+ suppressNextScopeChangeRef.current = true;dispatchProjectScopeMenu({ type: "project-settings-opened" });openProjectSettings(projectGroup);},@@ -3724,10 +3732,18 @@ export default function Sidebar() {isItemEqualToValue={(a, b) => a.value === b.value}open={projectScopeMenuState.open}onOpenChange={(open) => {+ if (open) suppressNextScopeChangeRef.current = false;dispatchProjectScopeMenu({ type: "open-changed", open });}}+ onItemHighlighted={(item) => {+ highlightedProjectScopeKeyRef.current = item?.value ?? null;+ }}value={selectedProjectScopeItem}onValueChange={(item) => {+ if (suppressNextScopeChangeRef.current) {+ suppressNextScopeChangeRef.current = false;+ return;+ }if (!item) return;setProjectScopeKey(item.value === "all" ? null : item.value);}}@@ -3778,6 +3794,24 @@ export default function Sidebar() {size="sm"unstyledvalue={projectScopeMenuState.query}+ onKeyDown={(event) => {+ if (+ event.defaultPrevented ||+ event.nativeEvent.isComposing ||+ event.ctrlKey ||+ event.altKey ||+ event.metaKey ||+ (event.key !== "ContextMenu" &&+ !(event.shiftKey && event.key === "F10"))+ ) {+ return;+ }+ // Combobox items use virtual focus: keyboard events+ // stay on this input, not on the highlighted option.+ const scopeKey = highlightedProjectScopeKeyRef.current;+ const project = scopeKey ? projectGroupByScopeKey.get(scopeKey) : null;+ if (project) handleProjectSettings(event, project);+ }}onChange={(event) =>dispatchProjectScopeMenu({type: "query-changed",@@ -3798,6 +3832,9 @@ export default function Sidebar() {value={item}className="h-8 min-h-8 py-0 font-medium"contentClassName="flex min-w-0 items-center gap-2"+ onContextMenu={(event) => {+ if (project) handleProjectSettings(event, project);+ }}>{project ? (<ProjectFavicon@@ -3816,7 +3853,8 @@ export default function Sidebar() {<Buttonsize="icon-xs"variant="ghost-muted"- aria-label={`Project settings for ${project.displayName}`}+ tabIndex={-1}+ aria-hidden="true"title={`Project settings for ${project.displayName}`}className="ml-auto size-6 [--control-icon-color:currentColor] text-icon-muted focus-visible:bg-accent focus-visible:text-foreground"onPointerDown={(event) => event.stopPropagation()}