Open-source personal finance manager. Self-hosted, privacy-first.
fix: make category picker scrollable inside dialogs on touch/wheel input (#439)
Ítalo Assunção2b12f3678391
diff --git a/frontend/src/components/ui/command.tsx b/frontend/src/components/ui/command.tsxindex 717e5f0f..bbb3096c 100644--- a/frontend/src/components/ui/command.tsx+++ b/frontend/src/components/ui/command.tsx@@ -4,6 +4,55 @@ import { SearchIcon } from "lucide-react"import { cn } from "@/lib/utils"+// When this list is nested inside a modal Dialog (e.g. category picker+// inside the transaction dialog), Radix's body scroll lock (react-remove-scroll)+// registers a bubble-phase `wheel`/`touchmove` listener on `document` that+// preventDefault()s events whose target isn't inside the dialog's own DOM+// subtree — which is exactly this list's situation, since its Popover portals+// to document.body. That listener only fires once the event has bubbled all+// the way up, so React's own (passive, non-preventable) onWheel/onTouchMove+// props can't detect or work around it in time. The only reliable fix is to+// attach our own non-passive native listener directly on the list and drive+// scrollTop ourselves, unconditionally — this works the same whether or not+// a Dialog's scroll lock is active.+function useManualScroll<T extends HTMLElement>() {+ const ref = React.useRef<T>(null)++ React.useEffect(() => {+ const el = ref.current+ if (!el) return++ const onWheel = (e: WheelEvent) => {+ e.preventDefault()+ const multiplier = e.deltaMode === 1 ? 20 : e.deltaMode === 2 ? el.clientHeight : 1+ el.scrollTop += e.deltaY * multiplier+ }++ let touchStart: { y: number; scrollTop: number } | null = null+ const onTouchStart = (e: TouchEvent) => {+ const touch = e.touches[0]+ touchStart = { y: touch.clientY, scrollTop: el.scrollTop }+ }+ const onTouchMove = (e: TouchEvent) => {+ if (!touchStart) return+ e.preventDefault()+ const touch = e.touches[0]+ el.scrollTop = touchStart.scrollTop + (touchStart.y - touch.clientY)+ }++ el.addEventListener("wheel", onWheel, { passive: false })+ el.addEventListener("touchstart", onTouchStart, { passive: true })+ el.addEventListener("touchmove", onTouchMove, { passive: false })+ return () => {+ el.removeEventListener("wheel", onWheel)+ el.removeEventListener("touchstart", onTouchStart)+ el.removeEventListener("touchmove", onTouchMove)+ }+ }, [])++ return ref+}+function Command({className,...props@@ -43,10 +92,12 @@ function CommandList({className,...props}: React.ComponentProps<typeof CommandPrimitive.List>) {+ const ref = useManualScroll<HTMLDivElement>()return (<CommandPrimitive.List+ ref={ref}data-slot="command-list"- className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}+ className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden overscroll-contain", className)}{...props}/>)