Skip to content

Commit

Permalink
Update usages of KeyboardListener and KeyboardDragListener after chan…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Apr 25, 2024
1 parent b29f9eb commit deca9ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
14 changes: 7 additions & 7 deletions js/AquaRadioButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import StrictOmit from '../../phet-core/js/types/StrictOmit.js';
import optionize, { combineOptions } from '../../phet-core/js/optionize.js';
import { FlowBox, FlowBoxOptions, KeyboardListener, PDOMPeer, SceneryConstants } from '../../scenery/js/imports.js';
import { FlowBox, FlowBoxOptions, KeyboardUtils, PDOMPeer, SceneryConstants, SceneryEvent } from '../../scenery/js/imports.js';
import multiSelectionSoundPlayerFactory from '../../tambo/js/multiSelectionSoundPlayerFactory.js';
import Tandem from '../../tandem/js/Tandem.js';
import AquaRadioButton, { AquaRadioButtonOptions } from './AquaRadioButton.js';
Expand Down Expand Up @@ -137,12 +137,13 @@ export default class AquaRadioButtonGroup<T> extends FlowBox {

// zoom - signify that key input is reserved and we should not pan when user presses arrow keys
// See https://github.com/phetsims/scenery/issues/974
const intentListener = new KeyboardListener( {
keys: [ 'arrowLeft', 'arrowRight', 'arrowUp', 'arrowDown' ],
callback: event => {
event && event.pointer.reserveForKeyboardDrag();
const intentListener = {
keydown: ( event: SceneryEvent<KeyboardEvent> ) => {
if ( KeyboardUtils.isArrowKey( event.domEvent ) ) {
event.pointer.reserveForKeyboardDrag();
}
}
} );
};
this.addInputListener( intentListener );

const boundOnRadioButtonInput = this.onRadioButtonInput.bind( this );
Expand All @@ -158,7 +159,6 @@ export default class AquaRadioButtonGroup<T> extends FlowBox {

this.disposeAquaRadioButtonGroup = () => {
this.removeInputListener( intentListener );
intentListener.dispose();
radioButtons.forEach( radioButton => radioButton.dispose() );
this.onInputEmitter.dispose();
nodes.forEach( node => node.dispose() );
Expand Down
11 changes: 2 additions & 9 deletions js/ComboBoxListBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export default class ComboBoxListBox<T> extends Panel {
// pdom - listener that navigates listbox items and closes the box from keyboard input
const keyboardListener = new KeyboardListener( {
keys: [ 'escape', 'tab', 'shift+tab', 'arrowUp', 'arrowDown', 'home', 'end' ],
callback: ( event, keysPressed ) => {
fire: ( event, keysPressed ) => {
const sceneryEvent = event!;
assert && assert( sceneryEvent, 'event is required for this listener' );

Expand All @@ -274,16 +274,12 @@ export default class ComboBoxListBox<T> extends Panel {

if ( keysPressed === 'escape' || keysPressed === 'tab' || keysPressed === 'shift+tab' ) {

// This keyboard event is captured so that escape doesn't forward to other popupable components. If
// ComboBox is ever implemented with generalized popupable/pane system this abort will not be necessary.
sceneryEvent.abort();

// Escape and Tab hide the list box and return focus to the button
hideListBoxCallback();
focusButtonCallback();
}
else if ( keysPressed === 'arrowUp' || keysPressed === 'arrowDown' ) {
const domEvent = sceneryEvent.domEvent!;
const domEvent = event!;
assert && assert( domEvent, 'domEvent is required for this listener' );

// prevent "native" behavior so that Safari doesn't make an error sound with arrow keys in
Expand All @@ -297,9 +293,6 @@ export default class ComboBoxListBox<T> extends Panel {

const nextIndex = focusedItemIndex + direction;
visibleItemNodes[ nextIndex ] && visibleItemNodes[ nextIndex ].focus();

// reserve for drag after focus has moved, as the change in focus will clear the intent on the pointer
sceneryEvent.pointer.reserveForKeyboardDrag();
}
else if ( keysPressed === 'home' ) {
visibleItemNodes[ 0 ].focus();
Expand Down
6 changes: 3 additions & 3 deletions js/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ export default class Dialog extends Popupable( Panel, 1 ) {
// pdom - close the dialog when pressing "escape"
const keyboardListener = new KeyboardListener( {
keys: [ 'escape', 'tab', 'shift+tab' ],
callback: ( event, keysPressed ) => {
assert && assert( event && event.domEvent, 'event should be non-null and defined for this listener' );
const domEvent = event!.domEvent!;
fire: ( event, keysPressed ) => {
assert && assert( event, 'event should be non-null and defined for this listener' );
const domEvent = event!;

if ( keysPressed === 'escape' ) {
domEvent.preventDefault();
Expand Down

0 comments on commit deca9ae

Please sign in to comment.