Skip to content

Commit 8c4f23f

Browse files
committed
Checkboxradio: add classes option
1 parent bd5cea9 commit 8c4f23f

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

tests/unit/checkboxradio/checkboxradio_common.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ TestHelpers.commonWidgetTests( "checkboxradio", {
44
disabled: null,
55
label: null,
66
icon: false,
7+
classes: {
8+
"ui-checkboxradio": null,
9+
"ui-checkbox": null,
10+
"ui-radio": null,
11+
"ui-checkbox-label": "ui-corner-all",
12+
"ui-radio-label": "ui-corner-all",
13+
"ui-checkboxradio-icon": "ui-corner-all",
14+
"ui-radio-checked": null,
15+
"ui-checkbox-checked": null
16+
},
717

818
// Callbacks
919
create: null

tests/unit/checkboxradio/checkboxradio_options.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module( "Checkboxradio: checkbox: options" );
7676
strictEqual( widget.find( "span" ).length, 1,
7777
"Label contains a span when created with icon:true" );
7878
strictEqual( widget.find( "span" ).attr( "class" ),
79-
"ui-icon ui-icon-background ui-corner-all ui-icon-blank",
79+
"ui-checkboxradio-icon ui-corner-all ui-icon ui-icon-background ui-icon-blank",
8080
"Icon span has proper classes when created not checked" );
8181

8282
checkbox.checkboxradio( "destroy" ).prop( "checked", true );
@@ -86,7 +86,7 @@ module( "Checkboxradio: checkbox: options" );
8686
});
8787

8888
strictEqual( widget.find( "span" ).attr( "class" ),
89-
"ui-icon ui-icon-background ui-corner-all ui-icon-check",
89+
"ui-checkboxradio-icon ui-corner-all ui-icon ui-icon-background ui-icon-check",
9090
"Icon span has proper classes when created checked" );
9191

9292
checkbox.checkboxradio( "option", "icon", false );
@@ -97,7 +97,7 @@ module( "Checkboxradio: checkbox: options" );
9797
checkbox.checkboxradio( "option", "icon", true );
9898

9999
strictEqual( widget.find( "span" ).attr( "class" ),
100-
"ui-icon ui-icon-background ui-corner-all ui-icon-check",
100+
"ui-checkboxradio-icon ui-corner-all ui-icon ui-icon-background ui-icon-check",
101101
"Icon span has proper classes when option set to true and :is( checked )" );
102102

103103
checkbox.prop( "checked", false ).checkboxradio( "refresh" );
@@ -109,7 +109,7 @@ module( "Checkboxradio: checkbox: options" );
109109
checkbox.checkboxradio( "option", "icon", true );
110110

111111
strictEqual( widget.find( "span" ).attr( "class" ),
112-
"ui-icon ui-icon-background ui-corner-all ui-icon-blank",
112+
"ui-checkboxradio-icon ui-corner-all ui-icon ui-icon-background ui-icon-blank",
113113
"Icon span has proper classes when option set to true and not checked" );
114114

115115
checkbox.checkboxradio( "destroy" );

ui/checkboxradio.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ $.widget( "ui.checkboxradio", {
5757
options: {
5858
disabled: null,
5959
label: null,
60+
<<<<<<< HEAD
6061
icon: true,
62+
=======
63+
icon: false,
64+
>>>>>>> db16c96... Checkboxradio: add classes option
6165
classes: {
6266
"ui-checkboxradio": null,
6367
"ui-checkbox": null,
@@ -187,12 +191,14 @@ $.widget( "ui.checkboxradio", {
187191
var checked = this.element.is( ":checked" );
188192

189193
this._updateIcon( checked );
190-
this.element.addClass( "ui-helper-hidden-accessible ui-checkboxradio" );
194+
this.element.addClass( "ui-helper-hidden-accessible " +
195+
this._classes( "ui-checkboxradio" ) );
191196

192-
this.label.addClass( baseClasses + " ui-" + this.type + "-label" );
197+
this.label.addClass( baseClasses + " " + this._classes( "ui-" + this.type + "-label" ) );
193198

194199
if ( checked ) {
195-
this.label.addClass( "ui-" + this.type + "-checked ui-state-active" );
200+
this.label.addClass( this._classes( "ui-" + this.type + "-checked" ) +
201+
" ui-state-active" );
196202
}
197203
if ( this.options.label && this.options.label !== this.originalLabel ) {
198204
this.label.html( this.icon ? this.icon : "" ).append( this.options.label );
@@ -207,7 +213,8 @@ $.widget( "ui.checkboxradio", {
207213

208214
_toggleClasses: function() {
209215
var checked = this.element.is( ":checked" );
210-
this.label.toggleClass( "ui-" + this.type + "-checked ui-state-active", checked );
216+
this.label.toggleClass( this._classes( "ui-" + this.type + "-checked" ) +
217+
" ui-state-active", checked );
211218
if ( this.options.icon && this.type === "checkbox" ) {
212219
this.icon
213220
.toggleClass( "ui-icon-check", checked )
@@ -219,7 +226,7 @@ $.widget( "ui.checkboxradio", {
219226
.map(function() {
220227
return $( this ).checkboxradio( "widget" )[ 0 ];
221228
})
222-
.removeClass( "ui-state-active ui-radio-checked" );
229+
.removeClass( "ui-state-active " + this._classes( "ui-radio-checked" ) );
223230
}
224231
},
225232

@@ -228,7 +235,8 @@ $.widget( "ui.checkboxradio", {
228235
if ( this.icon ) {
229236
this.icon.remove();
230237
}
231-
this.element.removeClass( "ui-checkboxradio ui-helper-hidden-accessible" );
238+
this.element.removeClass( this._classes( "ui-checkboxradio" ) +
239+
" ui-helper-hidden-accessible" );
232240
},
233241

234242
_setOption: function( key, value ) {
@@ -249,7 +257,8 @@ $.widget( "ui.checkboxradio", {
249257
},
250258

251259
_updateIcon: function( checked ) {
252-
var toAdd = "ui-icon ui-icon-background ui-corner-all ";
260+
var toAdd = this._classes( "ui-checkboxradio-icon" ) +
261+
" ui-icon ui-icon-background ";
253262

254263
if ( this.options.icon ) {
255264
this.label.addClass( "ui-icon-beginning" );
@@ -274,7 +283,6 @@ $.widget( "ui.checkboxradio", {
274283
var checked = this.element.is( ":checked" ),
275284
isDisabled = this.element.is( ":disabled" );
276285
this._updateIcon( checked );
277-
console.log( this.options.label );
278286
this.label.toggleClass( "ui-state-active " + this._classes( "ui-" + this.type + "-checked" ), checked );
279287
if ( this.options.label !== null ) {
280288
this.label.contents().not( this.element.add( this.icon ) ).remove();

0 commit comments

Comments
 (0)