-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should addAccessibleInputListener automatically preventDefault? #636
Comments
I am afraid that preventing default in addAccessibleInputListener would be too aggressive. For instance, calling |
Maybe we can factor out common interactions that will require us to prevent default. Like // on delete or backspace, the focused circuit element should be deleted
if ( code === Input.KEY_DELETE || code === Input.KEY_BACKSPACE ) {
// prevent default so 'backspace' and 'delete' don't navigate back a page in Firefox
event.preventDefault();
circuit.circuitElements.remove( circuitElement );
} Perhaps the API could look like var myKeyboardDeleteHandler = new KeyboardDeleteHandler( {
onDelete: function( event ) {
circuit.circuitElements.remove( circuitElement );
}
})
myNode.addAccessibleInputListener( myKeyboardDeleteHandler ) And the handler calls |
We could end up with a lot of these I am not sure how I feel about lots of these handlers. But at least the reasons for preventDefault would be isolated and documented in each one. |
Perhaps we should see (or anticipate) what patterns come up frequently. Perhaps an abstraction like: new KeyHandler([Input.KEY_DELETE,Input.KEY_BACKSPACE],{
preventDefault:true
},function(){ /*callback*/}); would work well? It's difficult to say whether this would be necessary or useful. |
Agreed, though an abstraction does seem useful. I found 44 usages of addAccessibleInputListener, and inspection showed about 1/4 use |
I spoke with @jessegreenberg about this today. We believe that preventDefault should still be called in the exact locations that it is needed, and not eagerly. I believe this could be handled by better encapsulation of keyboard input handlers that may be worked on in #1445. Like from #636 (comment) We are ready to close this issue. |
In phetsims/circuit-construction-kit-common#307 @jessegreenberg added
preventDefault
calls to prevent e.g., firefox from navigating pages back. Should this be automatically implemented in addAccessibleInputListener so we don't end up scattering preventDefault everywhere?The text was updated successfully, but these errors were encountered: