Skip to content

Commit

Permalink
add focusChangedEmitter, phetsims/scenery-phet#341
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 24, 2017
1 parent a4ddbaf commit fbd9a93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions js/accessibility/Accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ define( function( require ) {
// @public (scenery-internal) - emitters for when state properties change
this.accessibleVisibilityChangedEmitter = new Emitter();

// @public - emits when focus changes. This will trigger with the 'focus' event and the 'blur' event.
// Listener receives 1 parameter, {boolean} - isFocused. see Display.focus
this.focusChangedEmitter = new Emitter();

// @private {Array.<Node>} - (a11y) If provided, it will override the focus order between children (and optionally
// descendants). If not provided, the focus order will default to the rendering order (first children first, last
// children last) determined by the children array.
Expand Down
9 changes: 8 additions & 1 deletion js/display/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ define( function( require ) {
* Called when an ancestor node's accessible order is changed. First we check to see if the leaf most node on
* the trail has an AccessibleInstance. If if does, we sort the accessible instances under it. Otherwise, find
* the closest ancestor that has an AccessibleInstance, and sort AccessibleInstances under that one.
*
*
* @private
*
* @param {Trail} trail
Expand Down Expand Up @@ -1819,7 +1819,14 @@ define( function( require ) {
* @param {Focus|null} value
*/
set focus( value ) {

// Emit that the old focused node is no longer focused
this.focusProperty.value && this.focusProperty.value.trail.lastNode().focusChangedEmitter.emit1( false );

this.focusProperty.value = value;

// Emit that the new node is focused
value && value.trail.lastNode().focusChangedEmitter.emit1( true );
},

/**
Expand Down

0 comments on commit fbd9a93

Please sign in to comment.