Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const BaseCanvasInnerComponent = <NodeType extends Node = Node, EdgeType extends
zoomOnDoubleClick = true,
snapToGrid = BASE_CANVAS_DEFAULTS.snapToGrid,
snapGrid = BASE_CANVAS_DEFAULTS.snapGrid,
preventScrolling = false,

// Layout
initialAutoLayout,
Expand All @@ -91,6 +92,9 @@ const BaseCanvasInnerComponent = <NodeType extends Node = Node, EdgeType extends
onToolbarAction,
breakpoints,

// Navigation
enableBackNavigationPrevention = true,

// Pan Shortcut Teaching UI
panShortcutTeachingUIMessage = 'Hold Space and drag to pan around the canvas!',

Expand All @@ -109,7 +113,8 @@ const BaseCanvasInnerComponent = <NodeType extends Node = Node, EdgeType extends
const { ensureNodesInView, ensureAllNodesInView, centerNode } = useEnsureNodesInView();

// Prevent browser back navigation on touch gestures
usePreventBackNavigation();
const preventBackNavigationEnabled = preventScrolling === false && enableBackNavigationPrevention;
usePreventBackNavigation(preventBackNavigationEnabled);

// Maintain specified nodes in view when canvas resizes
// This ensures important nodes remain visible in responsive layouts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ export interface BaseCanvasProps<NodeType extends Node = Node, EdgeType extends
* @default undefined
*/
isDarkMode?: boolean;

/**
* Whether to prevent browser back navigation on touch gestures and horizontal wheel scrolling.
* Disable this when the canvas is embedded in a scrollable page where horizontal scroll should work normally.
* @default true
*/
enableBackNavigationPrevention?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { useEffect } from 'react';
* Custom hook to prevent browser back navigation on touch gestures and horizontal wheel scrolling.
* This is useful for canvas/flow components where accidental navigation can interrupt user work.
*/
export function usePreventBackNavigation() {
export function usePreventBackNavigation(enabled = true) {
useEffect(() => {
if (!enabled) return;
const preventBackNavigation = (e: TouchEvent) => {
if (e.touches.length === 2) {
e.preventDefault();
Expand All @@ -28,5 +29,5 @@ export function usePreventBackNavigation() {
document.removeEventListener('touchmove', preventBackNavigation);
document.removeEventListener('wheel', preventWheel);
};
}, []);
}, [enabled]);
}
Loading