Skip to content

Commit

Permalink
prevent fake pointer like events from PDOM root, see phetsims/a11y-re…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Mar 29, 2019
1 parent b73643c commit 9339a9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
15 changes: 0 additions & 15 deletions js/accessibility/AccessiblePeer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ define( function( require ) {
var LABEL_TAG = AccessibilityUtil.TAGS.LABEL;
var INPUT_TAG = AccessibilityUtil.TAGS.INPUT;

// On certain screen readers, the assistive device may send "fake" pointer events to the browser when only using
// a keyboard. We want to handle these as keyboard or alternative events exclusively and not through scenery's
// pointer system. See https://github.com/phetsims/scenery/issues/852#issuecomment-467994327
var BLOCKED_EVENTS = [ 'touchstart', 'touchend', 'mousedown', 'mouseup' ];

// DOM observers that apply new CSS transformations are triggered when children, or inner content change. Updating
// style/positioning of the element will change attributes so we can't observe those changes since it would trigger
// the MutationObserver infinitely.
Expand Down Expand Up @@ -199,16 +194,6 @@ define( function( require ) {
trailId: uniqueId
} );

// Block any fake pointer events that will be sourced on the primary sibling when a screen reader is in use.
// Screen readers inconsistently send these events and we want all pointer events to go through
// scenery's pointer input system and the display div, never the PDOM
for ( var i = 0; i < BLOCKED_EVENTS.length; i++ ) {
this._primarySibling.addEventListener( BLOCKED_EVENTS[ i ], function( event ) {
event.preventDefault();
event.stopPropagation();
} );
}

// create the container parent for the dom siblings
if ( options.containerTagName ) {
this._containerParent = AccessibilityUtil.createElement( options.containerTagName, false, {
Expand Down
15 changes: 15 additions & 0 deletions js/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ define( require => {

const TARGET_SUBSTITUTE_KEY = 'targetSubstitute';

// Some assistive devices may send "fake" pointer like events to the browser when only using
// a keyboard. We want to handle these as keyboard or alternative events exclusively and not through scenery's
// pointer system. See https://github.com/phetsims/scenery/issues/852#issuecomment-467994327
var BLOCKED_ACCESSIBLE_EVENTS = [ 'touchstart', 'touchend', 'mousedown', 'mouseup' ];

/**
* An input controller for a specific Display.
* @constructor
Expand Down Expand Up @@ -768,6 +773,16 @@ define( require => {
}, accessibleEventOptions );
} );

// Block any fake pointer events that may be sourced on the a PDOM element when a screen reader is in use.
// Screen readers inconsistently send these fake "pointer" like events to DOM elements and we want
// all pointer events to go through scenery's pointer input system and the display div, never the PDOM
for ( var i = 0; i < BLOCKED_ACCESSIBLE_EVENTS.length; i++ ) {
this.display.accessibleDOMElement.addEventListener( BLOCKED_ACCESSIBLE_EVENTS[ i ], function( event ) {
event.preventDefault();
event.stopPropagation();
} );
}

// Add a listener to the document body that will capture any keydown for a11y before focus is in this display.
document.body.addEventListener( 'keydown', this.handleDocumentKeydown.bind( this ) );
}
Expand Down

0 comments on commit 9339a9c

Please sign in to comment.