@@ -289,9 +289,9 @@ export function main() {
289
289
expect ( el . nativeElement . className ) . toContain ( 'md-checkbox-disabled' ) ;
290
290
} ) ;
291
291
292
- it ( 'sets the tabindex to -1 on the host element' , function ( ) {
292
+ it ( 'removes the tabindex attribute from the host element' , function ( ) {
293
293
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 ) ;
295
295
} ) ;
296
296
297
297
it ( 'sets "aria-disabled" to "true" on the host element' , function ( ) {
@@ -307,7 +307,7 @@ export function main() {
307
307
tabindexController . isDisabled = true ;
308
308
fixture . detectChanges ( ) ;
309
309
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 ) ;
311
311
312
312
tabindexController . isDisabled = false ;
313
313
fixture . detectChanges ( ) ;
@@ -334,9 +334,9 @@ export function main() {
334
334
} ) . then ( done ) . catch ( done ) ;
335
335
} ) ;
336
336
337
- it ( 'keeps the tabindex at -1 ' , function ( ) {
337
+ it ( 'keeps the tabindex removed from the host ' , function ( ) {
338
338
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 ) ;
340
340
} ) ;
341
341
342
342
it ( 'uses the newly changed tabindex when re-enabled' , function ( ) {
@@ -394,6 +394,48 @@ export function main() {
394
394
} ) ;
395
395
} ) ;
396
396
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
+
397
439
describe ( 'when a spacebar press occurs on the checkbox' , function ( ) {
398
440
var fixture : ComponentFixture ;
399
441
var controller : CheckboxController ;
@@ -597,27 +639,36 @@ function click(el: DebugElement, fixture: ComponentFixture) {
597
639
}
598
640
599
641
// 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 {
601
643
var kbdEvent : Event ;
602
644
if ( BROWSER_SUPPORTS_EVENT_CONSTRUCTORS ) {
603
- kbdEvent = new KeyboardEvent ( 'keyup' ) ;
645
+ kbdEvent = new KeyboardEvent ( name ) ;
604
646
} else {
605
- kbdEvent = document . createEvent ( 'Events ' ) ;
606
- kbdEvent . initEvent ( 'keyup' , true , true ) ;
647
+ kbdEvent = document . createEvent ( 'Event ' ) ;
648
+ kbdEvent . initEvent ( name , true , true ) ;
607
649
}
608
650
// Hack DOM Level 3 Events "key" prop into keyboard event.
609
651
Object . defineProperty ( kbdEvent , 'key' , {
610
- value : ' ' ,
652
+ value : key ,
611
653
enumerable : false ,
612
654
writable : false ,
613
655
configurable : true
614
656
} ) ;
657
+ spyOn ( kbdEvent , 'preventDefault' ) . and . callThrough ( ) ;
615
658
spyOn ( kbdEvent , 'stopPropagation' ) . and . callThrough ( ) ;
616
659
el . nativeElement . dispatchEvent ( kbdEvent ) ;
617
660
fixture . detectChanges ( ) ;
618
661
return kbdEvent ;
619
662
}
620
663
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
+
621
672
@Component ( {
622
673
selector : 'checkbox-controller' ,
623
674
template : `
0 commit comments