Description of the problem
The current OrbitControls get keydown events from window
which has issue if there are any text input elements.
Steps to repo
- https://jsfiddle.net/greggman/xz73t9gc/
- click in text area
- type stuff and press left right arrow gets text area
Notice OrbitControls are responding to arrow keys
It seems like the solution is 4 fold
-
Pass renderer.domElement into OrbitControls
-
Have OrbitControls put keydown on
scope.domElement
which is either document or the element passed in -
Set
scope.domElement.tabIndex
>= 0. This could happen in OrbitControls or be left to the userThis lets the canvas get selected. Without this the canvas can never get keyboard input since it can never be the focus
-
Optional: set CSS
canvas:focus { outline: none; }
Doing steps all these steps allows it to work correctly
https://jsfiddle.net/greggman/gywcao3e/
In the code above the OrbitControls are pasted at the bottom. the window.addEventListener('keydown', ...)
has been changed do scope.domElement.addEventListener('keydown', ...)
and if scope.domElement
is not the body then if its tabIndex
is < 0 it’s set to 0.
This seems to fix the issue and still seems to work as it used to if no element is passed in
Three.js version
- Dev
Browser
- All of them
OS
- All of them
I agree this is a pain in the neck. How about:
It’s janky, anyway. Does anybody use the keys for panning?