Skip to content

Commit 06565e5

Browse files
authored
Fix misaligned gap controls when justifyContent or alignContent is set (#6565)
**Problem:** Gap controls are misaligned when justifyContent or alignContent is set, e.g.: <img width="337" alt="image" src="https://github.com/user-attachments/assets/64150066-2114-4b20-84f3-fbedfce94840"> **Fix:** GridRowHighlight (I renamed it to GridRowOrColumnHighlight) component sets alignContent (when it is a column) or justifyContent (when it is a row) to the value coming from the grid style. **Manual Tests:** I hereby swear that: - [x] I opened a hydrogen project and it loaded - [x] I could navigate to various routes in Play mode
1 parent 40c535a commit 06565e5

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

editor/src/components/canvas/controls/grid-controls-for-strategies.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
} from './grid-controls'
3434
import { isEdgePositionOnSide } from '../canvas-utils'
3535
import { findOriginalGrid } from '../canvas-strategies/strategies/grid-helpers'
36+
import type { AlignContent, FlexJustifyContent } from '../../inspector/inspector-common'
3637

3738
export const GridCellTestId = (elementPath: ElementPath) => `grid-cell-${EP.toString(elementPath)}`
3839

@@ -70,8 +71,8 @@ export type GridMeasurementHelperData = {
7071
gap: number | null
7172
rowGap: number | null
7273
columnGap: number | null
73-
justifyContent: string | null
74-
alignContent: string | null
74+
justifyContent: FlexJustifyContent | null
75+
alignContent: AlignContent | null
7576
padding: Sides
7677
columns: number
7778
cells: number

editor/src/components/canvas/controls/select-mode/grid-gap-control-component.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@ import type { CSSProperties } from 'react'
22
import React from 'react'
33
import { createArrayWithLength, interleaveArray } from '../../../../core/shared/array-utils'
44
import type { GridAutoOrTemplateBase } from '../../../../core/shared/element-template'
5-
import type { CanvasVector, Size } from '../../../../core/shared/math-utils'
6-
import { size, windowPoint } from '../../../../core/shared/math-utils'
5+
import type { Size } from '../../../../core/shared/math-utils'
6+
import { size } from '../../../../core/shared/math-utils'
77
import type { ElementPath } from '../../../../core/shared/project-file-types'
88
import { assertNever } from '../../../../core/shared/utils'
9-
import { Modifier } from '../../../../utils/modifiers'
109
import { when } from '../../../../utils/react-conditionals'
1110
import type { UtopiColor } from '../../../../uuiui'
1211
import { useColorTheme, UtopiaStyles } from '../../../../uuiui'
1312
import { CSSCursor } from '../../../../uuiui-deps'
14-
import type { EditorDispatch } from '../../../editor/action-types'
1513
import { useDispatch } from '../../../editor/store/dispatch-context'
1614
import { Substores, useEditorState, useRefEditorState } from '../../../editor/store/store-hook'
1715
import {
1816
cssNumber,
1917
printCSSNumber,
2018
stringifyGridDimension,
2119
} from '../../../inspector/common/css-utils'
22-
import CanvasActions from '../../canvas-actions'
23-
import { createInteractionViaMouse, gridGapHandle } from '../../canvas-strategies/interaction-state'
24-
import { windowToCanvasCoordinates } from '../../dom-lookup'
2520
import type { Axis } from '../../gap-utils'
2621
import { maybeGridGapData } from '../../gap-utils'
2722
import { CanvasOffsetWrapper } from '../canvas-offset-wrapper'
@@ -31,6 +26,7 @@ import { getGridHelperStyleMatchingTargetGrid } from '../grid-controls-helpers'
3126
import type { CSSNumberWithRenderedValue } from './controls-common'
3227
import { CanvasLabel, PillHandle, useHoverWithDelay } from './controls-common'
3328
import { startGapControlInteraction } from './grid-gap-control-helpers'
29+
import type { AlignContent, FlexJustifyContent } from '../../../inspector/inspector-common'
3430

3531
export interface GridGapControlProps {
3632
selectedElement: ElementPath
@@ -187,7 +183,7 @@ export const GridPaddingOutlineForDimension = (props: {
187183
{createArrayWithLength(length, (index) => {
188184
const hide = index === 0 || index === length - 1 || index % 2 === 0
189185
return (
190-
<GridRowHighlight
186+
<GridRowOrColumnHighlight
191187
key={index}
192188
hide={hide} // we only want to show the divs that fall in where the gaps are in the original grid
193189
gapId={`${dimension}-${index}`}
@@ -202,6 +198,8 @@ export const GridPaddingOutlineForDimension = (props: {
202198
beingDragged={beingDragged}
203199
onMouseOver={onMouseOver}
204200
elementHovered={elementHovered}
201+
gridJustifyContent={grid.justifyContent}
202+
gridAlignContent={grid.alignContent}
205203
draggedOutlineColor={draggedOutlineColor}
206204
/>
207205
)
@@ -210,7 +208,7 @@ export const GridPaddingOutlineForDimension = (props: {
210208
)
211209
}
212210

213-
const GridRowHighlight = (props: {
211+
const GridRowOrColumnHighlight = (props: {
214212
gapId: string
215213
onMouseDown: React.MouseEventHandler
216214
hide: boolean
@@ -222,6 +220,8 @@ const GridRowHighlight = (props: {
222220
beingDragged: boolean
223221
onMouseOver: () => void
224222
elementHovered: boolean
223+
gridJustifyContent: FlexJustifyContent | null
224+
gridAlignContent: AlignContent | null
225225
draggedOutlineColor?: UtopiColor
226226
}) => {
227227
const {
@@ -236,6 +236,8 @@ const GridRowHighlight = (props: {
236236
beingDragged,
237237
onMouseOver,
238238
elementHovered,
239+
gridJustifyContent,
240+
gridAlignContent,
239241
draggedOutlineColor,
240242
} = props
241243

@@ -302,8 +304,8 @@ const GridRowHighlight = (props: {
302304
boxShadow: `inset 0 0 0 ${lineWidth}px ${outlineColor}`,
303305
opacity: hide ? 0 : 1,
304306

305-
alignItems: 'center',
306-
justifyContent: 'center',
307+
alignContent: axis === 'row' ? undefined : gridAlignContent ?? undefined,
308+
justifyContent: axis === 'row' ? gridJustifyContent ?? undefined : undefined,
307309
placeItems: 'center',
308310

309311
gap: gap ?? 0,

0 commit comments

Comments
 (0)