]> source.dussan.org Git - jquery-ui.git/commitdiff
Accordion: Properly handle collapsible: false and active: false by changing active...
authorScott González <scott.gonzalez@gmail.com>
Thu, 3 Feb 2011 14:54:11 +0000 (09:54 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 3 Feb 2011 14:54:11 +0000 (09:54 -0500)
tests/unit/accordion/accordion_options.js
ui/jquery.ui.accordion.js

index 8fcfdb17211c99e964d63f1184a2c2ba31e64183..71154d57a958617e77c5fc0978b79cd8e508e5eb 100644 (file)
@@ -17,17 +17,16 @@ test( "{ active: false }", function() {
        equals( ac.find( ".ui-accordion-header.ui-state-active" ).size(), 0, "no headers selected" );
        equals( ac.accordion( "option", "active" ), false );
 
-       // TODO: fix active: false when not collapsible
-//     ac.accordion( "option", "collapsible", false );
-//     state( ac, 1, 0, 0 );
-//     equals( ac.accordion( "option", "active" ), 0 );
-//
-//     ac.accordion( "destroy" );
-//     ac.accordion({
-//             active: false
-//     });
-//     state( ac, 1, 0, 0 );
-//     strictEqual( ac.accordion( "option", "active" ), 0 );
+       ac.accordion( "option", "collapsible", false );
+       state( ac, 1, 0, 0 );
+       equals( ac.accordion( "option", "active" ), 0 );
+
+       ac.accordion( "destroy" );
+       ac.accordion({
+               active: false
+       });
+       state( ac, 1, 0, 0 );
+       strictEqual( ac.accordion( "option", "active" ), 0 );
 });
 
 test( "{ active: Number }", function() {
index 4357c435b28e5cc76d22130c825fb78ccc8290b0..33c3a8505cc8c6457f52c18b20bfce638bb9a7ea 100644 (file)
@@ -44,6 +44,10 @@ $.widget( "ui.accordion", {
                self.headers.next()
                        .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" );
 
+               // don't allow collapsible: false and active: false
+               if ( !options.collapsible && options.active === false ) {
+                       options.active = 0;
+               }
                self.active = self._findActive( options.active )
                        .addClass( "ui-state-default ui-state-active" )
                        .toggleClass( "ui-corner-all" )
@@ -149,12 +153,18 @@ $.widget( "ui.accordion", {
 
                this._super( "_setOption", key, value );
 
+               // setting collapsible: false while collapsed; open first panel
+               if ( key === "collapsible" && !value && this.options.active === false ) {
+                       this._activate( 0 );
+               }
+
                if ( key === "icons" ) {
                        this._destroyIcons();
                        if ( value ) {
                                this._createIcons();
                        }
                }
+
                // #5332 - opacity doesn't cascade to positioned elements in IE
                // so we need to add the disabled class to the headers and panels
                if ( key === "disabled" ) {