fix: boards scrolling with wheel
This commit is contained in:
@ -6,6 +6,7 @@ import Board from "@/app/deals/components/shared/Board/Board";
|
|||||||
import CreateBoardButton from "@/app/deals/components/shared/CreateBoardButton/CreateBoardButton";
|
import CreateBoardButton from "@/app/deals/components/shared/CreateBoardButton/CreateBoardButton";
|
||||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||||
import SortableDnd from "@/components/dnd/SortableDnd";
|
import SortableDnd from "@/components/dnd/SortableDnd";
|
||||||
|
import useHorizontalWheel from "@/hooks/utils/useHorizontalWheel";
|
||||||
import useIsMobile from "@/hooks/utils/useIsMobile";
|
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||||
import { BoardSchema } from "@/lib/client";
|
import { BoardSchema } from "@/lib/client";
|
||||||
import styles from "./Boards.module.css";
|
import styles from "./Boards.module.css";
|
||||||
@ -13,6 +14,7 @@ import styles from "./Boards.module.css";
|
|||||||
const Boards = () => {
|
const Boards = () => {
|
||||||
const { boards, setSelectedBoardId, boardsCrud } = useBoardsContext();
|
const { boards, setSelectedBoardId, boardsCrud } = useBoardsContext();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
const { ref, onWheel } = useHorizontalWheel<HTMLDivElement>();
|
||||||
|
|
||||||
const renderBoard = (board: BoardSchema) => <Board board={board} />;
|
const renderBoard = (board: BoardSchema) => <Board board={board} />;
|
||||||
|
|
||||||
@ -29,6 +31,8 @@ const Boards = () => {
|
|||||||
align={"end"}
|
align={"end"}
|
||||||
className={styles.container}>
|
className={styles.container}>
|
||||||
<ScrollArea
|
<ScrollArea
|
||||||
|
viewportRef={ref}
|
||||||
|
onWheel={onWheel}
|
||||||
offsetScrollbars={"x"}
|
offsetScrollbars={"x"}
|
||||||
scrollbars={"x"}
|
scrollbars={"x"}
|
||||||
scrollbarSize={0}>
|
scrollbarSize={0}>
|
||||||
|
|||||||
18
src/hooks/utils/useHorizontalWheel.ts
Normal file
18
src/hooks/utils/useHorizontalWheel.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { useCallback, useRef, WheelEvent } from "react";
|
||||||
|
|
||||||
|
function useHorizontalWheel<T extends HTMLElement>() {
|
||||||
|
const ref = useRef<T | null>(null);
|
||||||
|
const onWheel = useCallback((e: WheelEvent<T>) => {
|
||||||
|
if (!ref.current) return;
|
||||||
|
|
||||||
|
e.stopPropagation();
|
||||||
|
if (e.deltaY < 0) {
|
||||||
|
ref.current.scrollLeft -= Math.max(e.deltaY, -40);
|
||||||
|
} else {
|
||||||
|
ref.current.scrollLeft -= Math.min(e.deltaY, 40);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
return { ref, onWheel };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useHorizontalWheel;
|
||||||
Reference in New Issue
Block a user