Add swipe-to-open sidebar on first tab

When swiping right on the first tab, opens the mobile sidebar menu.
Added onSwipePastStart prop to SwipeTabs component.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-23 02:33:31 +01:00
parent 18c4760b5d
commit be5d6141f4
5 changed files with 18 additions and 68 deletions

View File

@@ -22,6 +22,7 @@ type SwipeTabsProps<T extends string | number> = {
threshold?: number;
renderWindow?: number;
scrollToTopOnChange?: boolean;
onSwipePastStart?: () => void;
};
const DRAG_START_DISTANCE = 3;
@@ -57,7 +58,8 @@ export function SwipeTabs<T extends string | number>({
swipeDisabled = false,
threshold = DEFAULT_THRESHOLD,
renderWindow = DEFAULT_RENDER_WINDOW,
scrollToTopOnChange = true
scrollToTopOnChange = true,
onSwipePastStart
}: SwipeTabsProps<T>) {
const containerRef = useRef<HTMLDivElement>(null);
const trackRef = useRef<HTMLDivElement>(null);
@@ -336,6 +338,11 @@ export function SwipeTabs<T extends string | number>({
if (!cancelled && Math.abs(dx) > thresholdPx) {
const direction = dx < 0 ? 1 : -1;
targetIndex = Math.min(Math.max(state.startIndex + direction, 0), tabs.length - 1);
// If swiping right on first tab, call onSwipePastStart
if (state.startIndex === 0 && dx > 0 && onSwipePastStart) {
onSwipePastStart();
}
}
dragOffsetRef.current = 0;
@@ -354,7 +361,7 @@ export function SwipeTabs<T extends string | number>({
}
}
},
[activeTab, applyTransform, onTabChange, setDraggingClass, tabs, threshold]
[activeTab, applyTransform, onTabChange, onSwipePastStart, setDraggingClass, tabs, threshold]
);
const handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {