@@ -1799,6 +1799,149 @@ describe('FlexibleConnectedPositionStrategy', () => {
1799
1799
} ) ;
1800
1800
} ) ;
1801
1801
1802
+ describe ( 'panel classes' , ( ) => {
1803
+ let originElement : HTMLElement ;
1804
+ let positionStrategy : FlexibleConnectedPositionStrategy ;
1805
+
1806
+ beforeEach ( ( ) => {
1807
+ originElement = createPositionedBlockElement ( ) ;
1808
+ document . body . appendChild ( originElement ) ;
1809
+ positionStrategy = overlay . position ( )
1810
+ . flexibleConnectedTo ( originElement )
1811
+ . withFlexibleDimensions ( false )
1812
+ . withPush ( false ) ;
1813
+ } ) ;
1814
+
1815
+ afterEach ( ( ) => {
1816
+ document . body . removeChild ( originElement ) ;
1817
+ } ) ;
1818
+
1819
+ it ( 'should be able to apply a class based on the position' , ( ) => {
1820
+ positionStrategy . withPositions ( [ {
1821
+ originX : 'start' ,
1822
+ originY : 'bottom' ,
1823
+ overlayX : 'start' ,
1824
+ overlayY : 'top' ,
1825
+ panelClass : 'is-below'
1826
+ } ] ) ;
1827
+
1828
+ attachOverlay ( { positionStrategy} ) ;
1829
+
1830
+ expect ( overlayRef . overlayElement . classList ) . toContain ( 'is-below' ) ;
1831
+ } ) ;
1832
+
1833
+ it ( 'should be able to apply multiple classes based on the position' , ( ) => {
1834
+ positionStrategy . withPositions ( [ {
1835
+ originX : 'start' ,
1836
+ originY : 'bottom' ,
1837
+ overlayX : 'start' ,
1838
+ overlayY : 'top' ,
1839
+ panelClass : [ 'is-below' , 'is-under' ]
1840
+ } ] ) ;
1841
+
1842
+ attachOverlay ( { positionStrategy} ) ;
1843
+
1844
+ expect ( overlayRef . overlayElement . classList ) . toContain ( 'is-below' ) ;
1845
+ expect ( overlayRef . overlayElement . classList ) . toContain ( 'is-under' ) ;
1846
+ } ) ;
1847
+
1848
+ it ( 'should remove the panel class when detaching' , ( ) => {
1849
+ positionStrategy . withPositions ( [ {
1850
+ originX : 'start' ,
1851
+ originY : 'bottom' ,
1852
+ overlayX : 'start' ,
1853
+ overlayY : 'top' ,
1854
+ panelClass : 'is-below'
1855
+ } ] ) ;
1856
+
1857
+ attachOverlay ( { positionStrategy} ) ;
1858
+ expect ( overlayRef . overlayElement . classList ) . toContain ( 'is-below' ) ;
1859
+
1860
+ overlayRef . detach ( ) ;
1861
+ expect ( overlayRef . overlayElement . classList ) . not . toContain ( 'is-below' ) ;
1862
+ } ) ;
1863
+
1864
+ it ( 'should clear the previous classes when the position changes' , ( ) => {
1865
+ originElement . style . top = '200px' ;
1866
+ originElement . style . right = '25px' ;
1867
+
1868
+ positionStrategy . withPositions ( [
1869
+ {
1870
+ originX : 'end' ,
1871
+ originY : 'center' ,
1872
+ overlayX : 'start' ,
1873
+ overlayY : 'center' ,
1874
+ panelClass : [ 'is-center' , 'is-in-the-middle' ]
1875
+ } ,
1876
+ {
1877
+ originX : 'start' ,
1878
+ originY : 'bottom' ,
1879
+ overlayX : 'end' ,
1880
+ overlayY : 'top' ,
1881
+ panelClass : 'is-below'
1882
+ }
1883
+ ] ) ;
1884
+
1885
+ attachOverlay ( { positionStrategy} ) ;
1886
+
1887
+ const overlayClassList = overlayRef . overlayElement . classList ;
1888
+
1889
+ expect ( overlayClassList ) . not . toContain ( 'is-center' ) ;
1890
+ expect ( overlayClassList ) . not . toContain ( 'is-in-the-middle' ) ;
1891
+ expect ( overlayClassList ) . toContain ( 'is-below' ) ;
1892
+
1893
+ // Move the element so another position is applied.
1894
+ originElement . style . top = '200px' ;
1895
+ originElement . style . left = '200px' ;
1896
+
1897
+ overlayRef . updatePosition ( ) ;
1898
+
1899
+ expect ( overlayClassList ) . toContain ( 'is-center' ) ;
1900
+ expect ( overlayClassList ) . toContain ( 'is-in-the-middle' ) ;
1901
+ expect ( overlayClassList ) . not . toContain ( 'is-below' ) ;
1902
+ } ) ;
1903
+
1904
+ it ( 'should not clear the existing `panelClass` from the `OverlayRef`' , ( ) => {
1905
+ originElement . style . top = '200px' ;
1906
+ originElement . style . right = '25px' ;
1907
+
1908
+ positionStrategy . withPositions ( [
1909
+ {
1910
+ originX : 'end' ,
1911
+ originY : 'center' ,
1912
+ overlayX : 'start' ,
1913
+ overlayY : 'center' ,
1914
+ panelClass : [ 'is-center' , 'is-in-the-middle' ]
1915
+ } ,
1916
+ {
1917
+ originX : 'start' ,
1918
+ originY : 'bottom' ,
1919
+ overlayX : 'end' ,
1920
+ overlayY : 'top' ,
1921
+ panelClass : 'is-below'
1922
+ }
1923
+ ] ) ;
1924
+
1925
+ attachOverlay ( {
1926
+ panelClass : 'custom-panel-class' ,
1927
+ positionStrategy
1928
+ } ) ;
1929
+
1930
+ const overlayClassList = overlayRef . overlayElement . classList ;
1931
+
1932
+ expect ( overlayClassList ) . toContain ( 'custom-panel-class' ) ;
1933
+
1934
+ // Move the element so another position is applied.
1935
+ originElement . style . top = '200px' ;
1936
+ originElement . style . left = '200px' ;
1937
+
1938
+ overlayRef . updatePosition ( ) ;
1939
+
1940
+ expect ( overlayClassList ) . toContain ( 'custom-panel-class' ) ;
1941
+ } ) ;
1942
+
1943
+ } ) ;
1944
+
1802
1945
} ) ;
1803
1946
1804
1947
/** Creates an absolutely positioned, display: block element with a default size. */
0 commit comments