-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: Waves Component Not Registering Mouse Clicks after being added as a section #129
Comments
Hi @zanjeel While I wasn't able to reproduce your exact problem, I did notice the component's mouse responsiveness would rapidly deteriorate every time it was re-rendered on the page, until a certain point when it wouldn't work at all. This means one thing: Why this was happening The fix Hopefully, with these changes, if my guess was right, you'll be able to see the mouse interaction even with components that re-render the Waves component a bunch of times, but if it still doesn't work, to me it indicates a deeper problem in your application that you should consider fixing. |
Hi @DavidHDev I just fixed the issue in Waves component used in ReactBits which was causing the issue, and it WORKSSS!! 👯 :D 💃 The waves would stop responding to mouse movement after the first few interactions. This was happening because of incorrect mouse position calculations that didn't properly account for scroll position and container bounds. How can I give the full code to you? I want to contribute to the Waves.jsx with Tailwind (as I never contributed to an open source Github repo lol-first time woo) Below is what I did shortly: a) First Change: Updated the mouse position calculation to use getBoundingClientRect() "const rect = containerRef.current.getBoundingClientRect(); instead of: "mouse.x = x - b.left; b) Second Change: Added proper scroll handling: "const scrollX = window.pageXOffset || document.documentElement.scrollLeft; This worked bcs: -> getBoundingClientRect() provides live, accurate coordinates of the container relative to the viewport and accounts for both horizontal and vertical scroll positions -> The mouse coordinates are now always calculated relative to the container's current position, not its initial position. The calculation remains accurate even when the page is scrolled or the container's position changes. Previous Issues: This fix ensures that the waves component always knows the exact position of the mouse relative to its container, making the interaction smooth and consistent throughout the entire user session, regardless of scrolling or container position changes. Do let me know how I can contribute. Thanks! |
(attached a video of the correct implementation now, error was with registering the mouse movement in React Waves component.) @DavidHDev recording-waves.mp4 |
@zanjeel Awesome, glad you figured it out, if you want to contribute with this, you'd have to fork and run the project locally, update all 4 versions of the component so that they are in sync with this change, and then check that the demo page is error-free and without any surprises. Then you'd just open a PR to merge your changes into the |
@DavidHDev Sure, will do soon! |
Will be closing this issue @zanjeel , but feel free to open that PR whenever you want! |
Describe the issue
Hi, https://www.reactbits.dev/backgrounds/waves work perfectly as a single component but don't move on user mouse hover or drag after they are added as a separate component. I have tried rendering it only and it works and registers mouse movement.
But as soon as I add my Hero section, it does'nt work. I tried changing ZIndex and relative/absolute positioning but didn't work.
Reproduction Link
No response
Steps to reproduce
You could try importing other ready made components taking up space like Hero/Contact sections and rendering Wave component below them, do tell me if it registers the mouse movement. Thanks!
Validations
The text was updated successfully, but these errors were encountered: