Skip to content

Commit 7dde5c9

Browse files
committed
Widget: Call ._setOptionDisabled() on init if the widget is disabled
Fixes #9151 Ref gh-1599
1 parent 0db243a commit 7dde5c9

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

tests/unit/widget/core.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,39 @@ test( ".disable()", function() {
729729
$( "<div>" ).testWidget().testWidget( "disable" );
730730
} );
731731

732+
test( "._setOptionDisabled()", function() {
733+
expect( 3 );
734+
735+
var method;
736+
var widget;
737+
738+
$.widget( "ui.testWidget", {
739+
_setOptionDisabled: function( value ) {
740+
method( value );
741+
}
742+
} );
743+
744+
method = function() {
745+
ok( false, "._setOptionDisabled() called on init when not disabled" );
746+
};
747+
$( "<div>" ).testWidget();
748+
749+
method = function( value ) {
750+
strictEqual( value, true, "._setOptionDisabled called on init when disabled" );
751+
};
752+
widget = $( "<div>" ).testWidget( { disabled: true } );
753+
754+
method = function( value ) {
755+
strictEqual( value, false, "._setOptionDisabled called when enabling" );
756+
};
757+
widget.testWidget( "enable" );
758+
759+
method = function( value ) {
760+
strictEqual( value, true, "._setOptionDisabled called when disabling" );
761+
};
762+
widget.testWidget( "option", "disabled", true );
763+
} );
764+
732765
test( ".widget() - base", function() {
733766
expect( 2 );
734767
var constructor = $.widget( "ui.testWidget", {

ui/widget.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ $.Widget.prototype = {
318318
options );
319319

320320
this._create();
321+
322+
if ( this.options.disabled ) {
323+
this._setOptionDisabled( this.options.disabled );
324+
}
325+
321326
this._trigger( "create", null, this._getCreateEventData() );
322327
this._init();
323328
},
@@ -419,13 +424,7 @@ $.Widget.prototype = {
419424
this.options[ key ] = value;
420425

421426
if ( key === "disabled" ) {
422-
this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
423-
424-
// If the widget is becoming disabled, then nothing is interactive
425-
if ( value ) {
426-
this._removeClass( this.hoverable, null, "ui-state-hover" );
427-
this._removeClass( this.focusable, null, "ui-state-focus" );
428-
}
427+
this._setOptionDisabled( value );
429428
}
430429

431430
return this;
@@ -462,6 +461,16 @@ $.Widget.prototype = {
462461
}
463462
},
464463

464+
_setOptionDisabled: function( value ) {
465+
this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
466+
467+
// If the widget is becoming disabled, then nothing is interactive
468+
if ( value ) {
469+
this._removeClass( this.hoverable, null, "ui-state-hover" );
470+
this._removeClass( this.focusable, null, "ui-state-focus" );
471+
}
472+
},
473+
465474
enable: function() {
466475
return this._setOptions( { disabled: false } );
467476
},

0 commit comments

Comments
 (0)