Skip to content

Commit

Permalink
add visible property to AccessiblePeer, #715
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 6, 2018
1 parent ca66e74 commit 52cc4f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion js/accessibility/AccessibleInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ define( function( require ) {
if ( this.parent ) {
return this.parent.isGloballyVisible();
}
else {
else { // base case at root
return true;
}
},
Expand Down
48 changes: 29 additions & 19 deletions js/accessibility/AccessiblePeer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', '' );
}
} );
}
},

/**
Expand Down
1 change: 0 additions & 1 deletion js/accessibility/FocusTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 52cc4f5

Please sign in to comment.