Skip to content
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

Tabview Scrollable. Add mousewheel interaction for horizontal scroll #2480

Closed
hartum opened this issue Nov 30, 2021 · 3 comments
Closed

Tabview Scrollable. Add mousewheel interaction for horizontal scroll #2480

hartum opened this issue Nov 30, 2021 · 3 comments
Labels
Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team

Comments

@hartum
Copy link

hartum commented Nov 30, 2021

I'm submitting a ...

[ ] bug report
[X] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

I was looking at tabview Scrollable, and looks fantastic.
Just playing with it horizontal scroll, Mac mouse works really great,
but nothing happens in other OS (ubuntu, windows 10) when I try to use central mousewheel.

It would be great if component captured the mouse wheel event to scroll horizontally when the pointer is over the tabView.

Is it possible to implement this functionality?

Thanks a lot in advance and best regards.

@melloware
Copy link
Member

I am able to handle the mousewheel on the tabs no problem. The issue I am having is stopping the mousewheel from scrolling the outer window as its a bad experience.

@melloware
Copy link
Member

melloware commented Nov 30, 2021

Ughhh its a React problem at its core with onwheel events: facebook/react#14856

This workaround seems to be the only thing that works...

That being said, it's the only solution that worked for me, so I have encapsulated it in a hook:

function useWheelHack(timeout = 300) {
  const wheelTimeout = useRef()

  // block the body from scrolling while wheelTimeout is set
  useEffect(() => {
    const maybeCancelWheel = (e) => wheelTimeout.current && e.preventDefault()
    document.body.addEventListener('wheel', maybeCancelWheel, { passive: false })
    return () => document.body.removeEventListener('wheel', maybeCancelWheel)
  }, [])

  // return a function that can be used to prevent scrolling for timeout ms
  return () => {
    clearTimeout(wheelTimeout.current)
    wheelTimeout.current = setTimeout(() => {
      wheelTimeout.current = false
    }, timeout)
  }
}

Usage:

const preventWheelDefault = useWheelHack()

return (
  <someElement
    onWheel={(event) => {
      preventWheelDefault()
      // do other stuff here...
    }}
  />
)

@hartum
Copy link
Author

hartum commented Dec 1, 2021

I have to say I am impressed, super fast response and solution (hack included).

@melloware you are my hero.

Thanks a lot.

@yigitfindikli yigitfindikli added the Type: New Feature Issue contains a new feature or new component request label Mar 21, 2022
@melloware melloware added the Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team label Apr 21, 2022
@melloware melloware added Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior and removed Type: New Feature Issue contains a new feature or new component request labels Nov 17, 2022
@melloware melloware closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants