@@ -48,6 +48,7 @@ interface GraphProps {
48
48
49
49
export function Graph ( props : GraphProps ) {
50
50
const containerRef = useRef < HTMLDivElement > ( null ) ;
51
+ const graphContainerRef = useRef < HTMLDivElement > ( null ) ;
51
52
const [ scale , setScale ] = useState ( 1 ) ;
52
53
const [ position , setPosition ] = useState ( { x : 0 , y : 0 } ) ;
53
54
const [ isDragging , setIsDragging ] = useState ( false ) ;
@@ -207,12 +208,24 @@ export function Graph(props: GraphProps) {
207
208
highlightSelectedNode ( ) ;
208
209
} , [ highlightSelectedNode ] ) ;
209
210
210
- const handleWheel = useCallback ( ( e : React . WheelEvent ) => {
211
+ const handleWheel = useCallback ( ( e : WheelEvent ) => {
211
212
e . preventDefault ( ) ;
212
213
const delta = e . deltaY > 0 ? 0.9 : 1.1 ;
213
214
setScale ( ( prev ) => Math . max ( 0.1 , Math . min ( 3 , prev * delta ) ) ) ;
214
215
} , [ ] ) ;
215
216
217
+ // Add wheel event listener with ref
218
+ useEffect ( ( ) => {
219
+ const element = graphContainerRef . current ;
220
+ if ( ! element ) return ;
221
+
222
+ element . addEventListener ( "wheel" , handleWheel , { passive : false } ) ;
223
+
224
+ return ( ) => {
225
+ element . removeEventListener ( "wheel" , handleWheel ) ;
226
+ } ;
227
+ } , [ handleWheel ] ) ;
228
+
216
229
const handleMouseDown = useCallback (
217
230
( e : React . MouseEvent ) => {
218
231
if ( e . button === 0 ) {
@@ -273,8 +286,8 @@ export function Graph(props: GraphProps) {
273
286
274
287
{ /* Graph Container */ }
275
288
< div
289
+ ref = { graphContainerRef }
276
290
className = { `w-full h-full cursor-grab active:cursor-grabbing ${ props . selectedNodeId ? "pr-80" : "" } ` }
277
- onWheel = { handleWheel }
278
291
onMouseDown = { handleMouseDown }
279
292
onMouseMove = { handleMouseMove }
280
293
onMouseUp = { handleMouseUp }
0 commit comments