Skip to content

Commit ad947c7

Browse files
ruprictscottgonzalez
authored andcommitted
Button: modified the event bindings for focus and blur. Fixed #6711 - checkbox/radio button do not show focused state when using Keyboard Navigation
(cherry picked from commit c49dbe0)
1 parent bb076e3 commit ad947c7

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

tests/unit/button/button_tickets.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ test( "#6262 - buttonset not applying ui-corner to invisible elements", function
2020
ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) );
2121
});
2222

23+
test( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() {
24+
var check = $( "#check" ).button(),
25+
label = $( "label[for='check']" );
26+
ok( !label.is( ".ui-state-focus" ) );
27+
check.focus();
28+
ok( label.is( ".ui-state-focus" ) );
29+
});
30+
2331
test( "#7092 - button creation that requires a matching label does not find label in all cases", function() {
2432
var group = $( "<span><label for='t7092a'/><input type='checkbox' id='t7092a'/></span>" );
2533
group.find( "input:checkbox" ).button();

ui/jquery.ui.button.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,21 @@ $.widget( "ui.button", {
9494
}
9595
$( this ).removeClass( hoverClass );
9696
})
97-
.bind( "focus.button", function() {
98-
// no need to check disabled, focus won't be triggered anyway
99-
$( this ).addClass( focusClass );
100-
})
101-
.bind( "blur.button", function() {
102-
$( this ).removeClass( focusClass );
103-
})
10497
.bind( "click.button", function( event ) {
10598
if ( options.disabled ) {
10699
event.stopImmediatePropagation();
107100
}
108101
});
109102

103+
this.element
104+
.bind( "focus.button", function() {
105+
// no need to check disabled, focus won't be triggered anyway
106+
self.buttonElement.addClass( focusClass );
107+
})
108+
.bind( "blur.button", function() {
109+
self.buttonElement.removeClass( focusClass );
110+
});
111+
110112
if ( toggleButton ) {
111113
this.element.bind( "change.button", function() {
112114
if ( clickDragged ) {

0 commit comments

Comments
 (0)