Skip to content

Commit

Permalink
Button: modified the event bindings for focus and blur. Fixed #6711 -…
Browse files Browse the repository at this point in the history
… checkbox/radio button do not show focused state when using Keyboard Navigation

(cherry picked from commit c49dbe0)
  • Loading branch information
ruprict authored and scottgonzalez committed May 26, 2011
1 parent bb076e3 commit ad947c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tests/unit/button/button_tickets.js
Expand Up @@ -20,6 +20,14 @@ test( "#6262 - buttonset not applying ui-corner to invisible elements", function
ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) ); ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) );
}); });


test( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() {
var check = $( "#check" ).button(),
label = $( "label[for='check']" );
ok( !label.is( ".ui-state-focus" ) );
check.focus();
ok( label.is( ".ui-state-focus" ) );
});

test( "#7092 - button creation that requires a matching label does not find label in all cases", function() { test( "#7092 - button creation that requires a matching label does not find label in all cases", function() {
var group = $( "<span><label for='t7092a'/><input type='checkbox' id='t7092a'/></span>" ); var group = $( "<span><label for='t7092a'/><input type='checkbox' id='t7092a'/></span>" );
group.find( "input:checkbox" ).button(); group.find( "input:checkbox" ).button();
Expand Down
16 changes: 9 additions & 7 deletions ui/jquery.ui.button.js
Expand Up @@ -94,19 +94,21 @@ $.widget( "ui.button", {
} }
$( this ).removeClass( hoverClass ); $( this ).removeClass( hoverClass );
}) })
.bind( "focus.button", function() {
// no need to check disabled, focus won't be triggered anyway
$( this ).addClass( focusClass );
})
.bind( "blur.button", function() {
$( this ).removeClass( focusClass );
})
.bind( "click.button", function( event ) { .bind( "click.button", function( event ) {
if ( options.disabled ) { if ( options.disabled ) {
event.stopImmediatePropagation(); event.stopImmediatePropagation();
} }
}); });


this.element
.bind( "focus.button", function() {
// no need to check disabled, focus won't be triggered anyway
self.buttonElement.addClass( focusClass );
})
.bind( "blur.button", function() {
self.buttonElement.removeClass( focusClass );
});

if ( toggleButton ) { if ( toggleButton ) {
this.element.bind( "change.button", function() { this.element.bind( "change.button", function() {
if ( clickDragged ) { if ( clickDragged ) {
Expand Down

0 comments on commit ad947c7

Please sign in to comment.