@@ -19,12 +19,9 @@ describe('MdSelect', () => {
19
19
declarations : [ BasicSelect , NgModelSelect , ManySelects , NgIfSelect ] ,
20
20
providers : [
21
21
{ provide : OverlayContainer , useFactory : ( ) => {
22
- overlayContainerElement = document . createElement ( 'div' ) ;
22
+ overlayContainerElement = document . createElement ( 'div' ) as HTMLElement ;
23
+ overlayContainerElement . classList . add ( 'cdk-overlay-container' ) ;
23
24
24
- // add fixed positioning to match real overlay container styles
25
- overlayContainerElement . style . position = 'fixed' ;
26
- overlayContainerElement . style . top = '0' ;
27
- overlayContainerElement . style . left = '0' ;
28
25
document . body . appendChild ( overlayContainerElement ) ;
29
26
30
27
// remove body padding to keep consistent cross-browser
@@ -561,12 +558,7 @@ describe('MdSelect', () => {
561
558
* @param index The index of the option.
562
559
*/
563
560
function checkTriggerAlignedWithOption ( index : number ) : void {
564
- const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
565
-
566
- // We need to set the position to absolute, because the top/left positioning won't work
567
- // since the component CSS isn't included in the tests.
568
- overlayPane . style . position = 'absolute' ;
569
-
561
+ const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
570
562
const triggerTop = trigger . getBoundingClientRect ( ) . top ;
571
563
const overlayTop = overlayPane . getBoundingClientRect ( ) . top ;
572
564
const options = overlayPane . querySelectorAll ( 'md-option' ) ;
@@ -599,9 +591,7 @@ describe('MdSelect', () => {
599
591
trigger . click ( ) ;
600
592
fixture . detectChanges ( ) ;
601
593
602
- const overlayPane =
603
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
604
- const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
594
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .md-select-panel' ) ;
605
595
606
596
// The panel should be scrolled to 0 because centering the option is not possible.
607
597
expect ( scrollContainer . scrollTop ) . toEqual ( 0 , `Expected panel not to be scrolled.` ) ;
@@ -617,9 +607,7 @@ describe('MdSelect', () => {
617
607
trigger . click ( ) ;
618
608
fixture . detectChanges ( ) ;
619
609
620
- const overlayPane =
621
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
622
- const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
610
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .md-select-panel' ) ;
623
611
624
612
// The panel should be scrolled to 0 because centering the option is not possible.
625
613
expect ( scrollContainer . scrollTop ) . toEqual ( 0 , `Expected panel not to be scrolled.` ) ;
@@ -635,9 +623,7 @@ describe('MdSelect', () => {
635
623
trigger . click ( ) ;
636
624
fixture . detectChanges ( ) ;
637
625
638
- const overlayPane =
639
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
640
- const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
626
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .md-select-panel' ) ;
641
627
642
628
// The selected option should be scrolled to the center of the panel.
643
629
// This will be its original offset from the scrollTop - half the panel height + half the
@@ -657,9 +643,7 @@ describe('MdSelect', () => {
657
643
trigger . click ( ) ;
658
644
fixture . detectChanges ( ) ;
659
645
660
- const overlayPane =
661
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
662
- const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
646
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .md-select-panel' ) ;
663
647
664
648
// The selected option should be scrolled to the max scroll position.
665
649
// This will be the height of the scrollContainer - the panel height.
@@ -691,9 +675,7 @@ describe('MdSelect', () => {
691
675
trigger . click ( ) ;
692
676
fixture . detectChanges ( ) ;
693
677
694
- const overlayPane =
695
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
696
- const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
678
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .md-select-panel' ) ;
697
679
698
680
// Scroll should adjust by the difference between the top space available (85px + 8px
699
681
// viewport padding = 77px) and the height of the panel above the option (113px).
@@ -716,9 +698,7 @@ describe('MdSelect', () => {
716
698
trigger . click ( ) ;
717
699
fixture . detectChanges ( ) ;
718
700
719
- const overlayPane =
720
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
721
- const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
701
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .md-select-panel' ) ;
722
702
723
703
// Scroll should adjust by the difference between the bottom space available
724
704
// (686px - 600px margin - 30px trigger height = 56px - 8px padding = 48px)
@@ -742,13 +722,7 @@ describe('MdSelect', () => {
742
722
trigger . click ( ) ;
743
723
fixture . detectChanges ( ) ;
744
724
745
- const overlayPane =
746
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
747
-
748
- // We need to set the position to absolute, because the top/left positioning won't work
749
- // since the component CSS isn't included in the tests.
750
- overlayPane . style . position = 'absolute' ;
751
-
725
+ const overlayPane = document . querySelector ( '.cdk-overlay-pane' ) ;
752
726
const triggerBottom = trigger . getBoundingClientRect ( ) . bottom ;
753
727
const overlayBottom = overlayPane . getBoundingClientRect ( ) . bottom ;
754
728
const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
@@ -775,13 +749,7 @@ describe('MdSelect', () => {
775
749
trigger . click ( ) ;
776
750
fixture . detectChanges ( ) ;
777
751
778
- const overlayPane =
779
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
780
-
781
- // We need to set the position to absolute, because the top/left positioning won't work
782
- // since the component CSS isn't included in the tests.
783
- overlayPane . style . position = 'absolute' ;
784
-
752
+ const overlayPane = document . querySelector ( '.cdk-overlay-pane' ) ;
785
753
const triggerTop = trigger . getBoundingClientRect ( ) . top ;
786
754
const overlayTop = overlayPane . getBoundingClientRect ( ) . top ;
787
755
const scrollContainer = overlayPane . querySelector ( '.md-select-panel' ) ;
@@ -864,11 +832,7 @@ describe('MdSelect', () => {
864
832
trigger . click ( ) ;
865
833
fixture . detectChanges ( ) ;
866
834
867
- // CSS styles aren't in the tests, so position must be absolute to reflect top/left
868
- const overlayPane =
869
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
870
- overlayPane . style . position = 'absolute' ;
871
-
835
+ const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
872
836
const triggerBottom = trigger . getBoundingClientRect ( ) . bottom ;
873
837
const overlayBottom = overlayPane . getBoundingClientRect ( ) . bottom ;
874
838
@@ -892,11 +856,7 @@ describe('MdSelect', () => {
892
856
trigger . click ( ) ;
893
857
fixture . detectChanges ( ) ;
894
858
895
- // CSS styles aren't in the tests, so position must be absolute to reflect top/left
896
- const overlayPane =
897
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
898
- overlayPane . style . position = 'absolute' ;
899
-
859
+ const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
900
860
const triggerTop = trigger . getBoundingClientRect ( ) . top ;
901
861
const overlayTop = overlayPane . getBoundingClientRect ( ) . top ;
902
862
@@ -916,16 +876,9 @@ describe('MdSelect', () => {
916
876
trigger . click ( ) ;
917
877
fixture . detectChanges ( ) ;
918
878
919
- const overlayPane =
920
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
921
-
922
- // We need to set the position to absolute, because the top/left positioning won't work
923
- // since the component CSS isn't included in the tests.
924
- overlayPane . style . position = 'absolute' ;
925
-
926
879
const triggerLeft = trigger . getBoundingClientRect ( ) . left ;
927
880
const firstOptionLeft =
928
- overlayPane . querySelector ( 'md-option' ) . getBoundingClientRect ( ) . left ;
881
+ document . querySelector ( '.cdk-overlay-pane md-option' ) . getBoundingClientRect ( ) . left ;
929
882
930
883
// Each option is 32px wider than the trigger, so it must be adjusted 16px
931
884
// to ensure the text overlaps correctly.
@@ -940,16 +893,9 @@ describe('MdSelect', () => {
940
893
trigger . click ( ) ;
941
894
fixture . detectChanges ( ) ;
942
895
943
- const overlayPane =
944
- overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
945
-
946
- // We need to set the position to absolute, because the top/left positioning won't work
947
- // since the component CSS isn't included in the tests.
948
- overlayPane . style . position = 'absolute' ;
949
-
950
896
const triggerRight = trigger . getBoundingClientRect ( ) . right ;
951
897
const firstOptionRight =
952
- overlayPane . querySelector ( 'md-option' ) . getBoundingClientRect ( ) . right ;
898
+ document . querySelector ( '.cdk-overlay-pane md-option' ) . getBoundingClientRect ( ) . right ;
953
899
954
900
// Each option is 32px wider than the trigger, so it must be adjusted 16px
955
901
// to ensure the text overlaps correctly.
0 commit comments