Skip to content

Commit

Permalink
fix: pointer events offset for ScrollControls
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Oct 29, 2021
1 parent 64fb3f7 commit 1766ed2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 8 additions & 9 deletions .storybook/stories/ScrollControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const Container = ({ children }) => (
paddingLeft: '100px',
paddingRight: '100px',
paddingBottom: '100px',
height: '100%',
height: 'calc(100vh - 200px)',
}}
>
{children}
Expand All @@ -136,12 +136,11 @@ export const DefaultStory = () => (
DefaultStory.decorators = [(storyFn) => <ScrollControlsSetup>{storyFn()}</ScrollControlsSetup>]
DefaultStory.storyName = 'Default'

export const InsideContainerStory = () => <DefaultStory />
InsideContainerStory.decorators = [
(storyFn) => (
<Container>
<ScrollControlsSetup>{storyFn()}</ScrollControlsSetup>
</Container>
),
]
export const InsideContainerStory = () => (
<Container>
<ScrollControlsSetup>
<DefaultStory />
</ScrollControlsSetup>
</Container>
)
InsideContainerStory.storyName = 'Inside a container'
5 changes: 4 additions & 1 deletion src/web/ScrollControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export function ScrollControls({
const oldTarget = events.connected
requestAnimationFrame(() => events.connect?.(el))
const oldCompute = raycaster.computeOffsets
raycaster.computeOffsets = ({ clientX, clientY }) => ({ offsetX: clientX, offsetY: clientY })
raycaster.computeOffsets = ({ clientX, clientY }) => ({
offsetX: clientX - (target as HTMLElement).offsetLeft,
offsetY: clientY - (target as HTMLElement).offsetTop,
})

return () => {
target.removeChild(el)
Expand Down

0 comments on commit 1766ed2

Please sign in to comment.