Skip to content

Commit 66ced30

Browse files
committed
Checkboxradio: add classes option
1 parent e9436fa commit 66ced30

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
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: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ $.widget( "ui.checkboxradio", {
5757
options: {
5858
disabled: null,
5959
label: null,
60-
icon: false
60+
icon: false,
61+
classes: {
62+
"ui-checkboxradio": null,
63+
"ui-checkbox": null,
64+
"ui-radio": null,
65+
"ui-checkbox-label": "ui-corner-all",
66+
"ui-radio-label": "ui-corner-all",
67+
"ui-checkboxradio-icon": "ui-corner-all",
68+
"ui-radio-checked": null,
69+
"ui-checkbox-checked": null
70+
}
6171
},
6272

6373
_getCreateOptions: function() {
@@ -168,12 +178,14 @@ $.widget( "ui.checkboxradio", {
168178
var checked = this.element.is( ":checked" );
169179

170180
this._updateIcon( checked );
171-
this.element.addClass( "ui-helper-hidden-accessible ui-checkboxradio" );
181+
this.element.addClass( "ui-helper-hidden-accessible " +
182+
this._classes( "ui-checkboxradio" ) );
172183

173-
this.label.addClass( baseClasses + " ui-" + this.type + "-label" );
184+
this.label.addClass( baseClasses + " " + this._classes( "ui-" + this.type + "-label" ) );
174185

175186
if ( checked ) {
176-
this.label.addClass( "ui-" + this.type + "-checked ui-state-active" );
187+
this.label.addClass( this._classes( "ui-" + this.type + "-checked" ) +
188+
" ui-state-active" );
177189
}
178190
if ( this.options.label && this.options.label !== this.originalLabel ) {
179191
this.label.html( this.icon ? this.icon : "" ).append( this.options.label );
@@ -188,7 +200,8 @@ $.widget( "ui.checkboxradio", {
188200

189201
_toggleClasses: function() {
190202
var checked = this.element.is( ":checked" );
191-
this.label.toggleClass( "ui-" + this.type + "-checked ui-state-active", checked );
203+
this.label.toggleClass( this._classes( "ui-" + this.type + "-checked" ) +
204+
" ui-state-active", checked );
192205
if ( this.options.icon && this.type === "checkbox" ) {
193206
this.icon
194207
.toggleClass( "ui-icon-check", checked )
@@ -200,7 +213,7 @@ $.widget( "ui.checkboxradio", {
200213
.map(function() {
201214
return $( this ).checkboxradio( "widget" )[ 0 ];
202215
})
203-
.removeClass( "ui-state-active ui-radio-checked" );
216+
.removeClass( "ui-state-active " + this._classes( "ui-radio-checked" ) );
204217
}
205218
},
206219

@@ -209,7 +222,8 @@ $.widget( "ui.checkboxradio", {
209222
if ( this.icon ) {
210223
this.icon.remove();
211224
}
212-
this.element.removeClass( "ui-checkboxradio ui-helper-hidden-accessible" );
225+
this.element.removeClass( this._classes( "ui-checkboxradio" ) +
226+
" ui-helper-hidden-accessible" );
213227
},
214228

215229
_setOption: function( key, value ) {
@@ -230,7 +244,8 @@ $.widget( "ui.checkboxradio", {
230244
},
231245

232246
_updateIcon: function( checked ) {
233-
var toAdd = "ui-icon ui-icon-background ui-corner-all ";
247+
var toAdd = this._classes( "ui-checkboxradio-icon" ) +
248+
" ui-icon ui-icon-background ";
234249

235250
if ( this.options.icon ) {
236251
this.label.addClass( "ui-icon-beginning" );
@@ -255,7 +270,7 @@ $.widget( "ui.checkboxradio", {
255270
var checked = this.element.is( ":checked" ),
256271
isDisabled = this.element.is( ":disabled" );
257272
this._updateIcon( checked );
258-
this.label.toggleClass( "ui-state-active ui-" + this.type + "-checked", checked );
273+
this.label.toggleClass( "ui-state-active " + this._classes( "ui-" + this.type + "-checked" ), checked );
259274
if ( this.options.label !== null ) {
260275
this.label.html( !!this.icon ? this.icon : "" ).append( this.options.label );
261276
}

0 commit comments

Comments
 (0)