Skip to content

Commit 00e5e14

Browse files
apushakscottgonzalez
authored andcommitted
Accordion: Correct height calculated when closed
Fixes #11938 Closes gh-1536 Closes gh-1616 (cherry picked from commit c87653b)
1 parent f7a529f commit 00e5e14

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

tests/unit/accordion/accordion.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<script src="../swarminject.js"></script>
3131
<style>
32-
#list, #list1 *, #navigation, #navigation * {
32+
#list, #list1 *, #navigation, #navigation *, #collapsible, #collapsible * {
3333
margin: 0;
3434
padding: 0;
3535
font-size: 12px;
@@ -39,6 +39,10 @@
3939
#list1 > div {
4040
overflow: visible;
4141
}
42+
#collapsibleWrapper {
43+
width: 300px;
44+
float: left;
45+
}
4246
</style>
4347
</head>
4448
<body>
@@ -134,6 +138,19 @@ <h2><a href="?p=1.1.3">Drums</a></h2>
134138
</dd>
135139
</dl>
136140

141+
<div id="collapsibleWrapper">
142+
<div id="collapsible">
143+
<h3>Header</h3>
144+
<div>
145+
<p>
146+
The calculated height of this accordion should be the same
147+
regardless of whether the accordion was collapsed or not
148+
when the height was calculated.
149+
</p>
150+
</div>
151+
</div>
152+
</div>
153+
137154
</div>
138155
</body>
139156
</html>

tests/unit/accordion/accordion_options.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ test( "{ active: false }", function() {
4444
strictEqual( element.accordion( "option", "active" ), 0 );
4545
});
4646

47+
// http://bugs.jqueryui.com/ticket/11938
48+
test( "{ active: false, collapsible: true }", function() {
49+
expect( 1 );
50+
var element = $( "#collapsible" ).accordion(),
51+
height = element.outerHeight();
52+
53+
element
54+
.accordion( "destroy" )
55+
.accordion( {
56+
active: false,
57+
collapsible: true
58+
} )
59+
.accordion( "option", "active", 0 );
60+
equal( element.outerHeight(), height );
61+
} );
62+
4763
test( "{ active: Number }", function() {
4864
expect( 8 );
4965
var element = $( "#list1" ).accordion({

ui/accordion.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,16 @@ return $.widget( "ui.accordion", {
360360
} else if ( heightStyle === "auto" ) {
361361
maxHeight = 0;
362362
this.headers.next()
363-
.each(function() {
363+
.each( function() {
364+
var isVisible = $( this ).is( ":visible" );
365+
if ( !isVisible ) {
366+
$( this ).show();
367+
}
364368
maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() );
365-
})
369+
if ( !isVisible ) {
370+
$( this ).hide();
371+
}
372+
} )
366373
.height( maxHeight );
367374
}
368375
},

0 commit comments

Comments
 (0)