Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(comments): Fix text selection in trace comments (#9730)

Nimarb384eb5a2b84
diff --git a/web/src/components/ui/drawer.tsx b/web/src/components/ui/drawer.tsx
index b24a149595..5fdca7e654 100644
--- a/web/src/components/ui/drawer.tsx
+++ b/web/src/components/ui/drawer.tsx
@@ -9,6 +9,12 @@ import { cva } from "class-variance-authority";
type DrawerProps = React.ComponentProps<typeof DrawerPrimitive.Root> & {
forceDirection?: "right" | "bottom" | "responsive";
+ /**
+ * Whether to block text selection in the drawer.
+ * Set to false to allow text selection (e.g., in comment sections).
+ * @default false
+ */
+ blockTextSelection?: boolean;
};
type DrawerContentProps = React.ComponentPropsWithoutRef<
@@ -18,6 +24,7 @@ type DrawerContentProps = React.ComponentPropsWithoutRef<
size?: "default" | "md" | "lg" | "full";
position?: "top";
height?: "default" | "md";
+ blockTextSelection?: boolean;
};
// https://tailwindcss.com/docs/responsive-design
@@ -49,9 +56,18 @@ const drawerVariants = cva(
},
);
+const DrawerContext = React.createContext<{
+ blockTextSelection: boolean;
+}>({
+ blockTextSelection: false,
+});
+
+const useDrawerContext = () => React.useContext(DrawerContext);
+
const Drawer = ({
shouldScaleBackground = true,
forceDirection = "responsive",
+ blockTextSelection = false,
...props
}: DrawerProps) => {
const isMediumScreen = useMediaQuery({
@@ -65,11 +81,13 @@ const Drawer = ({
: forceDirection;
return (
- <DrawerPrimitive.Root
- shouldScaleBackground={shouldScaleBackground}
- direction={direction}
- {...props}
- />
+ <DrawerContext.Provider value={{ blockTextSelection }}>
+ <DrawerPrimitive.Root
+ shouldScaleBackground={shouldScaleBackground}
+ direction={direction}
+ {...props}
+ />
+ </DrawerContext.Provider>
);
};
Drawer.displayName = "Drawer";
@@ -99,21 +117,26 @@ const DrawerContent = React.forwardRef<
(
{ className, children, overlayClassName, size, height, position, ...props },
ref,
- ) => (
- <DrawerPortal>
- <DrawerOverlay className={overlayClassName} />
- <DrawerPrimitive.Content
- ref={ref}
- className={cn(drawerVariants({ size, className, height, position }))}
- {...props}
- >
- <DrawerDescription className="sr-only">
- {props.title ?? ""}
- </DrawerDescription>
- {children}
- </DrawerPrimitive.Content>
- </DrawerPortal>
- ),
+ ) => {
+ const { blockTextSelection } = useDrawerContext();
+
+ return (
+ <DrawerPortal>
+ <DrawerOverlay className={overlayClassName} />
+ <DrawerPrimitive.Content
+ ref={ref}
+ className={cn(drawerVariants({ size, className, height, position }))}
+ data-allow-text-selection={!blockTextSelection}
+ {...props}
+ >
+ <DrawerDescription className="sr-only">
+ {props.title ?? ""}
+ </DrawerDescription>
+ {children}
+ </DrawerPrimitive.Content>
+ </DrawerPortal>
+ );
+ },
);
DrawerContent.displayName = "DrawerContent";
diff --git a/web/src/styles/globals.css b/web/src/styles/globals.css
index 320e06590b..a71f5685c6 100644
--- a/web/src/styles/globals.css
+++ b/web/src/styles/globals.css
@@ -245,3 +245,17 @@
}
}
}
+
+/*
+ * Fix for Vaul drawer blocking text selection
+ * Vaul applies user-select: none to the entire drawer on desktop via CSS media query
+ * We override this for drawers that set blockTextSelection={false}
+ * See: node_modules/vaul/dist/index.js line 84
+ */
+[data-vaul-drawer][data-allow-text-selection="true"],
+[data-vaul-drawer][data-allow-text-selection="true"] * {
+ user-select: text !important;
+ -webkit-user-select: text !important;
+ -moz-user-select: text !important;
+ -ms-user-select: text !important;
+}