Skip to content

Commit

Permalink
feat(OrbitControls): keyEvents prop (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed May 26, 2023
1 parent eefb21f commit c959e0d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/core/OrbitControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ export type OrbitControlsProps = Omit<
onStart?: (e?: Event) => void
regress?: boolean
target?: ReactThreeFiber.Vector3
keyEvents?: boolean | HTMLElement
}
>,
'ref'
>

export const OrbitControls = React.forwardRef<OrbitControlsImpl, OrbitControlsProps>(
({ makeDefault, camera, regress, domElement, enableDamping = true, onChange, onStart, onEnd, ...restProps }, ref) => {
(
{
makeDefault,
camera,
regress,
domElement,
enableDamping = true,
keyEvents = false,
onChange,
onStart,
onEnd,
...restProps
},
ref
) => {
const invalidate = useThree((state) => state.invalidate)
const defaultCamera = useThree((state) => state.camera)
const gl = useThree((state) => state.gl)
Expand All @@ -44,9 +59,13 @@ export const OrbitControls = React.forwardRef<OrbitControlsImpl, OrbitControlsPr
}, -1)

React.useEffect(() => {
if (keyEvents) {
controls.connect(keyEvents === true ? explDomElement : keyEvents)
}

controls.connect(explDomElement)
return () => void controls.dispose()
}, [explDomElement, regress, controls, invalidate])
}, [keyEvents, explDomElement, regress, controls, invalidate])

React.useEffect(() => {
const callback = (e: OrbitControlsChangeEvent) => {
Expand Down

1 comment on commit c959e0d

@vercel
Copy link

@vercel vercel bot commented on c959e0d May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.