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

fix: pointer events offset for ScrollControls #601

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: pointer events offset for ScrollControls
  • Loading branch information
Glavin001 committed Oct 29, 2021
commit 1766ed26198442cb8051b914067d6558821bb9bb
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