Skip to content

Commit 09fde89

Browse files
committed
Controlgroup: Fix create and destroy for controlgroupLabel
Creating the label broke while doing a refactoring, the lack of tests allowed that to go unnoticed. Shouldn't happen again with the extra tests, covering both controlgroupLabel and spinner.
1 parent bb56dd5 commit 09fde89

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

tests/unit/controlgroup/controlgroup.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>jQuery UI Controlgroup Test Suite</title>
66

77
<script src="../../../external/requirejs/require.js"></script>
8-
<script src="../../lib/css.js" data-modules="core button checkboxradio selectmenu controlgroup"></script>
8+
<script src="../../lib/css.js" data-modules="core button checkboxradio selectmenu spinner controlgroup"></script>
99
<script src="../../lib/bootstrap.js" data-modules="common core methods options"></script>
1010
</head>
1111
<body>
@@ -28,6 +28,8 @@
2828
</select>
2929
<div class="test"></div>
3030
<button>Button with icon on the bottom</button>
31+
<label for="spinner" class="ui-controlgroup-label"># of cars</label>
32+
<input id="spinner" class="ui-spinner-input">
3133
<select>
3234
<option>Fast</option>
3335
<option>Medium</option>

tests/unit/controlgroup/core.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ define( [
99
module( "Controlgroup: Core" );
1010

1111
test( "selectmenu: open/close corners", function( assert ) {
12-
expect( 1 );
12+
expect( 12 );
1313
var element = $( ".controlgroup" ).controlgroup(),
1414
selects = element.find( "select" ),
1515
selectButton = selects.eq( 0 ).selectmenu( "widget" );
1616

17-
expect( 12 );
18-
1917
selects.eq( 0 ).selectmenu( "open" );
2018
assert.hasClasses( selectButton, "ui-corner-tl",
2119
"Horizontal: First selectmenu gets ui-corner-tl when opened" );
@@ -66,4 +64,13 @@ test( "selectmenu: open/close corners", function( assert ) {
6664
"vertical: Last selectmenu gets ui-corner-bottom when closed" );
6765
} );
6866

67+
test( "selectmenu: controlgroupLabel", function( assert ) {
68+
expect( 2 );
69+
var element = $( ".controlgroup" ).controlgroup();
70+
var label = element.find( ".ui-controlgroup-label" );
71+
72+
assert.hasClasses( label, "ui-widget ui-widget-content ui-state-default ui-controlgroup-item" );
73+
assert.hasClasses( label.find( "span" ), "ui-controlgroup-label-contents" );
74+
} );
75+
6976
} );

ui/widgets/controlgroup.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ return $.widget( "ui.controlgroup", {
6161
this._callChildMethod( "destroy" );
6262
this.childWidgets.removeData( "ui-controlgroup-data" );
6363
this.element.removeAttr( "role" );
64+
if ( this.options.items.controlgroupLabel ) {
65+
this.element
66+
.find( this.options.items.controlgroupLabel )
67+
.find( ".ui-controlgroup-label-contents" )
68+
.contents().unwrap();
69+
}
6470
},
6571

6672
_initWidgets: function() {
@@ -72,8 +78,8 @@ return $.widget( "ui.controlgroup", {
7278
var labels;
7379
var options = {};
7480

75-
// Make sure the widget actually exists and has a selector set
76-
if ( !$.fn[ widget ] || !selector ) {
81+
// Make sure the widget has a selector set
82+
if ( !selector ) {
7783
return;
7884
}
7985

@@ -87,6 +93,11 @@ return $.widget( "ui.controlgroup", {
8793
return;
8894
}
8995

96+
// Make sure the widget actually exists
97+
if ( !$.fn[ widget ] ) {
98+
return;
99+
}
100+
90101
// We assume everything is in the middle to start because we can't determine
91102
// first / last elements until all enhancments are done.
92103
if ( that[ "_" + widget + "Options" ] ) {

0 commit comments

Comments
 (0)