diff --git a/editor/src/components/canvas/controls/grid-controls.tsx b/editor/src/components/canvas/controls/grid-controls.tsx index 685a0cf2d6fd..00c211396b2a 100644 --- a/editor/src/components/canvas/controls/grid-controls.tsx +++ b/editor/src/components/canvas/controls/grid-controls.tsx @@ -74,14 +74,9 @@ import { windowToCanvasCoordinates } from '../dom-lookup' import type { Axis } from '../gap-utils' import { useCanvasAnimation } from '../ui-jsx-canvas-renderer/animation-context' import { CanvasOffsetWrapper } from './canvas-offset-wrapper' -import type { - GridControlsProps, - GridData, - GridMeasurementHelperData, -} from './grid-controls-for-strategies' +import type { GridControlsProps, GridData } from './grid-controls-for-strategies' import { edgePositionToGridResizeEdge, - getNullableAutoOrTemplateBaseString, GridCellTestId, GridControlKey, gridEdgeToEdgePosition, @@ -148,8 +143,22 @@ const GridResizingControl = React.memo((props: GridResizingControlProps) => { const dispatch = useDispatch() const colorTheme = useColorTheme() + const canResize = React.useMemo(() => { + return ( + props.fromPropsAxisValues?.type === 'DIMENSIONS' && + props.fromPropsAxisValues.dimensions.length > 0 + ) + }, [props.fromPropsAxisValues]) + const mouseDownHandler = React.useCallback( (event: React.MouseEvent): void => { + event.stopPropagation() + event.preventDefault() + + if (!canResize) { + return + } + function mouseUpHandler() { setResizingIndex(null) window.removeEventListener('mouseup', mouseUpHandler) @@ -173,10 +182,8 @@ const GridResizingControl = React.memo((props: GridResizingControlProps) => { ), ), ]) - event.stopPropagation() - event.preventDefault() }, - [canvasOffset, dispatch, props.axis, props.dimensionIndex, scale, setResizingIndex], + [canvasOffset, dispatch, props.axis, props.dimensionIndex, scale, setResizingIndex, canResize], ) const { maybeClearHighlightsOnHoverEnd } = useMaybeHighlightElement() @@ -229,7 +236,9 @@ const GridResizingControl = React.memo((props: GridResizingControlProps) => { display: 'flex', alignItems: 'center', justifyContent: 'center', - cursor: gridEdgeToCSSCursor(props.axis === 'column' ? 'column-start' : 'row-start'), + cursor: canResize + ? gridEdgeToCSSCursor(props.axis === 'column' ? 'column-start' : 'row-start') + : 'default', pointerEvents: 'initial', }} onMouseDown={mouseDownHandler} @@ -452,16 +461,23 @@ export const GridRowColumnResizingControlsComponent = ({ }: GridRowColumnResizingControlsProps) => { const grids = useGridData([target]) - function getStripedAreaLength(template: GridAutoOrTemplateBase | null, gap: number) { + function getStripedAreaLength( + template: GridAutoOrTemplateBase | null, + gap: number, + ): number | null { if (template?.type !== 'DIMENSIONS') { return null } - return template.dimensions.reduce((acc, curr, index) => { + const fromDimensions = template.dimensions.reduce((acc, curr, index) => { if (curr.type === 'NUMBER') { return acc + curr.value.value + (index > 0 ? gap : 0) } return acc }, 0) + if (fromDimensions <= 0) { + return null + } + return fromDimensions } const scale = useEditorState( @@ -514,7 +530,9 @@ export const GridRowColumnResizingControlsComponent = ({ axis={'column'} gap={grid.columnGap ?? grid.gap} padding={grid.padding} - stripedAreaLength={getStripedAreaLength(grid.gridTemplateRows, grid.gap ?? 0)} + stripedAreaLength={ + getStripedAreaLength(grid.gridTemplateRows, grid.gap ?? 0) ?? grid.frame.height + } alignContent={grid.justifyContent} justifyContent={grid.alignContent} /> @@ -530,7 +548,9 @@ export const GridRowColumnResizingControlsComponent = ({ axis={'row'} gap={grid.rowGap ?? grid.gap} padding={grid.padding} - stripedAreaLength={getStripedAreaLength(grid.gridTemplateColumns, grid.gap ?? 0)} + stripedAreaLength={ + getStripedAreaLength(grid.gridTemplateColumns, grid.gap ?? 0) ?? grid.frame.width + } alignContent={grid.alignContent} justifyContent={grid.justifyContent} />