Skip to content

Controlgroup: Add "only" position to class generator functions #1711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/unit/controlgroup/controlgroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
<label class="ui-controlgroup-label">Label</label>
<button>Button with icon on the bottom</button>
</div>
<div class="controlgroup-single-select">
<select id="select-single">
<option>Fast</option>
<option>Medium</option>
<option>Slow</option>
</select>
</div>
<div class="controlgroup-single-simple">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to controlgroup-single-button to match the one above (also update the test titles).

<button class="single-button">button</button>
</div>
</div>
</body>
</html>
60 changes: 60 additions & 0 deletions tests/unit/controlgroup/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,64 @@ QUnit.test( "_resolveClassesValues", function( assert ) {
assertSanatized( assert, "bar", "bar", "No corner classes" );
} );

QUnit.test( "Single controlgroup select - horizontal", function( assert ) {
assert.expect( 4 );
var group = $( ".controlgroup-single-select" ).controlgroup();
var select = group.find( ".ui-selectmenu-button" );

assert.hasClasses( select, "ui-corner-all" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );

group.find( "select" ).selectmenu( "open" );
assert.hasClasses( select, "ui-corner-top" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-all ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );

QUnit.test( "Single controlgroup select - vertical", function( assert ) {
assert.expect( 4 );
var group = $( ".controlgroup-single-select" ).controlgroup( {
direction: "verticle"
} );
var select = group.find( ".ui-selectmenu-button" );

assert.hasClasses( select, "ui-corner-all" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );

group.find( "select" ).selectmenu( "open" );
assert.hasClasses( select, "ui-corner-top" );
assert.lacksClasses( select,
"ui-corner-left ui-corner-right ui-corner-all ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );

QUnit.test( "Single controlgroup simple - horizontal", function( assert ) {
assert.expect( 2 );
var group = $( ".controlgroup-single-simple" ).controlgroup();
var button = group.find( "button" );

assert.hasClasses( button, "ui-corner-all" );
assert.lacksClasses( button,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );

QUnit.test( "Single controlgroup simple - vertical", function( assert ) {
assert.expect( 2 );
var group = $( ".controlgroup-single-simple" ).controlgroup( {
direction: "verticle"
} );
var button = group.find( "button" );

assert.hasClasses( button, "ui-corner-all" );
assert.lacksClasses( button,
"ui-corner-left ui-corner-right ui-corner-top ui-corner-left" +
" ui-corner-tr ui-corner-tl ui-corner-bl ui corner-br" );
} );

} );
15 changes: 12 additions & 3 deletions ui/widgets/controlgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ return $.widget( "ui.controlgroup", {
},

_updateCornerClass: function( element, position ) {
var remove = "ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right";
var remove = "ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right ui-corner-all";
var add = this._buildSimpleOptions( position, "label" ).classes.label;

this._removeClass( element, null, remove );
Expand All @@ -167,7 +167,8 @@ return $.widget( "ui.controlgroup", {
result.classes[ key ] = {
"middle": "",
"first": "ui-corner-" + ( direction ? "top" : "left" ),
"last": "ui-corner-" + ( direction ? "bottom" : "right" )
"last": "ui-corner-" + ( direction ? "bottom" : "right" ),
"only": "ui-corner-all"
}[ position ];

return result;
Expand Down Expand Up @@ -206,6 +207,10 @@ return $.widget( "ui.controlgroup", {
last: {
"ui-selectmenu-button-open": direction ? "" : "ui-corner-tr",
"ui-selectmenu-button-closed": "ui-corner-" + ( direction ? "bottom" : "right" )
},
only: {
"ui-selectmenu-button-open": "ui-corner-top",
"ui-selectmenu-button-closed": "ui-corner-all"
}

}[ position ]
Expand Down Expand Up @@ -261,7 +266,11 @@ return $.widget( "ui.controlgroup", {
var instance = children[ value ]().data( "ui-controlgroup-data" );

if ( instance && that[ "_" + instance.widgetName + "Options" ] ) {
var options = that[ "_" + instance.widgetName + "Options" ]( value );
var options = that[ "_" + instance.widgetName + "Options" ](
children.length === 1 ?
"only" :
value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines should be indented, but I'd probably put the entire ternary on a single line.

);
options.classes = that._resolveClassesValues( options.classes, instance );
instance.element[ instance.widgetName ]( options );
} else {
Expand Down