@@ -409,9 +409,9 @@ describe('ngClick (touch)', function() {
409
409
expect ( $rootScope . count ) . toBe ( 2 ) ;
410
410
} ) ) ;
411
411
412
+ describe ( 'near a input and label' , function ( ) {
412
413
413
- describe ( 'when clicking on a label immediately following a touch event' , function ( ) {
414
- var touch = function ( element , x , y ) {
414
+ function touch ( element , x , y ) {
415
415
time = 10 ;
416
416
browserTrigger ( element , 'touchstart' , {
417
417
keys : [ ] ,
@@ -425,99 +425,129 @@ describe('ngClick (touch)', function() {
425
425
x : x ,
426
426
y : y
427
427
} ) ;
428
- } ;
428
+ }
429
429
430
- var click = function ( element , x , y ) {
430
+ function click ( element , x , y ) {
431
431
browserTrigger ( element , 'click' , {
432
432
keys : [ ] ,
433
433
x : x ,
434
434
y : y
435
435
} ) ;
436
- } ;
436
+ }
437
437
438
- var $rootScope ;
439
- var container , otherElement , input , label ;
440
- beforeEach ( inject ( function ( _$rootScope_ , $compile , $rootElement ) {
441
- $rootScope = _$rootScope_ ;
442
- var container = $compile ( '<div><div ng-click="count = count + 1"></div>' +
443
- '<input id="input1" type="radio" ng-model="selection" value="radio1">' +
444
- '<label for="input1">Input1</label></div>' ) ( $rootScope ) ;
445
- $rootElement . append ( container ) ;
446
- otherElement = container . children ( ) [ 0 ] ;
447
- input = container . children ( ) [ 1 ] ;
448
- label = container . children ( ) [ 2 ] ;
438
+ describe ( 'immediately following a touch event' , function ( ) {
449
439
450
- $rootScope . selection = 'initial' ;
440
+ var $rootScope ;
441
+ var container , otherElement , input , label ;
451
442
452
- $rootScope . $digest ( ) ;
453
- } ) ) ;
443
+ beforeEach ( inject ( function ( _$rootScope_ , $compile , $rootElement ) {
444
+ $rootScope = _$rootScope_ ;
445
+ var container = $compile ( '<div><div ng-click="count = count + 1"></div>' +
446
+ '<input id="input1" type="radio" ng-model="selection" value="radio1">' +
447
+ '<label for="input1">Input1</label></div>' ) ( $rootScope ) ;
448
+ $rootElement . append ( container ) ;
449
+ otherElement = container . children ( ) [ 0 ] ;
450
+ input = container . children ( ) [ 1 ] ;
451
+ label = container . children ( ) [ 2 ] ;
454
452
453
+ $rootScope . selection = 'initial' ;
455
454
456
- afterEach ( function ( ) {
457
- dealoc ( label ) ;
458
- dealoc ( input ) ;
459
- dealoc ( otherElement ) ;
460
- dealoc ( container ) ;
461
- } ) ;
455
+ $rootScope . $digest ( ) ;
456
+ } ) ) ;
462
457
463
458
464
- it ( 'should not cancel input clicks with (0,0) coordinates' , function ( ) {
465
- touch ( otherElement , 100 , 100 ) ;
459
+ afterEach ( function ( ) {
460
+ dealoc ( container ) ;
461
+ } ) ;
466
462
467
- time = 500 ;
468
- click ( label , 10 , 10 ) ;
469
- click ( input , 0 , 0 ) ;
470
463
471
- expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
472
- } ) ;
464
+ it ( 'should not cancel input clicks with (0,0) coordinates' , function ( ) {
465
+ touch ( otherElement , 100 , 100 ) ;
473
466
467
+ time = 500 ;
468
+ click ( label , 10 , 10 ) ;
469
+ click ( input , 0 , 0 ) ;
474
470
475
- it ( 'should not cancel input clicks with negative coordinates' , function ( ) {
476
- touch ( otherElement , 100 , 100 ) ;
471
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
472
+ } ) ;
477
473
478
- time = 500 ;
479
- click ( label , 10 , 10 ) ;
480
- click ( input , - 1 , - 1 ) ;
481
474
482
- expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
483
- } ) ;
475
+ it ( 'should not cancel input clicks with negative coordinates' , function ( ) {
476
+ touch ( otherElement , 100 , 100 ) ;
484
477
478
+ time = 500 ;
479
+ click ( label , 10 , 10 ) ;
480
+ click ( input , - 1 , - 1 ) ;
485
481
486
- it ( 'should not cancel input clicks with positive coordinates identical to label click' , function ( ) {
487
- touch ( otherElement , 100 , 100 ) ;
482
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
483
+ } ) ;
488
484
489
- time = 500 ;
490
- click ( label , 10 , 10 ) ;
491
- click ( input , 10 , 10 ) ;
492
485
493
- expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
494
- } ) ;
486
+ it ( 'should not cancel input clicks with positive coordinates identical to label click' , function ( ) {
487
+ touch ( otherElement , 100 , 100 ) ;
488
+
489
+ time = 500 ;
490
+ click ( label , 10 , 10 ) ;
491
+ click ( input , 10 , 10 ) ;
492
+
493
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
494
+ } ) ;
495
+
495
496
497
+ it ( 'should cancel input clicks with positive coordinates different than label click' , function ( ) {
498
+ touch ( otherElement , 100 , 100 ) ;
496
499
497
- it ( 'should cancel input clicks with positive coordinates different than label click' , function ( ) {
498
- touch ( otherElement , 100 , 100 ) ;
500
+ time = 500 ;
501
+ click ( label , 10 , 10 ) ;
502
+ click ( input , 11 , 11 ) ;
499
503
500
- time = 500 ;
501
- click ( label , 10 , 10 ) ;
502
- click ( input , 11 , 11 ) ;
504
+ expect ( $rootScope . selection ) . toBe ( 'initial' ) ;
505
+ } ) ;
506
+
507
+
508
+ it ( 'should blur the other element on click' , function ( ) {
509
+ var blurSpy = spyOn ( otherElement , 'blur' ) ;
510
+ touch ( otherElement , 10 , 10 ) ;
503
511
504
- expect ( $rootScope . selection ) . toBe ( 'initial' ) ;
512
+ time = 500 ;
513
+ click ( label , 10 , 10 ) ;
514
+
515
+ expect ( blurSpy ) . toHaveBeenCalled ( ) ;
516
+ } ) ;
505
517
} ) ;
506
518
507
519
508
- it ( 'should blur the other element on click' , function ( ) {
509
- var blurSpy = spyOn ( otherElement , 'blur' ) ;
510
- touch ( otherElement , 10 , 10 ) ;
520
+ describe ( 'where label contains the input' , function ( ) {
521
+
522
+ var $rootScope ;
523
+ var container , otherElement , input , label ;
511
524
512
- time = 500 ;
513
- click ( label , 10 , 10 ) ;
525
+ it ( 'should not cancel input clicks with (0,0) coordinates' , inject ( function ( $rootScope , $compile , $rootElement ) {
526
+ var container = $compile ( '<div><div ng-click="count = count + 1"></div>' +
527
+ '<label for="input1">Input1 ' +
528
+ '<input id="input1" type="radio" ng-model="selection" value="radio1">' +
529
+ '</label></div>' ) ( $rootScope ) ;
514
530
515
- expect ( blurSpy ) . toHaveBeenCalled ( ) ;
531
+ $rootElement . append ( container ) ;
532
+ otherElement = container . children ( ) [ 0 ] ;
533
+ label = container . children ( ) . eq ( 1 ) ;
534
+ input = label . children ( ) [ 0 ] ;
535
+
536
+ $rootScope . selection = 'initial' ;
537
+ $rootScope . $digest ( ) ;
538
+
539
+ touch ( otherElement , 100 , 100 ) ;
540
+ click ( input , 0 , 0 ) ;
541
+ click ( label , 10 , 10 ) ;
542
+
543
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
544
+
545
+ dealoc ( container ) ;
546
+ } ) ) ;
516
547
} ) ;
517
548
} ) ;
518
549
} ) ;
519
550
520
-
521
551
describe ( 'click fallback' , function ( ) {
522
552
523
553
it ( 'should treat a click as a tap on desktop' , inject ( function ( $rootScope , $compile ) {
0 commit comments