-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add onDragging prop to PanelResizeHandle (#113)
Resolves issue #94
- Loading branch information
Showing
7 changed files
with
185 additions
and
27 deletions.
There are no files selected for viewing
12 changes: 10 additions & 2 deletions
12
packages/react-resizable-panels-website/src/routes/examples/types.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 |
---|---|---|
@@ -1,29 +1,37 @@ | ||
export type PanelCollapseLogEntryType = "onCollapse"; | ||
export type PanelGroupLayoutLogEntryType = "onLayout"; | ||
export type PanelResizeHandleDraggingLogEntryType = "onDragging"; | ||
export type PanelResizeLogEntryType = "onResize"; | ||
|
||
export type PanelCollapseLogEntry = { | ||
collapsed: boolean; | ||
panelId: string; | ||
type: PanelCollapseLogEntryType; | ||
}; | ||
export type PanelResizeHandleDraggingLogEntry = { | ||
isDragging: boolean; | ||
resizeHandleId: string; | ||
type: PanelResizeHandleDraggingLogEntryType; | ||
}; | ||
export type PanelGroupLayoutLogEntry = { | ||
groupId: string; | ||
type: PanelGroupLayoutLogEntryType; | ||
sizes: number[]; | ||
type: PanelGroupLayoutLogEntryType; | ||
}; | ||
export type PanelResizeLogEntry = { | ||
panelId: string; | ||
type: PanelResizeLogEntryType; | ||
size: number; | ||
type: PanelResizeLogEntryType; | ||
}; | ||
|
||
export type LogEntryType = | ||
| PanelCollapseLogEntryType | ||
| PanelResizeHandleDraggingLogEntryType | ||
| PanelGroupLayoutLogEntryType | ||
| PanelResizeLogEntryType; | ||
|
||
export type LogEntry = | ||
| PanelCollapseLogEntry | ||
| PanelResizeHandleDraggingLogEntry | ||
| PanelGroupLayoutLogEntry | ||
| PanelResizeLogEntry; |
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
93 changes: 93 additions & 0 deletions
93
packages/react-resizable-panels-website/tests/ResizeHandle-OnDragging.spec.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,93 @@ | ||
import { expect, Page, test } from "@playwright/test"; | ||
import { createElement } from "react"; | ||
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; | ||
|
||
import { PanelResizeHandleDraggingLogEntry } from "../src/routes/examples/types"; | ||
|
||
import { clearLogEntries, getLogEntries } from "./utils/debug"; | ||
import { goToUrl } from "./utils/url"; | ||
|
||
async function openPage(page: Page) { | ||
const panelGroup = createElement( | ||
PanelGroup, | ||
{ direction: "horizontal", id: "group" }, | ||
createElement(Panel, { collapsible: true, defaultSize: 20, order: 1 }), | ||
createElement(PanelResizeHandle, { id: "left-handle" }), | ||
createElement(Panel, { defaultSize: 60, order: 2 }), | ||
createElement(PanelResizeHandle, { id: "right-handle" }), | ||
createElement(Panel, { collapsible: true, defaultSize: 20, order: 3 }) | ||
); | ||
|
||
await goToUrl(page, panelGroup); | ||
} | ||
|
||
async function verifyEntries( | ||
page: Page, | ||
expected: Array<[handleId: string, isDragging: boolean]> | ||
) { | ||
const logEntries = await getLogEntries<PanelResizeHandleDraggingLogEntry>( | ||
page, | ||
"onDragging" | ||
); | ||
|
||
expect(logEntries.length).toEqual(expected.length); | ||
|
||
for (let index = 0; index < expected.length; index++) { | ||
const { isDragging: isDraggingActual, resizeHandleId: handleIdActual } = | ||
logEntries[index]; | ||
const [handleIdExpected, isDraggingExpected] = expected[index]; | ||
expect(handleIdExpected).toEqual(handleIdActual); | ||
expect(isDraggingExpected).toEqual(isDraggingActual); | ||
} | ||
} | ||
|
||
test.describe("PanelResizeHandle onDragging prop", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await openPage(page); | ||
}); | ||
|
||
test("should not be called on-mount", async ({ page }) => { | ||
await verifyEntries(page, []); | ||
}); | ||
|
||
test("should be called when the panel ResizeHandle starts or stops resizing", async ({ | ||
page, | ||
}) => { | ||
const leftHandle = page.locator( | ||
'[data-panel-resize-handle-id="left-handle"]' | ||
); | ||
const rightHandle = page.locator( | ||
'[data-panel-resize-handle-id="right-handle"]' | ||
); | ||
|
||
await clearLogEntries(page, "onDragging"); | ||
|
||
let bounds = await leftHandle.boundingBox(); | ||
await page.mouse.move(bounds.x, bounds.y); | ||
await page.mouse.down(); | ||
await page.mouse.move(5, 0); | ||
await page.mouse.move(10, 0); | ||
await page.mouse.move(15, 0); | ||
await verifyEntries(page, [["left-handle", true]]); | ||
|
||
await page.mouse.up(); | ||
await verifyEntries(page, [ | ||
["left-handle", true], | ||
["left-handle", false], | ||
]); | ||
|
||
await clearLogEntries(page, "onDragging"); | ||
|
||
bounds = await rightHandle.boundingBox(); | ||
await page.mouse.move(bounds.x, bounds.y); | ||
await page.mouse.down(); | ||
await page.mouse.move(25, 0); | ||
await verifyEntries(page, [["right-handle", true]]); | ||
|
||
await page.mouse.up(); | ||
await verifyEntries(page, [ | ||
["right-handle", true], | ||
["right-handle", false], | ||
]); | ||
}); | ||
}); |
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
a3537a7
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-bvaughn.vercel.app
react-resizable-panels.vercel.app
react-resizable-panels-git-main-bvaughn.vercel.app