Skip to content

Commit

Permalink
Accordion: Correct height calculated when closed
Browse files Browse the repository at this point in the history
Fixes #11938
Closes gh-1536
Closes gh-1616
  • Loading branch information
apushak authored and scottgonzalez committed Feb 9, 2016
1 parent 2bc8461 commit c87653b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/unit/accordion/accordion.html
Expand Up @@ -8,12 +8,16 @@
<script src="../../lib/css.js" data-modules="core accordion"></script> <script src="../../lib/css.js" data-modules="core accordion"></script>
<script src="../../lib/bootstrap.js" data-widget="accordion"></script> <script src="../../lib/bootstrap.js" data-widget="accordion"></script>
<style> <style>
#list, #list1 *, #navigation, #navigation * { #list, #list1 *, #navigation, #navigation *, #collapsible, #collapsible * {
margin: 0; margin: 0;
padding: 0; padding: 0;
font-size: 12px; font-size: 12px;
line-height: 15px; line-height: 15px;
} }
#collapsibleWrapper {
width: 300px;
float: left;
}
</style> </style>
</head> </head>
<body> <body>
Expand Down Expand Up @@ -109,6 +113,19 @@ <h2><a href="?p=1.1.3">Drums</a></h2>
</dd> </dd>
</dl> </dl>


<div id="collapsibleWrapper">
<div id="collapsible">
<h3>Header</h3>
<div>
<p>
The calculated height of this accordion should be the same
regardless of whether the accordion was collapsed or not
when the height was calculated.
</p>
</div>
</div>
</div>

</div> </div>
</body> </body>
</html> </html>
16 changes: 16 additions & 0 deletions tests/unit/accordion/options.js
Expand Up @@ -48,6 +48,22 @@ test( "{ active: false }", function() {
strictEqual( element.accordion( "option", "active" ), 0 ); strictEqual( element.accordion( "option", "active" ), 0 );
} ); } );


// http://bugs.jqueryui.com/ticket/11938
test( "{ active: false, collapsible: true }", function() {
expect( 1 );
var element = $( "#collapsible" ).accordion(),
height = element.outerHeight();

element
.accordion( "destroy" )
.accordion( {
active: false,
collapsible: true
} )
.accordion( "option", "active", 0 );
equal( element.outerHeight(), height );
} );

test( "{ active: Number }", function() { test( "{ active: Number }", function() {
expect( 8 ); expect( 8 );
var element = $( "#list1" ).accordion( { var element = $( "#list1" ).accordion( {
Expand Down
7 changes: 7 additions & 0 deletions ui/widgets/accordion.js
Expand Up @@ -373,7 +373,14 @@ return $.widget( "ui.accordion", {
maxHeight = 0; maxHeight = 0;
this.headers.next() this.headers.next()
.each( function() { .each( function() {
var isVisible = $( this ).is( ":visible" );
if ( !isVisible ) {
$( this ).show();
}
maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() ); maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() );
if ( !isVisible ) {
$( this ).hide();
}
} ) } )
.height( maxHeight ); .height( maxHeight );
} }
Expand Down

0 comments on commit c87653b

Please sign in to comment.