抽屉优化

This commit is contained in:
pphua committed 2026-08-25 12:05:26 +08:00
1 parent 7234874797
commit d968727460
14 files changed
+669 -154

No files matched your search

+1 -14
View File
@@ -3,7 +3,7 @@
import * as React from "react"
import { Dialog as SheetPrimitive } from "radix-ui"
import { cn, radixOverlayWasOpenAtPointerDown } from "@/lib/utils"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { XIcon } from "lucide-react"
@@ -50,7 +50,6 @@ function SheetContent({
children,
side = "right",
showCloseButton = true,
onInteractOutside,
...props
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
side?: "top" | "right" | "bottom" | "left"
@@ -62,18 +61,6 @@ function SheetContent({
<SheetPrimitive.Content
data-slot="sheet-content"
data-side={side}
// 关闭抽屉的唯一条件:点击的是遮罩(灰色背景)本身,且此刻没有任何 Radix 弹层
// (Select 下拉等)开着。其余"外部交互"一律挡掉(Esc、右上角 ✕ 仍可关):
// · 点弹层里的选项 → target 不是遮罩 → 挡;
// · 弹层开着时点抽屉外/遮罩想收起它 → 有弹层开着 → 挡(只收弹层,不关抽屉);
// · 弹层收起时焦点移动被 Radix 误判为焦点移出 → target 不是遮罩 → 挡。
// (onInteractOutside 在指针/焦点两条路径都会触发。)调用方仍可追加逻辑。
onInteractOutside={(e) => {
const target = e.detail.originalEvent.target as Element | null
const onOverlay = !!target?.closest?.("[data-slot='sheet-overlay']")
if (!onOverlay || radixOverlayWasOpenAtPointerDown()) e.preventDefault()
onInteractOutside?.(e)
}}
className={cn(
"fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg 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 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",
className