Skip to content

Commit 17004b9

Browse files
committed
Widget: Use focusin/focusout for ._focusable().
1 parent 3e370a4 commit 17004b9

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

tests/unit/widget/widget_core.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test( "error handling", function() {
137137
$.error = error;
138138
});
139139

140-
test("merge multiple option arguments", function() {
140+
test( "merge multiple option arguments", function() {
141141
expect( 1 );
142142
$.widget( "ui.testWidget", {
143143
_create: function() {
@@ -173,7 +173,7 @@ test("merge multiple option arguments", function() {
173173
});
174174
});
175175

176-
test( "_getCreateOptions()", function() {
176+
test( "._getCreateOptions()", function() {
177177
expect( 1 );
178178
$.widget( "ui.testWidget", {
179179
options: {
@@ -488,6 +488,10 @@ test( "._bind() to descendent", function() {
488488
descendent
489489
.trigger( "keyup" )
490490
.trigger( "keydown" );
491+
descendent
492+
.addClass( "ui-state-disabled" )
493+
.trigger( "keyup" )
494+
.trigger( "keydown" );
491495
widget
492496
.testWidget( "destroy" )
493497
.trigger( "keyup" )
@@ -537,25 +541,25 @@ test( "._focusable()", function() {
537541

538542
var div = $( "#widget" ).testWidget().children();
539543
ok( !div.hasClass( "ui-state-focus" ), "not focused on init" );
540-
div.trigger( "focus" );
544+
div.trigger( "focusin" );
541545
ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" );
542-
div.trigger( "blur" );
546+
div.trigger( "focusout" );
543547
ok( !div.hasClass( "ui-state-focus" ), "not focused after blur" );
544548

545-
div.trigger( "focus" );
549+
div.trigger( "focusin" );
546550
ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" );
547551
$( "#widget" ).testWidget( "disable" );
548552
ok( !div.hasClass( "ui-state-focus" ), "not focused while disabled" );
549-
div.trigger( "focus" );
553+
div.trigger( "focusin" );
550554
ok( !div.hasClass( "ui-state-focus" ), "can't focus while disabled" );
551555
$( "#widget" ).testWidget( "enable" );
552556
ok( !div.hasClass( "ui-state-focus" ), "enabling doesn't reset focus" );
553557

554-
div.trigger( "focus" );
558+
div.trigger( "focusin" );
555559
ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" );
556560
$( "#widget" ).testWidget( "destroy" );
557561
ok( !div.hasClass( "ui-state-focus" ), "not focused after destroy" );
558-
div.trigger( "focus" );
562+
div.trigger( "focusin" );
559563
ok( !div.hasClass( "ui-state-focus" ), "event handler removed on destroy" );
560564
});
561565

ui/jquery.ui.widget.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ $.Widget.prototype = {
236236
var instance = this;
237237
$.each( handlers, function( event, handler ) {
238238
element.bind( event + "." + instance.widgetName, function() {
239-
if ( instance.options.disabled ) {
239+
// allow widgets to customize the disabled handling
240+
// - disabled as an array instead of boolean
241+
// - disabled class as method for disabling individual parts
242+
if ( instance.options.disabled === true ||
243+
$( this ).hasClass( "ui-state-disabled" ) ) {
240244
return;
241245
}
242246
return ( typeof handler === "string" ? instance[ handler ] : handler )
@@ -260,10 +264,10 @@ $.Widget.prototype = {
260264
_focusable: function( element ) {
261265
this.focusable = this.focusable.add( element );
262266
this._bind( element, {
263-
focus: function( event ) {
267+
focusin: function( event ) {
264268
$( event.currentTarget ).addClass( "ui-state-focus" );
265269
},
266-
blur: function( event ) {
270+
focusout: function( event ) {
267271
$( event.currentTarget ).removeClass( "ui-state-focus" );
268272
}
269273
});

0 commit comments

Comments
 (0)