@@ -645,23 +645,21 @@ describe('igxOverlay', () => {
645
645
}
646
646
} ) ) ;
647
647
648
- it ( 'The shown component is in the center of igx-overlay (visible window) - default.' , ( ) => {
648
+ it ( 'The shown component is in the center of igx-overlay (visible window) - default.' , fakeAsync ( ( ) => {
649
649
const fixture = TestBed . createComponent ( EmptyPageComponent ) ;
650
650
fixture . detectChanges ( ) ;
651
651
fixture . componentInstance . overlay . show ( SimpleDynamicComponent ) ;
652
- fixture . whenStable ( ) . then ( ( ) => {
653
- fixture . detectChanges ( ) ;
654
- const overlayDiv = document . getElementsByClassName ( CLASS_OVERLAY_MAIN ) [ 0 ] ;
655
- const overlayWrapper = overlayDiv . children [ 0 ] as HTMLElement ;
656
- const componentEl = overlayWrapper . children [ 0 ] . children [ 0 ] ;
657
- const wrapperRect = overlayWrapper . getBoundingClientRect ( ) ;
658
- const componentRect = componentEl . getBoundingClientRect ( ) ;
659
- expect ( wrapperRect . width / 2 ) . toEqual ( componentRect . left ) ;
660
- expect ( wrapperRect . height / 2 ) . toEqual ( componentRect . top ) ;
661
- expect ( componentRect . left ) . toEqual ( componentRect . right - componentRect . width ) ;
662
- expect ( componentRect . top ) . toEqual ( componentRect . bottom - componentRect . height ) ;
663
- } ) ;
664
- } ) ;
652
+ tick ( ) ;
653
+ const overlayDiv = document . getElementsByClassName ( CLASS_OVERLAY_MAIN ) [ 0 ] ;
654
+ const overlayWrapper = overlayDiv . children [ 0 ] as HTMLElement ;
655
+ const componentEl = overlayWrapper . children [ 0 ] . children [ 0 ] ;
656
+ const wrapperRect = overlayWrapper . getBoundingClientRect ( ) ;
657
+ const componentRect = componentEl . getBoundingClientRect ( ) ;
658
+ expect ( wrapperRect . width / 2 - componentRect . width / 2 ) . toEqual ( componentRect . left ) ;
659
+ expect ( wrapperRect . height / 2 - componentRect . height / 2 ) . toEqual ( componentRect . top ) ;
660
+ expect ( componentRect . left ) . toEqual ( componentRect . right - componentRect . width ) ;
661
+ expect ( componentRect . top ) . toEqual ( componentRect . bottom - componentRect . height ) ;
662
+ } ) ) ;
665
663
666
664
it ( 'When adding a new instance of a component with the same options, it is rendered exactly on top of the previous one.' , ( ) => {
667
665
const fixture = TestBed . createComponent ( EmptyPageComponent ) ;
@@ -697,8 +695,10 @@ describe('igxOverlay', () => {
697
695
const componentEl = overlayWrapper . children [ 0 ] . children [ 0 ] ;
698
696
const wrapperRect = overlayWrapper . getBoundingClientRect ( ) ;
699
697
const componentRect = componentEl . getBoundingClientRect ( ) ;
700
- expect ( wrapperRect . width / 2 ) . toEqual ( componentRect . left ) ;
701
- expect ( wrapperRect . height / 2 ) . toEqual ( componentRect . top ) ;
698
+ expect ( componentRect . left ) . toBeLessThan ( 0 ) ;
699
+ expect ( wrapperRect . width / 2 ) . toEqual ( componentRect . left + componentRect . width / 2 ) ;
700
+ expect ( componentRect . top ) . toBeLessThan ( 0 ) ;
701
+ expect ( wrapperRect . height / 2 ) . toEqual ( componentRect . top + componentRect . height / 2 ) ;
702
702
hasScrollbar = document . body . scrollHeight > document . body . clientHeight ;
703
703
expect ( hasScrollbar ) . toBeTruthy ( ) ;
704
704
} ) ;
@@ -1746,6 +1746,26 @@ describe('igxOverlay', () => {
1746
1746
xit ( 'Css should not leak: From shown components to igx-overlay.' , ( ) => {
1747
1747
// TO DO
1748
1748
} ) ;
1749
+
1750
+ it ( 'Components with 100% width/height should use their initial container\'s properties when placed inside of the overlay element' ,
1751
+ fakeAsync ( ( ) => {
1752
+ const fixture = TestBed . createComponent ( WidthTestOverlayComponent ) ;
1753
+ fixture . detectChanges ( ) ;
1754
+ expect ( fixture . componentInstance . customComponent ) . toBeDefined ( ) ;
1755
+ expect ( fixture . componentInstance . customComponent . nativeElement . style . width ) . toEqual ( '100%' ) ;
1756
+ expect ( fixture . componentInstance . customComponent . nativeElement . getBoundingClientRect ( ) . width ) . toEqual ( 420 ) ;
1757
+ expect ( fixture . componentInstance . customComponent . nativeElement . style . height ) . toEqual ( '100%' ) ;
1758
+ expect ( fixture . componentInstance . customComponent . nativeElement . getBoundingClientRect ( ) . height ) . toEqual ( 280 ) ;
1759
+ fixture . componentInstance . buttonElement . nativeElement . click ( ) ;
1760
+ tick ( ) ;
1761
+ const overlayContent = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) [ 0 ] as HTMLElement ;
1762
+ const overlayChild = overlayContent . lastElementChild as HTMLElement ;
1763
+ expect ( overlayChild ) . toBeDefined ( ) ;
1764
+ expect ( overlayChild . style . width ) . toEqual ( '100%' ) ;
1765
+ expect ( overlayChild . getBoundingClientRect ( ) . width ) . toEqual ( 420 ) ;
1766
+ expect ( overlayChild . style . height ) . toEqual ( '100%' ) ;
1767
+ expect ( overlayChild . getBoundingClientRect ( ) . height ) . toEqual ( 280 ) ;
1768
+ } ) ) ;
1749
1769
} ) ;
1750
1770
} ) ;
1751
1771
@@ -1867,13 +1887,49 @@ export class TopLeftOffsetComponent {
1867
1887
}
1868
1888
}
1869
1889
1890
+ @Component ( {
1891
+ template : `<div style="width: 420px; height: 280px;">
1892
+ <button class='300_button' igxToggle #button (click)=\'click($event)\'>Show Overlay</button>
1893
+ <div #myCustomComponent class="customList" style="width: 100%; height: 100%;">
1894
+ Some Content
1895
+ </div>
1896
+ <div>` ,
1897
+ styles : [ `button {
1898
+ position: absolute;
1899
+ top: 300px;
1900
+ left: 300px;
1901
+ width: 100px;
1902
+ height: 60px;
1903
+ border: 0px;
1904
+ }` ]
1905
+ } )
1906
+ export class WidthTestOverlayComponent {
1907
+
1908
+ constructor ( @Inject ( IgxOverlayService ) public overlay : IgxOverlayService ) { }
1909
+
1910
+ @ViewChild ( 'button' ) buttonElement : ElementRef ;
1911
+ @ViewChild ( 'myCustomComponent' ) customComponent : ElementRef ;
1912
+ click ( event ) {
1913
+ const overlaySettings : OverlaySettings = {
1914
+ positionStrategy : new ConnectedPositioningStrategy ( ) ,
1915
+ scrollStrategy : new NoOpScrollStrategy ( ) ,
1916
+ closeOnOutsideClick : true ,
1917
+ modal : false
1918
+ } ;
1919
+
1920
+ overlaySettings . positionStrategy . settings . target = this . buttonElement . nativeElement ;
1921
+ this . overlay . show ( this . customComponent , overlaySettings ) ;
1922
+ }
1923
+ }
1924
+
1870
1925
const DYNAMIC_COMPONENTS = [
1871
1926
EmptyPageComponent ,
1872
1927
SimpleRefComponent ,
1873
1928
SimpleDynamicComponent ,
1874
1929
SimpleBigSizeComponent ,
1875
1930
DownRightButtonComponent ,
1876
- TopLeftOffsetComponent
1931
+ TopLeftOffsetComponent ,
1932
+ WidthTestOverlayComponent
1877
1933
] ;
1878
1934
1879
1935
const DIRECTIVE_COMPONENTS = [
0 commit comments