Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix horizontal scroll and last element selection in the Tree (#2181)

Ivan Starkov5a529cd8bdb3
diff --git a/packages/design-system/src/components/scroll-area.tsx b/packages/design-system/src/components/scroll-area.tsx
index 39784acc3d..77a3cbfeb5 100644
--- a/packages/design-system/src/components/scroll-area.tsx
+++ b/packages/design-system/src/components/scroll-area.tsx
@@ -13,7 +13,9 @@ const ScrollAreaThumb = styled(Thumb, {
background: theme.colors.foregroundScrollBar,
borderRadius: theme.spacing[4],
// increase target size for touch devices https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
+
position: "relative",
+
"&::before": {
content: '""',
position: "absolute",
@@ -22,8 +24,24 @@ const ScrollAreaThumb = styled(Thumb, {
transform: "translate(-50%, -50%)",
width: "100%",
height: "100%",
- minWidth: 16,
- minHeight: 44,
+ },
+
+ variants: {
+ orientation: {
+ vertical: {
+ "&::before": {
+ minWidth: 16,
+ minHeight: 44,
+ },
+ },
+ horizontal: {
+ minHeight: "100%",
+ "&::before": {
+ minWidth: 44,
+ minHeight: 16,
+ },
+ },
+ },
},
});
@@ -32,15 +50,31 @@ const ScrollAreaScrollbar = styled(Scrollbar, {
// ensures no selection
userSelect: "none",
// disable browser handling of all panning and scaleUp gestures on touch devices
- touchAction: "none",
padding: 2,
- paddingRight: 3,
+ touchAction: "none",
'&[data-orientation="vertical"]': {
width: theme.spacing[6],
+ paddingRight: 3,
},
'&[data-orientation="horizontal"]': {
flexDirection: "column",
height: theme.spacing[6],
+ paddingBottom: 3,
+ },
+
+ variants: {
+ direction: {
+ both: {
+ "&[data-orientation=vertical]": {
+ marginBottom: theme.spacing[4],
+ },
+ '&[data-orientation="horizontal"]': {
+ marginRight: theme.spacing[4],
+ },
+ },
+ horizontal: {},
+ vertical: {},
+ },
},
});
@@ -80,13 +114,13 @@ export const ScrollArea = forwardRef(
{children}
</Viewport>
{(direction === "vertical" || direction === "both") && (
- <ScrollAreaScrollbar orientation="vertical">
- <ScrollAreaThumb />
+ <ScrollAreaScrollbar orientation="vertical" direction={direction}>
+ <ScrollAreaThumb orientation="vertical" />
</ScrollAreaScrollbar>
)}
{(direction === "horizontal" || direction === "both") && (
- <ScrollAreaScrollbar orientation="horizontal">
- <ScrollAreaThumb />
+ <ScrollAreaScrollbar orientation="horizontal" direction={direction}>
+ <ScrollAreaThumb orientation="horizontal" />
</ScrollAreaScrollbar>
)}
</ScrollAreaRoot>
diff --git a/packages/design-system/src/components/tree/tree.tsx b/packages/design-system/src/components/tree/tree.tsx
index 87bb7ae4e8..217db11054 100644
--- a/packages/design-system/src/components/tree/tree.tsx
+++ b/packages/design-system/src/components/tree/tree.tsx
@@ -22,6 +22,7 @@ import {
getItemSelectorFromElement,
} from "./item-utils";
import { ScrollArea } from "../scroll-area";
+import { theme } from "../..";
export type TreeProps<Data extends { id: string }> = {
root: Data;
@@ -288,6 +289,10 @@ export const Tree = <Data extends { id: string }>({
onBlur={keyboardNavigation.handleBlur}
onKeyDown={keyboardNavigation.handleKeyDown}
onClick={keyboardNavigation.handleClick}
+ css={{
+ // To not intersect last element with the scroll
+ marginBottom: theme.spacing[7],
+ }}
>
<TreeNode
renderItem={renderItem}