UNPKG

@gechiui/block-editor

Version:
46 lines (39 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePopoverScroll = usePopoverScroll; var _compose = require("@gechiui/compose"); /** * GeChiUI dependencies */ /** * Allow scrolling "through" popovers over the canvas. This is only called for * as long as the pointer is over a popover. Do not use React events because it * will bubble through portals. * * @param {Object} scrollableRef */ function usePopoverScroll(scrollableRef) { return (0, _compose.useRefEffect)(node => { if (!scrollableRef) { return; } function onWheel(event) { const { deltaX, deltaY } = event; scrollableRef.current.scrollBy(deltaX, deltaY); } // Tell the browser that we do not call event.preventDefault // See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners const options = { passive: true }; node.addEventListener('wheel', onWheel, options); return () => { node.removeEventListener('wheel', onWheel, options); }; }, [scrollableRef]); } //# sourceMappingURL=use-popover-scroll.js.map