Skip to content

Commit c87653b

Browse files
apushakscottgonzalez
authored andcommitted
Accordion: Correct height calculated when closed
Fixes #11938 Closes jquerygh-1536 Closes jquerygh-1616
1 parent 2bc8461 commit c87653b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

tests/unit/accordion/accordion.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
<script src="../../lib/css.js" data-modules="core accordion"></script>
99
<script src="../../lib/bootstrap.js" data-widget="accordion"></script>
1010
<style>
11-
#list, #list1 *, #navigation, #navigation * {
11+
#list, #list1 *, #navigation, #navigation *, #collapsible, #collapsible * {
1212
margin: 0;
1313
padding: 0;
1414
font-size: 12px;
1515
line-height: 15px;
1616
}
17+
#collapsibleWrapper {
18+
width: 300px;
19+
float: left;
20+
}
1721
</style>
1822
</head>
1923
<body>
@@ -109,6 +113,19 @@ <h2><a href="?p=1.1.3">Drums</a></h2>
109113
</dd>
110114
</dl>
111115

116+
<div id="collapsibleWrapper">
117+
<div id="collapsible">
118+
<h3>Header</h3>
119+
<div>
120+
<p>
121+
The calculated height of this accordion should be the same
122+
regardless of whether the accordion was collapsed or not
123+
when the height was calculated.
124+
</p>
125+
</div>
126+
</div>
127+
</div>
128+
112129
</div>
113130
</body>
114131
</html>

tests/unit/accordion/options.js

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

51+
// http://bugs.jqueryui.com/ticket/11938
52+
test( "{ active: false, collapsible: true }", function() {
53+
expect( 1 );
54+
var element = $( "#collapsible" ).accordion(),
55+
height = element.outerHeight();
56+
57+
element
58+
.accordion( "destroy" )
59+
.accordion( {
60+
active: false,
61+
collapsible: true
62+
} )
63+
.accordion( "option", "active", 0 );
64+
equal( element.outerHeight(), height );
65+
} );
66+
5167
test( "{ active: Number }", function() {
5268
expect( 8 );
5369
var element = $( "#list1" ).accordion( {

ui/widgets/accordion.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,14 @@ return $.widget( "ui.accordion", {
373373
maxHeight = 0;
374374
this.headers.next()
375375
.each( function() {
376+
var isVisible = $( this ).is( ":visible" );
377+
if ( !isVisible ) {
378+
$( this ).show();
379+
}
376380
maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() );
381+
if ( !isVisible ) {
382+
$( this ).hide();
383+
}
377384
} )
378385
.height( maxHeight );
379386
}

0 commit comments

Comments
 (0)