@@ -289,9 +289,9 @@ export function main() {
289289 expect ( el . nativeElement . className ) . toContain ( 'md-checkbox-disabled' ) ;
290290 } ) ;
291291
292- it ( 'sets the tabindex to -1 on the host element' , function ( ) {
292+ it ( 'removes the tabindex attribute from the host element' , function ( ) {
293293 let el = fixture . debugElement . query ( By . css ( '.md-checkbox' ) ) ;
294- expect ( el . nativeElement . getAttribute ( 'tabindex' ) ) . toEqual ( '-1' ) ;
294+ expect ( el . nativeElement . hasAttribute ( 'tabindex' ) ) . toBe ( false ) ;
295295 } ) ;
296296
297297 it ( 'sets "aria-disabled" to "true" on the host element' , function ( ) {
@@ -307,7 +307,7 @@ export function main() {
307307 tabindexController . isDisabled = true ;
308308 fixture . detectChanges ( ) ;
309309 let el = fixture . debugElement . query ( By . css ( '.md-checkbox' ) ) ;
310- expect ( el . nativeElement . getAttribute ( 'tabindex' ) ) . toEqual ( '-1' ) ;
310+ expect ( el . nativeElement . hasAttribute ( 'tabindex' ) ) . toBe ( false ) ;
311311
312312 tabindexController . isDisabled = false ;
313313 fixture . detectChanges ( ) ;
@@ -334,9 +334,9 @@ export function main() {
334334 } ) . then ( done ) . catch ( done ) ;
335335 } ) ;
336336
337- it ( 'keeps the tabindex at -1 ' , function ( ) {
337+ it ( 'keeps the tabindex removed from the host ' , function ( ) {
338338 let el = fixture . debugElement . query ( By . css ( '.md-checkbox' ) ) ;
339- expect ( el . nativeElement . getAttribute ( 'tabindex' ) ) . toEqual ( '-1' ) ;
339+ expect ( el . nativeElement . hasAttribute ( 'tabindex' ) ) . toBe ( false ) ;
340340 } ) ;
341341
342342 it ( 'uses the newly changed tabindex when re-enabled' , function ( ) {
@@ -394,6 +394,48 @@ export function main() {
394394 } ) ;
395395 } ) ;
396396
397+ describe ( 'when the checkbox is focused' , function ( ) {
398+ var fixture : ComponentFixture ;
399+ var controller : CheckboxController ;
400+ var el : DebugElement ;
401+
402+ function dispatchUIEventOnEl ( evtName : string ) {
403+ var evt : Event ;
404+ if ( BROWSER_SUPPORTS_EVENT_CONSTRUCTORS ) {
405+ evt = new Event ( evtName ) ;
406+ } else {
407+ evt = document . createEvent ( 'Event' ) ;
408+ evt . initEvent ( evtName , true , true ) ;
409+ }
410+ el . nativeElement . dispatchEvent ( evt ) ;
411+ fixture . detectChanges ( ) ;
412+ }
413+
414+ beforeEach ( function ( done : ( ) => void ) {
415+ builder . createAsync ( CheckboxController ) . then ( function ( f ) {
416+ fixture = f ;
417+ controller = fixture . componentInstance ;
418+
419+ fixture . detectChanges ( ) ;
420+ el = fixture . debugElement . query ( By . css ( '.md-checkbox' ) ) ;
421+ } ) . then ( done ) . catch ( done ) ;
422+ } ) ;
423+
424+ it ( 'blocks spacebar keydown events from performing their default behavior' , function ( ) {
425+ dispatchUIEventOnEl ( 'focus' ) ;
426+
427+ var evt = keydown ( el , ' ' , fixture ) ;
428+ expect ( evt . preventDefault ) . toHaveBeenCalled ( ) ;
429+ } ) ;
430+
431+ it ( 'does not block other keyboard events from performing their default behavior' , function ( ) {
432+ dispatchUIEventOnEl ( 'focus' ) ;
433+
434+ var evt = keydown ( el , 'Tab' , fixture ) ;
435+ expect ( evt . preventDefault ) . not . toHaveBeenCalled ( ) ;
436+ } ) ;
437+ } ) ;
438+
397439 describe ( 'when a spacebar press occurs on the checkbox' , function ( ) {
398440 var fixture : ComponentFixture ;
399441 var controller : CheckboxController ;
@@ -597,27 +639,36 @@ function click(el: DebugElement, fixture: ComponentFixture) {
597639}
598640
599641// TODO(traviskaufman): Reinvestigate implementation of this method once tests in Dart begin to run.
600- function keyup ( el : DebugElement , key : string , fixture : ComponentFixture ) {
642+ function keyEvent ( name : string , el : DebugElement , key : string , fixture : ComponentFixture ) : Event {
601643 var kbdEvent : Event ;
602644 if ( BROWSER_SUPPORTS_EVENT_CONSTRUCTORS ) {
603- kbdEvent = new KeyboardEvent ( 'keyup' ) ;
645+ kbdEvent = new KeyboardEvent ( name ) ;
604646 } else {
605- kbdEvent = document . createEvent ( 'Events ' ) ;
606- kbdEvent . initEvent ( 'keyup' , true , true ) ;
647+ kbdEvent = document . createEvent ( 'Event ' ) ;
648+ kbdEvent . initEvent ( name , true , true ) ;
607649 }
608650 // Hack DOM Level 3 Events "key" prop into keyboard event.
609651 Object . defineProperty ( kbdEvent , 'key' , {
610- value : ' ' ,
652+ value : key ,
611653 enumerable : false ,
612654 writable : false ,
613655 configurable : true
614656 } ) ;
657+ spyOn ( kbdEvent , 'preventDefault' ) . and . callThrough ( ) ;
615658 spyOn ( kbdEvent , 'stopPropagation' ) . and . callThrough ( ) ;
616659 el . nativeElement . dispatchEvent ( kbdEvent ) ;
617660 fixture . detectChanges ( ) ;
618661 return kbdEvent ;
619662}
620663
664+ function keydown ( el : DebugElement , key : string , fixture : ComponentFixture ) : Event {
665+ return keyEvent ( 'keydown' , el , key , fixture ) ;
666+ }
667+
668+ function keyup ( el : DebugElement , key : string , fixture : ComponentFixture ) : Event {
669+ return keyEvent ( 'keyup' , el , key , fixture ) ;
670+ }
671+
621672@Component ( {
622673 selector : 'checkbox-controller' ,
623674 template : `
0 commit comments