From a2c64a078f39fcb9914cc4ef51f7c379ab2aa012 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Fri, 16 Oct 2026 19:48:21 -0600 Subject: [PATCH 1/6] fix: make logo asset menus accessible by keyboard --- package.json | 1 + pnpm-lock.yaml | 3 + src/components/BrandContextMenu.tsx | 129 ++++++++++++++++++---------- src/components/Navbar.tsx | 1 + src/routes/login.tsx | 2 +- src/routes/oauth/authorize.tsx | 2 +- 6 files changed, 91 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 2c157137b..6a0bcd114 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@phosphor-icons/react": "^2.1.10", "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dropdown-menu": "^2.1.16", + "@radix-ui/react-menu": "2.1.16", "@radix-ui/react-tooltip": "^1.2.8", "@react-three/drei": "^10.7.7", "@react-three/fiber": "^9.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be1b01d31..05a6011b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -100,6 +100,9 @@ importers: '@radix-ui/react-dropdown-menu': specifier: ^2.1.16 version: 2.1.16(@types/react-dom@19.2.3(@types/react@19.2.14))(@types/react@19.2.14)(react-dom@19.2.3(react@19.2.3))(react@19.2.3) + '@radix-ui/react-menu': + specifier: 2.1.16 + version: 2.1.16(@types/react-dom@19.2.3(@types/react@19.2.14))(@types/react@19.2.14)(react-dom@19.2.3(react@19.2.3))(react@19.2.3) '@radix-ui/react-tooltip': specifier: ^1.2.8 version: 1.2.8(@types/react-dom@19.2.3(@types/react@19.2.14))(@types/react@19.2.14)(react-dom@19.2.3(react@19.2.3))(react@19.2.3) diff --git a/src/components/BrandContextMenu.tsx b/src/components/BrandContextMenu.tsx index 2f7bbbf2c..2a58540ca 100644 --- a/src/components/BrandContextMenu.tsx +++ b/src/components/BrandContextMenu.tsx @@ -2,34 +2,31 @@ import * as React from 'react' import { useToast } from '~/components/ToastProvider' import { useNavigate } from '@tanstack/react-router' import { twMerge } from 'tailwind-merge' -import { - Dropdown, - DropdownTrigger, - DropdownContent, - DropdownItem, - DropdownSeparator, -} from './Dropdown' +import * as Menu from '@radix-ui/react-menu' import { copyTextToClipboard } from '~/utils/browser-effects' interface BrandContextMenuProps extends React.HTMLAttributes { children: React.ReactNode + showTrigger?: boolean } -export function BrandContextMenu({ children, ...rest }: BrandContextMenuProps) { +export function BrandContextMenu({ + children, + showTrigger = false, + ...rest +}: BrandContextMenuProps) { const navigate = useNavigate() const { notify } = useToast() const [open, setOpen] = React.useState(false) - const [coords, setCoords] = React.useState<{ x: number; y: number }>({ - x: 0, - y: 0, - }) - const virtualTriggerRef = React.useRef(null) - - const onContextMenu = (e: React.MouseEvent) => { - e.preventDefault() - setCoords({ x: e.clientX, y: e.clientY }) - setOpen(true) - } + const [point, setPoint] = React.useState({ x: 0, y: 0 }) + const anchorRef = React.useMemo( + () => ({ + current: { + getBoundingClientRect: () => new DOMRect(point.x, point.y, 0, 0), + }, + }), + [point], + ) const copyText = async (text: string) => { try { @@ -58,25 +55,64 @@ export function BrandContextMenu({ children, ...rest }: BrandContextMenuProps) { } return ( -
- {children} - - - + +
{ + rest.onContextMenu?.(event) + if (event.defaultPrevented) return + event.preventDefault() + event.stopPropagation() + setPoint({ x: event.clientX, y: event.clientY }) + setOpen(true) + }} + onKeyDown={(event) => { + rest.onKeyDown?.(event) + if ( + event.defaultPrevented || + !( + event.key === 'ContextMenu' || + (event.shiftKey && event.key === 'F10') + ) + ) + return + event.preventDefault() + event.stopPropagation() + const target = + event.target instanceof HTMLElement + ? event.target + : event.currentTarget + const rect = target.getBoundingClientRect() + setPoint({ x: rect.left, y: rect.bottom }) + setOpen(true) + }} + > + {children} + {showTrigger && ( + + )} +
+ + {[ { @@ -107,9 +143,9 @@ export function BrandContextMenu({ children, ...rest }: BrandContextMenuProps) { darkBg: true, }, ].map(({ label, url, darkBg }) => ( - { try { const res = await fetch(url) @@ -131,14 +167,17 @@ export function BrandContextMenu({ children, ...rest }: BrandContextMenuProps) { > {label}
- + ))} - - navigate({ to: '/ds/logos' })}> + + navigate({ to: '/ds/logos' })} + > All Logo Assets - - - - + + + + ) } diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index e20f2913b..b910df7de 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -654,6 +654,7 @@ export function Navbar({ children }: { children: React.ReactNode }) { />
diff --git a/src/routes/login.tsx b/src/routes/login.tsx index 392df8213..5b8f54bff 100644 --- a/src/routes/login.tsx +++ b/src/routes/login.tsx @@ -57,7 +57,7 @@ function SplashImage() { return (
- + diff --git a/src/routes/oauth/authorize.tsx b/src/routes/oauth/authorize.tsx index 1a4182489..a52781cd0 100644 --- a/src/routes/oauth/authorize.tsx +++ b/src/routes/oauth/authorize.tsx @@ -170,7 +170,7 @@ function SplashImage() { return (
- + From b8dc9310afda210248ad02174517a245ad2d614b Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 30 Nov 2026 10:32:29 -0700 Subject: [PATCH 2/6] Fix initial keyboard focus in logo menu --- src/components/BrandContextMenu.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/BrandContextMenu.tsx b/src/components/BrandContextMenu.tsx index 670eabb3e..b35dff64c 100644 --- a/src/components/BrandContextMenu.tsx +++ b/src/components/BrandContextMenu.tsx @@ -91,19 +91,16 @@ export function BrandContextMenu({ > {children} {showTrigger && ( - + )}
From c3b257010e09032f089dffe9cbb09ef7d352c9b4 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 30 Nov 2026 10:46:48 -0700 Subject: [PATCH 3/6] Position logo menu for arrow-key openings --- src/components/BrandContextMenu.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/BrandContextMenu.tsx b/src/components/BrandContextMenu.tsx index b35dff64c..f7b5599a4 100644 --- a/src/components/BrandContextMenu.tsx +++ b/src/components/BrandContextMenu.tsx @@ -94,6 +94,12 @@ export function BrandContextMenu({ { + if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { + const rect = event.currentTarget.getBoundingClientRect() + setPoint({ x: rect.left, y: rect.bottom }) + } + }} onClick={(event) => { const rect = event.currentTarget.getBoundingClientRect() setPoint({ x: rect.left, y: rect.bottom }) From 83bffee04f22a2a824b040e1dccb0f80e3fb35e4 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 30 Nov 2026 11:03:25 -0700 Subject: [PATCH 4/6] fix: focus first brand item for context keyboard shortcut --- src/components/BrandContextMenu.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/BrandContextMenu.tsx b/src/components/BrandContextMenu.tsx index f7b5599a4..bf68c9701 100644 --- a/src/components/BrandContextMenu.tsx +++ b/src/components/BrandContextMenu.tsx @@ -18,6 +18,8 @@ export function BrandContextMenu({ const navigate = useNavigate() const { notify } = useToast() const [open, setOpen] = React.useState(false) + const firstItemRef = React.useRef(null) + const focusFirstItemRef = React.useRef(false) const [point, setPoint] = React.useState({ x: 0, y: 0 }) const anchorRef = React.useMemo( () => ({ @@ -65,6 +67,7 @@ export function BrandContextMenu({ if (event.defaultPrevented) return event.preventDefault() event.stopPropagation() + focusFirstItemRef.current = false setPoint({ x: event.clientX, y: event.clientY }) setOpen(true) }} @@ -84,6 +87,7 @@ export function BrandContextMenu({ event.target instanceof HTMLElement ? event.target : event.currentTarget + focusFirstItemRef.current = true const rect = target.getBoundingClientRect() setPoint({ x: rect.left, y: rect.bottom }) setOpen(true) @@ -117,7 +121,18 @@ export function BrandContextMenu({ align="start" className="z-[1200]" > - + { + if ( + event.target === event.currentTarget && + focusFirstItemRef.current + ) { + focusFirstItemRef.current = false + firstItemRef.current?.focus() + } + }} + className="dropdown-content z-[1200] min-w-48 rounded-lg border border-gray-200 bg-white p-1.5 shadow-lg dark:border-gray-700 dark:bg-gray-900/50 backdrop-blur-md" + > {[ { label: 'Logo — Landscape (Black)', @@ -146,9 +161,10 @@ export function BrandContextMenu({ url: '/images/brand/tanstack-emblem-white.svg', darkBg: true, }, - ].map(({ label, url, darkBg }) => ( + ].map(({ label, url, darkBg }, index) => ( { try { From 73c62c7594fa596fa6d083f3e6063bf909e94331 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 30 Nov 2026 20:02:47 -0700 Subject: [PATCH 5/6] fix: restore logo menu focus by open path --- src/components/BrandContextMenu.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/components/BrandContextMenu.tsx b/src/components/BrandContextMenu.tsx index bf68c9701..ed0f25b65 100644 --- a/src/components/BrandContextMenu.tsx +++ b/src/components/BrandContextMenu.tsx @@ -20,6 +20,10 @@ export function BrandContextMenu({ const [open, setOpen] = React.useState(false) const firstItemRef = React.useRef(null) const focusFirstItemRef = React.useRef(false) + const triggerRef = React.useRef(null) + const [finalFocus, setFinalFocus] = React.useState< + boolean | React.RefObject + >(true) const [point, setPoint] = React.useState({ x: 0, y: 0 }) const anchorRef = React.useMemo( () => ({ @@ -68,6 +72,15 @@ export function BrandContextMenu({ event.preventDefault() event.stopPropagation() focusFirstItemRef.current = false + const active = document.activeElement + setFinalFocus( + active === triggerRef.current + ? triggerRef + : active instanceof HTMLElement && + event.currentTarget.contains(active) + ? { current: active } + : false, + ) setPoint({ x: event.clientX, y: event.clientY }) setOpen(true) }} @@ -88,6 +101,9 @@ export function BrandContextMenu({ ? event.target : event.currentTarget focusFirstItemRef.current = true + setFinalFocus( + target === triggerRef.current ? triggerRef : { current: target }, + ) const rect = target.getBoundingClientRect() setPoint({ x: rect.left, y: rect.bottom }) setOpen(true) @@ -96,15 +112,18 @@ export function BrandContextMenu({ {children} {showTrigger && ( { if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { + setFinalFocus(triggerRef) const rect = event.currentTarget.getBoundingClientRect() setPoint({ x: rect.left, y: rect.bottom }) } }} onClick={(event) => { + setFinalFocus(triggerRef) const rect = event.currentTarget.getBoundingClientRect() setPoint({ x: rect.left, y: rect.bottom }) }} @@ -122,6 +141,7 @@ export function BrandContextMenu({ className="z-[1200]" > { if ( event.target === event.currentTarget && From ab67e9cee54227f60a41d48a2a5e7a220a2b2603 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 30 Nov 2026 20:19:34 -0700 Subject: [PATCH 6/6] docs: explain logo menu focus ref --- src/components/BrandContextMenu.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/BrandContextMenu.tsx b/src/components/BrandContextMenu.tsx index ed0f25b65..da46e6ba7 100644 --- a/src/components/BrandContextMenu.tsx +++ b/src/components/BrandContextMenu.tsx @@ -141,6 +141,8 @@ export function BrandContextMenu({ className="z-[1200]" > { if (