An open-source, faster Devin alternative
TypeScript
fix(web): keep overlay dismissal guard through click
Igor Zalutski7c737f54ee6c
diff --git a/web/src/components/ui/floating-layer.ts b/web/src/components/ui/floating-layer.tsindex 3a16d2f1..878e22bb 100644--- a/web/src/components/ui/floating-layer.ts+++ b/web/src/components/ui/floating-layer.ts@@ -1,6 +1,7 @@const FLOATING_LAYER_ATTR = 'data-oc-floating-layer'const FLOATING_LAYER_SELECTOR = `[${FLOATING_LAYER_ATTR}]`-let floatingLayerOutsideInteractionDepth = 0+const FLOATING_LAYER_OUTSIDE_INTERACTION_WINDOW_MS = 500+let lastFloatingLayerOutsideInteractionAt = 0type OutsideEventDetail = {originalEvent?: Event@@ -24,20 +25,17 @@ function ownerDocumentForEvent(event: Event) {}export function markFloatingLayerOutsideInteraction() {- floatingLayerOutsideInteractionDepth += 1- globalThis.setTimeout(() => {- floatingLayerOutsideInteractionDepth = Math.max(- 0,- floatingLayerOutsideInteractionDepth - 1,- )- }, 0)+ lastFloatingLayerOutsideInteractionAt = Date.now()}export function shouldKeepParentOpenForFloatingLayer(event: Event) {const target = originalEventTarget(event)+ const isRecentFloatingLayerOutsideInteraction =+ Date.now() - lastFloatingLayerOutsideInteractionAt <=+ FLOATING_LAYER_OUTSIDE_INTERACTION_WINDOW_MSreturn (- floatingLayerOutsideInteractionDepth > 0 ||+ isRecentFloatingLayerOutsideInteraction ||(target instanceof Element &&target.closest(FLOATING_LAYER_SELECTOR) !== null) ||ownerDocumentForEvent(event)?.querySelector(FLOATING_LAYER_SELECTOR) !== nulldiff --git a/web/src/components/ui/sheet.tsx b/web/src/components/ui/sheet.tsxindex 32981d08..f5c123cd 100644--- a/web/src/components/ui/sheet.tsx+++ b/web/src/components/ui/sheet.tsx@@ -6,6 +6,11 @@ import { Dialog as SheetPrimitive } from 'radix-ui'import { cn } from '@/lib/utils'import { Button } from '@/components/ui/button'import { XIcon } from 'lucide-react'+import { shouldKeepParentOpenForFloatingLayer } from '@/components/ui/floating-layer'++function keepSheetOpenForFloatingLayer(event: Event) {+ if (shouldKeepParentOpenForFloatingLayer(event)) event.preventDefault()+}function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {return <SheetPrimitive.Root data-slot="sheet" {...props} />@@ -50,6 +55,9 @@ function SheetContent({children,side = 'right',showCloseButton = true,+ onInteractOutside,+ onPointerDownOutside,+ onFocusOutside,...props}: React.ComponentProps<typeof SheetPrimitive.Content> & {side?: 'top' | 'right' | 'bottom' | 'left'@@ -65,6 +73,18 @@ function SheetContent({'bg-popover text-popover-foreground data-open:animate-in data-open:fade-in-0 data-[side=bottom]:data-open:slide-in-from-bottom-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:animate-out data-closed:fade-out-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=right]:data-closed:slide-out-to-right-10 data-[side=top]:data-closed:slide-out-to-top-10 shadow-overlay fixed z-50 flex flex-col gap-4 bg-clip-padding text-sm transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm',className,)}+ onInteractOutside={(event) => {+ keepSheetOpenForFloatingLayer(event)+ onInteractOutside?.(event)+ }}+ onPointerDownOutside={(event) => {+ keepSheetOpenForFloatingLayer(event)+ onPointerDownOutside?.(event)+ }}+ onFocusOutside={(event) => {+ keepSheetOpenForFloatingLayer(event)+ onFocusOutside?.(event)+ }}{...props}>{children}