2021-04-09 12:29:59 +02:00
|
|
|
import { useEffect } from '../lib/teact/teact';
|
|
|
|
|
2021-06-15 12:21:30 +02:00
|
|
|
export default (container: HTMLElement | null, isDisabled?: boolean) => {
|
2021-04-09 12:29:59 +02:00
|
|
|
useEffect(() => {
|
|
|
|
if (!container) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleScroll(e: WheelEvent) {
|
|
|
|
// Ignore horizontal scroll and let it work natively (e.g. on touchpad)
|
|
|
|
if (!e.deltaX) {
|
|
|
|
container!.scrollLeft += e.deltaY / 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
container.addEventListener('wheel', handleScroll, { passive: true });
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
container.removeEventListener('wheel', handleScroll);
|
|
|
|
};
|
2021-06-15 12:21:30 +02:00
|
|
|
}, [container, isDisabled]);
|
2021-04-09 12:29:59 +02:00
|
|
|
};
|