diff --git a/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.spec.browser2.tsx b/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.spec.browser2.tsx index 0794789c9b11..ac49bea9ee31 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.spec.browser2.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.spec.browser2.tsx @@ -13,7 +13,6 @@ import { CanvasControlsContainerID } from '../../controls/new-canvas-controls' import { CircularHandleTestId } from '../../controls/select-mode/border-radius-control' import { mouseClickAtPoint, - mouseDoubleClickAtPoint, mouseDragFromPointToPoint, mouseDragFromPointWithDelta, mouseEnterAtPoint, @@ -187,7 +186,8 @@ describe('set border radius strategy', () => { codeForDragTest(`borderTopLeftRadius: '24px', borderTopRightRadius: '15px', borderBottomRightRadius: '16px', - borderBottomLeftRadius: '17px'`), + borderBottomLeftRadius: '17px', + overflow: 'hidden'`), ) }) @@ -202,7 +202,7 @@ describe('set border radius strategy', () => { await doDragTest(editor, 'tl', 400, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '${expectedBorderRadius}px'`), + codeForDragTest(`borderRadius: '${expectedBorderRadius}px', overflow: 'hidden'`), ) }) @@ -213,7 +213,7 @@ describe('set border radius strategy', () => { ) await doDragTest(editor, 'tl', -20, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '0px'`), + codeForDragTest(`borderRadius: '0px', overflow: 'hidden'`), ) }) @@ -240,7 +240,7 @@ describe('set border radius strategy', () => { await doDragTest(editor, 'tl', 400, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '200px'`), + codeForDragTest(`borderRadius: '200px', overflow: 'hidden'`), ) await resizeElement( @@ -267,6 +267,7 @@ describe('set border radius strategy', () => { width: 300, height: 100, borderRadius: '40px', + overflow: 'hidden', }} /> `), @@ -280,7 +281,7 @@ describe('set border radius strategy', () => { ) await doDragTest(editor, 'tl', 10, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '22px'`), + codeForDragTest(`borderRadius: '22px', overflow: 'hidden'`), ) }) @@ -292,7 +293,7 @@ describe('set border radius strategy', () => { ) await doDragTest(editor, 'tl', 10, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '24px'`), + codeForDragTest(`borderRadius: '24px', overflow: 'hidden'`), ) }) @@ -303,7 +304,7 @@ describe('set border radius strategy', () => { ) await doDragTest(editor, 'tr', 10, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '24px'`), + codeForDragTest(`borderRadius: '24px', overflow: 'hidden'`), ) }) @@ -314,7 +315,7 @@ describe('set border radius strategy', () => { ) await doDragTest(editor, 'bl', 10, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '24px'`), + codeForDragTest(`borderRadius: '24px', overflow: 'hidden'`), ) }) @@ -325,7 +326,7 @@ describe('set border radius strategy', () => { ) await doDragTest(editor, 'br', 10, emptyModifiers) expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( - codeForDragTest(`borderRadius: '24px'`), + codeForDragTest(`borderRadius: '24px', overflow: 'hidden'`), ) }) }) @@ -341,7 +342,8 @@ describe('set border radius strategy', () => { codeForDragTest(`borderTopLeftRadius: '24px', borderTopRightRadius: '14px', borderBottomRightRadius: '14px', - borderBottomLeftRadius: '14px',`), + borderBottomLeftRadius: '14px', + overflow: 'hidden'`), ) }) @@ -355,7 +357,8 @@ describe('set border radius strategy', () => { codeForDragTest(`borderTopLeftRadius: '14px', borderTopRightRadius: '24px', borderBottomRightRadius: '14px', - borderBottomLeftRadius: '14px',`), + borderBottomLeftRadius: '14px', + overflow: 'hidden'`), ) }) @@ -369,7 +372,8 @@ describe('set border radius strategy', () => { codeForDragTest(`borderTopLeftRadius: '14px', borderTopRightRadius: '14px', borderBottomRightRadius: '14px', - borderBottomLeftRadius: '24px',`), + borderBottomLeftRadius: '24px', + overflow: 'hidden'`), ) }) @@ -383,10 +387,43 @@ describe('set border radius strategy', () => { codeForDragTest(`borderTopLeftRadius: '14px', borderTopRightRadius: '14px', borderBottomRightRadius: '24px', - borderBottomLeftRadius: '14px',`), + borderBottomLeftRadius: '14px', + overflow: 'hidden'`), ) }) }) + + describe('Overflow property handling', () => { + it('does not overwrite existing overflow property', async () => { + const editor = await renderTestEditorWithCode( + codeForDragTest(`borderRadius: '14px', overflow: 'visible',`), + 'await-first-dom-report', + ) + await doDragTest(editor, 'tl', 10, cmdModifier) + expect(getPrintedUiJsCode(editor.getEditorState())).toEqual( + codeForDragTest(`overflow: 'visible', + borderTopLeftRadius: '24px', + borderTopRightRadius: '14px', + borderBottomRightRadius: '14px', + borderBottomLeftRadius: '14px'`), + ) + }) + + it('shows toast message', async () => { + const editor = await renderTestEditorWithCode( + codeForDragTest(`borderRadius: '14px',`), + 'await-first-dom-report', + ) + await doDragTest(editor, 'tl', 10, cmdModifier) + expect(editor.getEditorState().editor.toasts).toHaveLength(1) + expect(editor.getEditorState().editor.toasts[0]).toEqual({ + id: 'property-added', + level: 'NOTICE', + message: 'Element now hides overflowing content', + persistent: false, + }) + }) + }) }) function codeForDragTest(borderRadius: string): string { diff --git a/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.tsx b/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.tsx index 4d0cd8a69430..b96b15eb4481 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/set-border-radius-strategy.tsx @@ -12,6 +12,7 @@ import { isJSXElement, jsxElementName, jsxElementNameEquals, + modifiableAttributeIsAttributeNotFound, } from '../../../../core/shared/element-template' import type { CanvasPoint, CanvasVector, Size } from '../../../../core/shared/math-utils' import { @@ -69,6 +70,11 @@ import { import type { InteractionSession } from '../interaction-state' import { deleteProperties } from '../../commands/delete-properties-command' import { allElemsEqual } from '../../../../core/shared/array-utils' +import * as PP from '../../../../core/shared/property-path' +import { withUnderlyingTarget } from '../../../editor/store/editor-state' +import type { ProjectContentTreeRoot } from '../../../assets' +import { getModifiableJSXAttributeAtPath } from '../../../../core/shared/jsx-attributes' +import { showToastCommand } from '../../commands/show-toast-command' export const SetBorderRadiusStrategyId = 'SET_BORDER_RADIUS_STRATEGY' @@ -149,6 +155,7 @@ export const setBorderRadiusStrategy: CanvasStrategyFactory = ( strategyApplicationResult([ setCursorCommand(CSSCursor.Radius), ...commands(selectedElement), + ...getAddOverflowHiddenCommands(selectedElement, canvasState.projectContents), setElementsToRerenderCommand(selectedElements), ]), } @@ -586,3 +593,30 @@ const setShorthandStylePropertyCommand = ]), setProperty('always', target, StyleProp('borderRadius'), value), ] + +function getAddOverflowHiddenCommands( + target: ElementPath, + projectContents: ProjectContentTreeRoot, +): Array { + const overflowProp = PP.create('style', 'overflow') + + const propertyExists = withUnderlyingTarget(target, projectContents, false, (_, element) => { + if (isJSXElement(element)) { + return foldEither( + () => false, + (value) => !modifiableAttributeIsAttributeNotFound(value), + getModifiableJSXAttributeAtPath(element.props, overflowProp), + ) + } else { + return false + } + }) + + if (propertyExists) { + return [] + } + return [ + showToastCommand('Element now hides overflowing content', 'NOTICE', 'property-added'), + setProperty('always', target, overflowProp, 'hidden'), + ] +}