lil-gui icon indicating copy to clipboard operation
lil-gui copied to clipboard

captureKeys flag

Open georgealways opened this issue 9 months ago • 0 comments

Adds a captureKeys flag to GUI's constructor, which is true by default. If this is false, GUI will not call stopPropagation() on key events that originate from within the GUI. The user must then manage event propagation manually using something like the following:

const gui = new GUI( { captureKeys: false } );

window.addEventListener( 'keydown', e => { 
  if ( gui.domElement.contains( e.target ) ) {
    // I'm typing in the GUI.
  } else if ( e.code === 'Space' ) {
    jump();
  }
});

[!WARNING]
As of this change, folder titles will capture key events by default. This is different than 0.19.2.

The reason for this change is to have uniform behavior between Controllers and folder titles: they both respect captureKeys the same way. Of course, you can disable this behavior with { captureKeys: false }, but then you must manage all events yourself as shown above.

For tests: expanded the browser shim to simulate event propagation.

georgealways avatar May 25 '24 15:05 georgealways