]> source.dussan.org Git - jquery-ui.git/commitdiff
Controlgroup: Fix rendering of labels
authorAlexander Schmitz <arschmitz@gmail.com>
Wed, 11 May 2016 16:14:14 +0000 (12:14 -0400)
committerAlexander Schmitz <arschmitz@gmail.com>
Thu, 26 May 2016 13:15:48 +0000 (09:15 -0400)
Fixes #14967
Closes gh-1703

demos/controlgroup/default.html
tests/unit/controlgroup/controlgroup.html
tests/unit/controlgroup/core.js
tests/unit/controlgroup/methods.js
ui/widgets/controlgroup.js

index 0c26bd6cdda36365629acc3c0eaa72e12e6eef33..12e1a9af142274ebff82ee01cbf87b5739f77d7c 100644 (file)
@@ -75,7 +75,7 @@
                        <input type="checkbox" name="insurance" id="insurance-v">
                        <label for="vertical-spinner" class="ui-controlgroup-label"># of cars</label>
                        <input id="vertical-spinner" class="ui-spinner-input">
-                       <button>Book Now!</button>
+                       <button id="book">Book Now!</button>
                </div>
        </fieldset>
 </div>
index 9983232ec361a74ee43265713a1c5b015414fe72..170676aa85a36330da3dd691897f28afcf59dd17 100644 (file)
@@ -55,6 +55,7 @@
                        <option>Medium</option>
                        <option>Slow</option>
                </select>
+               <label class="ui-controlgroup-label">Label</label>
                <button>Button with icon on the bottom</button>
        </div>
 </div>
index 70d6267ad76156cd2cff3d531bb0cbaf01f0ee78..b32d829ed00e0257bd1b6634204a438f1ee60850 100644 (file)
@@ -92,12 +92,12 @@ var assertSanatized = function( assert, initClasses, expectedClasses, message )
 
 QUnit.test( "_resolveClassesValues", function( assert ) {
        assert.expect( 6 );
-       assertSanatized( assert, "bar ui-corner-bottom", "bar", "Single Corner Class Removed end" );
-       assertSanatized( assert, "ui-corner-bottom bar", "bar", "Single Corner Class Removed beginning" );
-       assertSanatized( assert, "bar ui-corner-bottom ui-corner-left", "bar", "Multiple Corner Class Removed end" );
-       assertSanatized( assert, "ui-corner-bottom ui-corner-left bar", "bar", "Multiple Corner Class Removed beginning" );
-       assertSanatized( assert, "bar ui-corner-bottom ui-corner-left foo", "bar foo", "Multiple Corner Class Removed Middle" );
-       assertSanatized( assert, "bar", "bar", "No corner Class" );
+       assertSanatized( assert, "bar ui-corner-bottom", "bar", "Single corner class removed end" );
+       assertSanatized( assert, "ui-corner-bottom bar", "bar", "Single corner class removed beginning" );
+       assertSanatized( assert, "bar ui-corner-bottom ui-corner-left", "bar", "Multiple corner classes removed end" );
+       assertSanatized( assert, "ui-corner-bottom ui-corner-left bar", "bar", "Multiple corner classes removed beginning" );
+       assertSanatized( assert, "bar ui-corner-bottom ui-corner-left foo", "bar foo", "Multiple corner class removed middle" );
+       assertSanatized( assert, "bar", "bar", "No corner classes" );
 } );
 
 } );
index a9d781f2ee640cc3ceaa1828e02459ee7a02f6e5..09271d39f280c858acb86b6fed85faf0196512b3 100644 (file)
@@ -177,4 +177,12 @@ QUnit.test( "Child Classes Option: refresh", function( assert ) {
        assert.hasClasses( selectmenu.selectmenu( "widget" ), "test-class" );
 } );
 
+QUnit.test( "Controlgroup Label: refresh", function( assert ) {
+       assert.expect( 1 );
+       var controlgroup = $( ".controlgroup-refresh" ).controlgroup();
+       controlgroup.controlgroup( "refresh" );
+       assert.strictEqual( controlgroup.find( ".ui-controlgroup-label-contents" ).length, 1,
+               "Controlgroup label does not re-wrap on refresh" );
+} );
+
 } );
index 34b2ba9c79b84f73bc005fd09d8aff4e5e58b45a..a79491bfb7b56610b70d71d3b4650f7524d5d3c8 100644 (file)
@@ -30,7 +30,7 @@
                factory( jQuery );
        }
 }( function( $ ) {
-var removeClassRegex = /ui-corner-([a-z]){2,6}/g;
+var controlgroupCornerRegex = /ui-corner-([a-z]){2,6}/g;
 
 return $.widget( "ui.controlgroup", {
        version: "@VERSION",
@@ -87,7 +87,12 @@ return $.widget( "ui.controlgroup", {
                        if ( widget === "controlgroupLabel" ) {
                                labels = that.element.find( selector );
                                labels.each( function() {
-                                       $( this ).contents()
+                                       var element = $( this );
+
+                                       if ( element.children( ".ui-controlgroup-label-contents" ).length ) {
+                                               return;
+                                       }
+                                       element.contents()
                                                .wrapAll( "<span class='ui-controlgroup-label-contents'></span>" );
                                } );
                                that._addClass( labels, null, "ui-widget ui-widget-content ui-state-default" );
@@ -210,8 +215,8 @@ return $.widget( "ui.controlgroup", {
        _resolveClassesValues: function( classes, instance ) {
                $.each( classes, function( key ) {
                        var current = instance.options.classes[ key ] || "";
-                       current = current.replace( removeClassRegex, "" ).trim();
-                       classes[ key ] = ( current + " " + classes[ key ] ).replace( / +/g, " " );
+                       current = current.replace( controlgroupCornerRegex, "" ).trim();
+                       classes[ key ] = ( current + " " + classes[ key ] ).replace( /\s+/g, " " );
                } );
                return classes;
        },