Skip to content

Commit bc0c566

Browse files
authored
Merge pull request #15620 from greggman/orbitcontrols-focus-iframe-issue
Fix for OrbitControls not allowing keyboard input in iframe
2 parents 2451173 + 9be5d8a commit bc0c566

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

examples/js/controls/OrbitControls.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ THREE.OrbitControls = function ( object, domElement ) {
539539

540540
//console.log( 'handleKeyDown' );
541541

542+
// prevent the browser from scrolling on cursor up/down
543+
544+
event.preventDefault();
545+
542546
switch ( event.keyCode ) {
543547

544548
case scope.keys.UP:
@@ -673,8 +677,15 @@ THREE.OrbitControls = function ( object, domElement ) {
673677

674678
if ( scope.enabled === false ) return;
675679

680+
// Prevent the browser from scrolling.
681+
676682
event.preventDefault();
677683

684+
// Manually set the focus since calling preventDefault above
685+
// prevents the browser from setting it automatically.
686+
687+
scope.domElement.focus ? scope.domElement.focus() : window.focus();
688+
678689
switch ( event.button ) {
679690

680691
case scope.mouseButtons.LEFT:

0 commit comments

Comments
 (0)