Skip to content

Commit

Permalink
use canClick in click function because a11y doesn't care about Pointe…
Browse files Browse the repository at this point in the history
…rs, see #831
  • Loading branch information
jessegreenberg committed Aug 24, 2018
1 parent c4db20e commit 10b8b17
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions js/listeners/PressListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ define( function( require ) {
* @returns {boolean}
*/
canPress: function( event ) {
// If this listener is already involved in pressing something, we can't press something
if ( this.isPressed ) {

// canClick is a subset of canPress, start by checking a11y state that doesn't involve pointers
if ( !this.canClick() ) {
return false;
}

Expand All @@ -385,6 +386,20 @@ define( function( require ) {
return false;
}

return true;
},

/**
* Returns whether this PressListener can be clicked from keyboard input.
* @return {boolean}
*/
canClick: function() {

// If this listener is already involved in pressing something, we can't press something
if ( this.isPressed ) {
return false;
}

// Check whether our options prevent us from starting a press right now.
if ( !this._canStartPress() ) {
return false;
Expand All @@ -393,6 +408,7 @@ define( function( require ) {
return true;
},


/**
* Moves the listener to the 'pressed' state if possible (attaches listeners and initializes press-related
* properties).
Expand Down Expand Up @@ -564,8 +580,8 @@ define( function( require ) {
* @private
* @a11y
*/
click: function() {
if ( this.canPress() ) {
click: function( event ) {
if ( this.canClick() ) {

// ensure that button is 'over' so listener can be called while button is down
this.isOverProperty.set( true );
Expand Down

0 comments on commit 10b8b17

Please sign in to comment.