Skip to content

Commit 6cf8d8b

Browse files
committed
feat: add backwards compatible deprecated handlers
- Add onMouseDown, onTouchStart, onTouchEnd back to DividerProps as deprecated - Create wrapper handlers that delegate to onPointerDown - Custom dividers using old props will continue to work - Bump version to 3.1.0 (minor, not breaking)
1 parent ba5b2ca commit 6cf8d8b

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-split-pane",
3-
"version": "4.0.0",
3+
"version": "3.1.0",
44
"description": "React split-pane component with hooks and TypeScript",
55
"type": "module",
66
"main": "./dist/index.cjs",

src/components/SplitPane.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,45 @@ export function SplitPane(props: SplitPaneProps) {
297297
onResizeEnd,
298298
});
299299

300+
// Deprecated handlers for backwards compatibility
301+
// These delegate to the pointer handler so custom dividers using old props still work
302+
const createMouseDownHandler = useCallback(
303+
(index: number) => (e: React.MouseEvent) => {
304+
// Create a synthetic pointer event from the mouse event
305+
const pointerEvent = {
306+
...e,
307+
pointerId: 1,
308+
pointerType: 'mouse',
309+
nativeEvent: e.nativeEvent,
310+
} as unknown as React.PointerEvent;
311+
handlePointerDown(index)(pointerEvent);
312+
},
313+
[handlePointerDown]
314+
);
315+
316+
const createTouchStartHandler = useCallback(
317+
(index: number) => (e: React.TouchEvent) => {
318+
const touch = e.touches[0];
319+
if (!touch) return;
320+
// Create a synthetic pointer event from the touch event
321+
const pointerEvent = {
322+
...e,
323+
clientX: touch.clientX,
324+
clientY: touch.clientY,
325+
pointerId: touch.identifier,
326+
pointerType: 'touch',
327+
nativeEvent: e.nativeEvent,
328+
} as unknown as React.PointerEvent;
329+
handlePointerDown(index)(pointerEvent);
330+
},
331+
[handlePointerDown]
332+
);
333+
334+
// Touch end is now a no-op since pointer events handle cleanup
335+
const handleTouchEnd = useCallback(() => {
336+
// No-op - pointer events handle the end of drag
337+
}, []);
338+
300339
// Container styles
301340
const containerStyle: CSSProperties = {
302341
display: 'flex',
@@ -349,6 +388,9 @@ export function SplitPane(props: SplitPaneProps) {
349388
isDragging={isDragging}
350389
disabled={!resizable}
351390
onPointerDown={handlePointerDown(index)}
391+
onMouseDown={createMouseDownHandler(index)}
392+
onTouchStart={createTouchStartHandler(index)}
393+
onTouchEnd={handleTouchEnd}
352394
onKeyDown={handleKeyDown(index)}
353395
className={dividerClassName}
354396
style={dividerStyle}

src/types/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ export interface DividerProps {
9696
/** Pointer down handler (handles mouse, touch, and pen input) */
9797
onPointerDown: (e: React.PointerEvent) => void;
9898

99+
/**
100+
* Mouse down handler
101+
* @deprecated Use onPointerDown instead. This is provided for backwards compatibility.
102+
*/
103+
onMouseDown?: (e: React.MouseEvent) => void;
104+
105+
/**
106+
* Touch start handler
107+
* @deprecated Use onPointerDown instead. This is provided for backwards compatibility.
108+
*/
109+
onTouchStart?: (e: React.TouchEvent) => void;
110+
111+
/**
112+
* Touch end handler
113+
* @deprecated Use onPointerDown instead. This is provided for backwards compatibility.
114+
*/
115+
onTouchEnd?: (e: React.TouchEvent) => void;
116+
99117
/** Keyboard handler */
100118
onKeyDown: (e: React.KeyboardEvent) => void;
101119

0 commit comments

Comments
 (0)