-
Notifications
You must be signed in to change notification settings - Fork 1
fix(VE-6459): psuedo-editable height collapse #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
faraazb
merged 2 commits into
develop_v3
from
VE-6459-fix-psuedoeditable-height-collapse
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
src/visualBuilder/utils/__test__/getPsuedoEditableEssentialStyles.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { getPsuedoEditableEssentialStyles } from "../getPsuedoEditableEssentialStyles"; | ||
|
|
||
| describe("getPsuedoEditableEssentialStyles", () => { | ||
| const mockRect: DOMRect = { | ||
| top: 50, | ||
| left: 30, | ||
| width: 200, | ||
| height: 100, | ||
| bottom: 150, | ||
| right: 230, | ||
| x: 30, | ||
| y: 50, | ||
| toJSON: () => ({}), | ||
| }; | ||
|
|
||
| const mockScrollX = 100; | ||
| const mockScrollY = 200; | ||
|
|
||
| beforeEach(() => { | ||
| // Mock window.scrollX and window.scrollY using vitest spies | ||
| vi.spyOn(window, "scrollX", "get").mockReturnValue(mockScrollX); | ||
| vi.spyOn(window, "scrollY", "get").mockReturnValue(mockScrollY); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| test("returns styles with kebab-case properties when camelCase is false", () => { | ||
| const result = getPsuedoEditableEssentialStyles({ | ||
| rect: mockRect, | ||
| camelCase: false, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| position: "absolute", | ||
| top: `${mockRect.top + mockScrollY}px`, | ||
| left: `${mockRect.left + mockScrollX}px`, | ||
| height: "auto", | ||
| "min-height": `${Math.abs(mockRect.height)}px`, | ||
| "white-space": "normal", | ||
| "text-transform": "none", | ||
| "text-wrap-mode": "wrap", | ||
| "text-overflow": "visible", | ||
| }); | ||
| }); | ||
|
|
||
| test("returns styles with kebab-case properties when camelCase is undefined", () => { | ||
| const result = getPsuedoEditableEssentialStyles({ | ||
| rect: mockRect, | ||
| camelCase: undefined, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| position: "absolute", | ||
| top: `${mockRect.top + mockScrollY}px`, | ||
| left: `${mockRect.left + mockScrollX}px`, | ||
| height: "auto", | ||
| "min-height": `${Math.abs(mockRect.height)}px`, | ||
| "white-space": "normal", | ||
| "text-transform": "none", | ||
| "text-wrap-mode": "wrap", | ||
| "text-overflow": "visible", | ||
| }); | ||
| }); | ||
|
|
||
| test("returns styles with camelCase properties when camelCase is true", () => { | ||
| const result = getPsuedoEditableEssentialStyles({ | ||
| rect: mockRect, | ||
| camelCase: true, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| position: "absolute", | ||
| top: `${mockRect.top + mockScrollY}px`, | ||
| left: `${mockRect.left + mockScrollX}px`, | ||
| height: "auto", | ||
| minHeight: `${Math.abs(mockRect.height)}px`, | ||
| whiteSpace: "normal", | ||
| textTransform: "none", | ||
| textWrapMode: "wrap", | ||
| textOverflow: "visible", | ||
| }); | ||
| }); | ||
|
|
||
| test("calculates correct positioning with scroll offset", () => { | ||
| const customScrollX = 50; | ||
| const customScrollY = 150; | ||
|
|
||
| // Override the default mock values for this test | ||
| vi.spyOn(window, "scrollX", "get").mockReturnValue(customScrollX); | ||
| vi.spyOn(window, "scrollY", "get").mockReturnValue(customScrollY); | ||
|
|
||
| const result = getPsuedoEditableEssentialStyles({ | ||
| rect: mockRect, | ||
| camelCase: false, | ||
| }); | ||
|
|
||
| expect(result.top).toBe(`${mockRect.top + customScrollY}px`); | ||
| expect(result.left).toBe(`${mockRect.left + customScrollX}px`); | ||
| }); | ||
|
|
||
| test("handles negative rect heights correctly", () => { | ||
| const negativeHeightRect: DOMRect = { | ||
| ...mockRect, | ||
| height: -50, | ||
| }; | ||
|
|
||
| const result = getPsuedoEditableEssentialStyles({ | ||
| rect: negativeHeightRect, | ||
| camelCase: false, | ||
| }); | ||
|
|
||
| expect(result["min-height"]).toBe( | ||
| `${Math.abs(negativeHeightRect.height)}px` | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/visualBuilder/utils/getPsuedoEditableEssentialStyles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import getCamelCaseStyles from "./getCamelCaseStyles"; | ||
|
|
||
| export function getPsuedoEditableEssentialStyles({ | ||
| rect, | ||
| camelCase, | ||
| }: { | ||
| rect: DOMRect; | ||
| camelCase: boolean | undefined; | ||
| }) { | ||
| const overrides = { | ||
| position: "absolute", | ||
| top: `${rect.top + window.scrollY}px`, | ||
| left: `${rect.left + window.scrollX}px`, | ||
| height: "auto", | ||
| "min-height": `${Math.abs(rect.height)}px`, | ||
| "white-space": "normal", | ||
| "text-transform": "none", | ||
| "text-wrap-mode": "wrap", | ||
| "text-overflow": "visible", | ||
| }; | ||
| return camelCase ? getCamelCaseStyles(overrides) : overrides; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,19 @@ | ||
| import getCamelCaseStyles from "./getCamelCaseStyles"; | ||
| import { getPsuedoEditableEssentialStyles } from "./getPsuedoEditableEssentialStyles"; | ||
| import getStyleOfAnElement from "./getStyleOfAnElement"; | ||
|
|
||
| export function getPsuedoEditableElementStyles( | ||
| psuedoEditableElement: HTMLElement, | ||
| camelCase?: boolean | ||
| ): { [key: string]: string } { | ||
| let styles = getStyleOfAnElement(psuedoEditableElement); | ||
| if (camelCase) { | ||
| styles = getCamelCaseStyles(styles); | ||
| } | ||
| // Get the offsetTop and offsetLeft of the editable element and set the position of the pseudo editable element | ||
| // The pseudo editable element is positioned absolutely at the same location as the editable element | ||
| const rect = psuedoEditableElement.getBoundingClientRect(); | ||
|
|
||
| styles.position = "absolute"; | ||
| styles.top = `${rect.top + window.scrollY}px`; | ||
| styles.left = `${rect.left + window.scrollX}px`; | ||
| // setting height to auto so that the element can grow based on the content | ||
| // and the resize observer can detect the change in height | ||
| styles.height = "auto"; | ||
| styles.whiteSpace = "pre-line"; | ||
| styles.textTransform = "none"; | ||
|
|
||
| return styles; | ||
| if (camelCase) { | ||
| styles = getCamelCaseStyles(styles); | ||
| } | ||
| const overrides = getPsuedoEditableEssentialStyles({ rect, camelCase }); | ||
| return { ...styles, ...overrides }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will override all the styles if camelCase is true. Is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is expected. I moved this down so we camelCase both exising and overriden fields. However, we are dependent on camelCase implementation in this case, so I have now removed this dependency on the latest commit