diff --git a/editor/src/components/canvas/controls/grid-controls.tsx b/editor/src/components/canvas/controls/grid-controls.tsx
index c651f64879d4..6c9958557dd7 100644
--- a/editor/src/components/canvas/controls/grid-controls.tsx
+++ b/editor/src/components/canvas/controls/grid-controls.tsx
@@ -405,12 +405,6 @@ export const GridResizing = React.memo((props: GridResizingProps) => {
})
}, [props.fromPropsAxisValues, resizingIndex])
- const scale = useEditorState(
- Substores.canvas,
- (store) => store.editor.canvas.scale,
- 'GridResizing scale',
- )
-
if (props.axisValues == null) {
return null
}
@@ -419,11 +413,6 @@ export const GridResizing = React.memo((props: GridResizingProps) => {
const size = GRID_RESIZE_HANDLE_CONTAINER_SIZE / canvasScale
const dimensions = props.axisValues.dimensions
- const hideControls = dimensions.some((dim) => {
- const scaledSize = (dim.type === 'NUMBER' ? dim.value.value : 0) * scale
- return scaledSize < GRID_RESIZE_HANDLE_SIZE
- })
-
return (
{
: undefined,
paddingTop:
props.axis === 'row' && props.padding != null ? `${props.padding.top}px` : undefined,
- visibility: hideControls ? 'hidden' : 'visible',
}}
>
{dimensions.flatMap((dimension, dimensionIndex) => {
@@ -594,9 +582,47 @@ export const GridRowColumnResizingControls =
}, 0)
}
+ const scale = useEditorState(
+ Substores.canvas,
+ (store) => store.editor.canvas.scale,
+ 'GridRowColumnResizingControls scale',
+ )
+
+ const gridsWithVisibleResizeControls = React.useMemo(() => {
+ return grids.filter((grid) => {
+ if (
+ grid.gridTemplateColumns?.type !== 'DIMENSIONS' ||
+ grid.gridTemplateRows?.type !== 'DIMENSIONS'
+ ) {
+ return false
+ }
+
+ // returns whether the rendered dimensions are too crowded, as in there are two cols/rows that are closer than the handle sizes
+ function tooCrowded(dimensions: GridDimension[]): boolean {
+ const visualSizes = dimensions.map(
+ (dim) => (dim.type === 'NUMBER' ? dim.value.value : 0) * scale,
+ )
+ return visualSizes.some((dim, index) => {
+ if (index < visualSizes.length - 1) {
+ const next = visualSizes[index + 1]
+ if (dim + next < GRID_RESIZE_HANDLE_SIZE * 2) {
+ return true
+ }
+ }
+ return false
+ })
+ }
+
+ return (
+ !tooCrowded(grid.gridTemplateColumns.dimensions) &&
+ !tooCrowded(grid.gridTemplateRows.dimensions)
+ )
+ })
+ }, [scale, grids])
+
return (
- {grids.flatMap((grid) => {
+ {gridsWithVisibleResizeControls.flatMap((grid) => {
return (
)
})}
- {grids.flatMap((grid) => {
+ {gridsWithVisibleResizeControls.flatMap((grid) => {
return (