Skip to content

Commit 2b7b587

Browse files
committed
Fix not properly aligned horizontal scroll bar
1 parent 14d2d68 commit 2b7b587

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

src/components/ScrollArea.tsx

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
42
import { cn } from "@utils/helpers";
53
import * as React from "react";
@@ -15,46 +13,31 @@ const ScrollArea = React.forwardRef<
1513
>(({ className, children, withoutViewport = false, ...props }, ref) => (
1614
<ScrollAreaPrimitive.Root
1715
ref={ref}
18-
className={cn(
19-
"relative will-change-scroll webkit-scroll",
20-
className,
21-
"overflow-hidden",
22-
)}
16+
className={cn("relative overflow-hidden", className)}
2317
{...props}
2418
>
2519
{withoutViewport ? (
2620
children
2721
) : (
28-
<ScrollAreaViewport disableOverflowY={false}>
29-
{children}
30-
</ScrollAreaViewport>
22+
<ScrollAreaViewport>{children}</ScrollAreaViewport>
3123
)}
32-
<ScrollBar />
24+
<ScrollBar orientation="horizontal" />
25+
<ScrollBar orientation="vertical" />
3326
<ScrollAreaPrimitive.Corner />
3427
</ScrollAreaPrimitive.Root>
3528
));
3629
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
3730

38-
type AdditionalScrollAreaViewportProps = {
39-
disableOverflowY?: boolean;
40-
};
41-
4231
const ScrollAreaViewport = React.forwardRef<
4332
React.ElementRef<typeof ScrollAreaPrimitive.Viewport>,
44-
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Viewport> &
45-
AdditionalScrollAreaViewportProps
46-
>(({ disableOverflowY = true, ...props }, ref) => {
47-
return (
48-
<ScrollAreaPrimitive.Viewport
49-
ref={ref}
50-
className="h-full w-full rounded-[inherit] will-change-scroll webkit-scroll"
51-
{...props}
52-
style={
53-
disableOverflowY ? { overflowY: undefined, ...props.style } : undefined
54-
}
55-
/>
56-
);
57-
});
33+
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Viewport>
34+
>(({ className, ...props }, ref) => (
35+
<ScrollAreaPrimitive.Viewport
36+
ref={ref}
37+
className={cn("h-full w-full rounded-[inherit]", className)}
38+
{...props}
39+
/>
40+
));
5841
ScrollAreaViewport.displayName = ScrollAreaPrimitive.Viewport.displayName;
5942

6043
const ScrollBar = React.forwardRef<
@@ -63,14 +46,11 @@ const ScrollBar = React.forwardRef<
6346
>(({ className, orientation = "vertical", ...props }, ref) => (
6447
<ScrollAreaPrimitive.ScrollAreaScrollbar
6548
ref={ref}
66-
style={{ boxSizing: "unset", overflow: undefined }}
6749
orientation={orientation}
6850
className={cn(
69-
"flex touch-none select-none transition-colors",
70-
orientation === "vertical" &&
71-
"h-full w-2.5 border-l border-l-transparent p-[1px]",
72-
orientation === "horizontal" &&
73-
"h-2.5 border-t border-t-transparent p-[1px]",
51+
"flex select-none touch-none transition-colors",
52+
orientation === "vertical" && "h-full w-2.5 p-[1px]",
53+
orientation === "horizontal" && "w-full h-2.5 p-[1px] bottom-0",
7454
className,
7555
)}
7656
{...props}
@@ -79,6 +59,7 @@ const ScrollBar = React.forwardRef<
7959
className={cn(
8060
"relative rounded-full bg-neutral-200 dark:bg-nb-gray-800",
8161
orientation === "vertical" && "flex-1",
62+
orientation === "horizontal" && "h-full",
8263
)}
8364
/>
8465
</ScrollAreaPrimitive.ScrollAreaScrollbar>

0 commit comments

Comments
 (0)