Skip to content

Commit

Permalink
Removing nodes/bounds from AccordionBox when content has invalid boun…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed May 5, 2020
1 parent ff3cc83 commit dde06b1
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions js/AccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ function AccordionBox( contentNode, options ) {

// @private {Rectangle} - Expanded box
this.expandedBox = new Rectangle( boxOptions );
this.addChild( this.expandedBox );

// @private {Rectangle} - Collapsed box
this.collapsedBox = new Rectangle( boxOptions );
this.addChild( this.collapsedBox );

// @private {Rectangle} - Transparent rectangle for working around issues like
// https://github.com/phetsims/graphing-quadratics/issues/86. The current hypothesis is that browsers (in this case,
Expand All @@ -189,7 +187,6 @@ function AccordionBox( contentNode, options ) {
fill: 'transparent',
pickable: false
} );
this.addChild( this.workaroundBox );

// @private {Path}
this.expandedTitleBar = new Path( null, merge( {
Expand Down Expand Up @@ -254,9 +251,6 @@ function AccordionBox( contentNode, options ) {
this.expandedTitleBar.cursor = enabled ? options.cursor : null;
} );

this.addChild( this.titleNode );
this.addChild( this.expandCollapseButton );

// optional box outline, on top of everything else
if ( options.stroke ) {

Expand All @@ -277,6 +271,10 @@ function AccordionBox( contentNode, options ) {

this.expandedBox.addChild( this._contentNode );

// @private {Node} - Holds the main components when the content's bounds are valid
this.containerNode = new Node();
this.addChild( this.containerNode );

this.layout();

// Watch future changes for re-layout (don't want to trigger on our first layout and queue useless ones)
Expand Down Expand Up @@ -320,6 +318,19 @@ inherit( Node, AccordionBox, {
* @private
*/
layout: function() {
const hasValidBounds = this._contentNode.bounds.isValid();
this.containerNode.children = hasValidBounds ? [
this.expandedBox,
this.collapsedBox,
this.workaroundBox,
this.titleNode,
this.expandCollapseButton
] : [];

if ( !hasValidBounds ) {
return;
}

const collapsedBoxHeight = this.getCollapsedBoxHeight();
const boxWidth = this.getBoxWidth();
const expandedBoxHeight = this.getExpandedBoxHeight();
Expand Down

0 comments on commit dde06b1

Please sign in to comment.