]> source.dussan.org Git - jquery-ui.git/commitdiff
Accordion: Correct height calculated when closed
authorAlyosha Pushak <alyosha.pushak@gmail.com>
Mon, 13 Apr 2015 02:17:16 +0000 (19:17 -0700)
committerScott González <scott.gonzalez@gmail.com>
Thu, 9 Jun 2016 21:38:09 +0000 (17:38 -0400)
Fixes #11938
Closes gh-1536
Closes gh-1616

(cherry picked from commit c87653bc24f5bc84c299b047d49a06c132a48788)

tests/unit/accordion/accordion.html
tests/unit/accordion/accordion_options.js
ui/accordion.js

index 5a76ba566ded2406ece8f8980c2dae5388763c8a..12e37b65a9155f5e3c710e4fc2ce7151adc97260 100644 (file)
@@ -29,7 +29,7 @@
 
        <script src="../swarminject.js"></script>
        <style>
-       #list, #list1 *, #navigation, #navigation * {
+       #list, #list1 *, #navigation, #navigation *, #collapsible, #collapsible * {
                margin: 0;
                padding: 0;
                font-size: 12px;
        #list1 > div {
                overflow: visible;
        }
+       #collapsibleWrapper {
+               width: 300px;
+               float: left;
+       }
        </style>
 </head>
 <body>
        </dd>
 </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>
 </body>
 </html>
index 214753e40bf7a8d01aa4581a73e03cefaf8534e0..dc50317fb5898c1117ed7392747217eeb3cebfce 100644 (file)
@@ -44,6 +44,22 @@ test( "{ active: false }", function() {
        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() {
        expect( 8 );
        var element = $( "#list1" ).accordion({
index 98c8412cc6756b1e55702ca7ccf5fa42a898fa72..483de50107d590ac61e7a064a08038188935d297 100644 (file)
@@ -360,9 +360,16 @@ return $.widget( "ui.accordion", {
                } else if ( heightStyle === "auto" ) {
                        maxHeight = 0;
                        this.headers.next()
-                               .each(function() {
+                               .each( function() {
+                                       var isVisible = $( this ).is( ":visible" );
+                                       if ( !isVisible ) {
+                                               $( this ).show();
+                                       }
                                        maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() );
-                               })
+                                       if ( !isVisible ) {
+                                               $( this ).hide();
+                                       }
+                               } )
                                .height( maxHeight );
                }
        },