Skip to content

Commit 7d5e6d2

Browse files
committed
Controlgroup: Fix rendering of labels
Fixes #14967 Closes gh-1703
1 parent 81a8e30 commit 7d5e6d2

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

demos/controlgroup/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h1>Controlgroup</h1>
7575
<input type="checkbox" name="insurance" id="insurance-v">
7676
<label for="vertical-spinner" class="ui-controlgroup-label"># of cars</label>
7777
<input id="vertical-spinner" class="ui-spinner-input">
78-
<button>Book Now!</button>
78+
<button id="book">Book Now!</button>
7979
</div>
8080
</fieldset>
8181
</div>

tests/unit/controlgroup/controlgroup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<option>Medium</option>
5656
<option>Slow</option>
5757
</select>
58+
<label class="ui-controlgroup-label">Label</label>
5859
<button>Button with icon on the bottom</button>
5960
</div>
6061
</div>

tests/unit/controlgroup/core.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ var assertSanatized = function( assert, initClasses, expectedClasses, message )
9292

9393
QUnit.test( "_resolveClassesValues", function( assert ) {
9494
assert.expect( 6 );
95-
assertSanatized( assert, "bar ui-corner-bottom", "bar", "Single Corner Class Removed end" );
96-
assertSanatized( assert, "ui-corner-bottom bar", "bar", "Single Corner Class Removed beginning" );
97-
assertSanatized( assert, "bar ui-corner-bottom ui-corner-left", "bar", "Multiple Corner Class Removed end" );
98-
assertSanatized( assert, "ui-corner-bottom ui-corner-left bar", "bar", "Multiple Corner Class Removed beginning" );
99-
assertSanatized( assert, "bar ui-corner-bottom ui-corner-left foo", "bar foo", "Multiple Corner Class Removed Middle" );
100-
assertSanatized( assert, "bar", "bar", "No corner Class" );
95+
assertSanatized( assert, "bar ui-corner-bottom", "bar", "Single corner class removed end" );
96+
assertSanatized( assert, "ui-corner-bottom bar", "bar", "Single corner class removed beginning" );
97+
assertSanatized( assert, "bar ui-corner-bottom ui-corner-left", "bar", "Multiple corner classes removed end" );
98+
assertSanatized( assert, "ui-corner-bottom ui-corner-left bar", "bar", "Multiple corner classes removed beginning" );
99+
assertSanatized( assert, "bar ui-corner-bottom ui-corner-left foo", "bar foo", "Multiple corner class removed middle" );
100+
assertSanatized( assert, "bar", "bar", "No corner classes" );
101101
} );
102102

103103
} );

tests/unit/controlgroup/methods.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,12 @@ QUnit.test( "Child Classes Option: refresh", function( assert ) {
177177
assert.hasClasses( selectmenu.selectmenu( "widget" ), "test-class" );
178178
} );
179179

180+
QUnit.test( "Controlgroup Label: refresh", function( assert ) {
181+
assert.expect( 1 );
182+
var controlgroup = $( ".controlgroup-refresh" ).controlgroup();
183+
controlgroup.controlgroup( "refresh" );
184+
assert.strictEqual( controlgroup.find( ".ui-controlgroup-label-contents" ).length, 1,
185+
"Controlgroup label does not re-wrap on refresh" );
186+
} );
187+
180188
} );

ui/widgets/controlgroup.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
factory( jQuery );
3131
}
3232
}( function( $ ) {
33-
var removeClassRegex = /ui-corner-([a-z]){2,6}/g;
33+
var controlgroupCornerRegex = /ui-corner-([a-z]){2,6}/g;
3434

3535
return $.widget( "ui.controlgroup", {
3636
version: "@VERSION",
@@ -87,7 +87,12 @@ return $.widget( "ui.controlgroup", {
8787
if ( widget === "controlgroupLabel" ) {
8888
labels = that.element.find( selector );
8989
labels.each( function() {
90-
$( this ).contents()
90+
var element = $( this );
91+
92+
if ( element.children( ".ui-controlgroup-label-contents" ).length ) {
93+
return;
94+
}
95+
element.contents()
9196
.wrapAll( "<span class='ui-controlgroup-label-contents'></span>" );
9297
} );
9398
that._addClass( labels, null, "ui-widget ui-widget-content ui-state-default" );
@@ -210,8 +215,8 @@ return $.widget( "ui.controlgroup", {
210215
_resolveClassesValues: function( classes, instance ) {
211216
$.each( classes, function( key ) {
212217
var current = instance.options.classes[ key ] || "";
213-
current = current.replace( removeClassRegex, "" ).trim();
214-
classes[ key ] = ( current + " " + classes[ key ] ).replace( / +/g, " " );
218+
current = current.replace( controlgroupCornerRegex, "" ).trim();
219+
classes[ key ] = ( current + " " + classes[ key ] ).replace( /\s+/g, " " );
215220
} );
216221
return classes;
217222
},

0 commit comments

Comments
 (0)