-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pixel to percentage conversion methods better handle negative group s…
- Loading branch information
Showing
9 changed files
with
177 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
47 changes: 47 additions & 0 deletions
47
packages/react-resizable-panels/src/utils/convertPixelConstraintsToPercentages.test.ts
This file contains 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,47 @@ | ||
import { convertPixelConstraintsToPercentages } from "./convertPixelConstraintsToPercentages"; | ||
|
||
describe("convertPixelConstraintsToPercentages", () => { | ||
it("should respect percentage panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
convertPixelConstraintsToPercentages( | ||
{ | ||
minSizePercentage: 25, | ||
defaultSizePercentage: 50, | ||
maxSizePercentage: 75, | ||
}, | ||
-100 | ||
) | ||
).toEqual({ | ||
collapsedSizePercentage: 0, | ||
defaultSizePercentage: 50, | ||
maxSizePercentage: 75, | ||
minSizePercentage: 25, | ||
}); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
// Edge case test (issues/206) | ||
it("should ignore pixel panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
convertPixelConstraintsToPercentages( | ||
{ | ||
minSizePixels: 25, | ||
maxSizePixels: 75, | ||
}, | ||
-100 | ||
) | ||
).toEqual({ | ||
collapsedSizePercentage: 0, | ||
defaultSizePercentage: undefined, | ||
maxSizePercentage: 0, | ||
minSizePercentage: 0, | ||
}); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains 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
4 changes: 3 additions & 1 deletion
4
packages/react-resizable-panels/src/utils/dom/getPanelGroupElement.ts
This file contains 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
45 changes: 45 additions & 0 deletions
45
packages/react-resizable-panels/src/utils/resizePanel.test.ts
This file contains 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,45 @@ | ||
import { resizePanel } from "./resizePanel"; | ||
|
||
describe("resizePanel", () => { | ||
// Edge case test (issues/206) | ||
fit("should respect percentage panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
resizePanel({ | ||
groupSizePixels: -100, | ||
panelConstraints: [ | ||
{ | ||
minSizePercentage: 25, | ||
maxSizePercentage: 75, | ||
}, | ||
], | ||
panelIndex: 0, | ||
size: 50, | ||
}) | ||
).toBe(50); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
// Edge case test (issues/206) | ||
it("should handle pixel panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
resizePanel({ | ||
groupSizePixels: -100, | ||
panelConstraints: [ | ||
{ | ||
minSizePixels: 25, | ||
maxSizePixels: 75, | ||
}, | ||
], | ||
panelIndex: 0, | ||
size: 50, | ||
}) | ||
).toBe(0); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains 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
3a2976d
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.
Successfully deployed to the following URLs:
react-resizable-panels – ./
react-resizable-panels.vercel.app
react-resizable-panels-git-main-bvaughn.vercel.app
react-resizable-panels-bvaughn.vercel.app