diff --git a/js/accessibility/AccessibleInstance.js b/js/accessibility/AccessibleInstance.js index bd7315eed..5bdbe51fc 100644 --- a/js/accessibility/AccessibleInstance.js +++ b/js/accessibility/AccessibleInstance.js @@ -392,7 +392,7 @@ define( function( require ) { if ( this.parent ) { return this.parent.isGloballyVisible(); } - else { + else { // base case at root return true; } }, diff --git a/js/accessibility/AccessiblePeer.js b/js/accessibility/AccessiblePeer.js index 056557cf7..8939f7de1 100644 --- a/js/accessibility/AccessiblePeer.js +++ b/js/accessibility/AccessiblePeer.js @@ -77,6 +77,10 @@ define( function( require ) { // @public {Trail} - NOTE: May have "gaps" due to accessibleOrder usage. this.trail = accessibleInstance.trail; + // @private {boolean|null} - whether or not this AccessiblePeer is visible in the PDOM + // Only initialized to null, should not be set to it. isVisible() will return true if this.visible is null (because it hasn't been set yet). + this.visible = null; + // @public {HTMLElement} - The main element associated with this peer. If focusable, this is the element that gets // the focus. It also will contain any children. this.primarySibling = primarySibling; @@ -327,34 +331,40 @@ define( function( require ) { * @returns {boolean} */ isVisible: function() { + if ( assert ) { - // TODO: assert if some visible and some are not - - var visibleElements = 0; - this.topLevelElements.forEach( function( element ) { - if ( !element.hidden ) { - visibleElements += 1; - } - } ); + var visibleElements = 0; + this.topLevelElements.forEach( function( element ) { + if ( !element.hidden ) { + visibleElements += 1; + } + } ); + assert( visibleElements === this.visible ? 0 : this.topLevelElements.length, + 'some of the peer\'s elements are visible and some are not' ); - return visibleElements === this.topLevelElements.length; + } + return this.visible === null ? true: this.visible; // default to true if visibility hasn't been set yet. }, /** - * + * Set whether or not the peer is visible in the PDOM * @param {boolean} visible */ setVisible: function( visible ) { - - this.topLevelElements.forEach( function( element ) { - - if ( visible ) { - element.removeAttribute( 'hidden' ); + assert && assert( typeof visible === 'boolean' ); + if ( this.visible !== visible ) { + + this.visible = visible; + for ( var i = 0; i < this.topLevelElements.length; i++ ) { + var element = this.topLevelElements[ i ]; + if ( visible ) { + element.removeAttribute( 'hidden' ); + } + else { + element.setAttribute( 'hidden', '' ); + } } - else { - element.setAttribute( 'hidden', '' ); - } - } ); + } }, /** diff --git a/js/accessibility/FocusTests.js b/js/accessibility/FocusTests.js index 65fbbc142..f73e4d6ff 100644 --- a/js/accessibility/FocusTests.js +++ b/js/accessibility/FocusTests.js @@ -274,7 +274,6 @@ define( function( require ) { // reverse accessible order rootNode.accessibleOrder = [ d, c, b, a ]; - // debugger; var divRoot = display._rootAccessibleInstance.peer.primarySibling; var divA = a.accessibleInstances[ 0 ].peer.primarySibling; var divB = b.accessibleInstances[ 0 ].peer.primarySibling;