@@ -13,6 +13,7 @@ describe('$mdPanel', function() {
13
13
var DEFAULT_CONFIG = { template : DEFAULT_TEMPLATE } ;
14
14
var PANEL_ID_PREFIX = 'panel_' ;
15
15
var SCROLL_MASK_CLASS = '.md-scroll-mask' ;
16
+ var ADJUSTED_CLASS = '_md-panel-position-adjusted' ;
16
17
17
18
/**
18
19
* @param {!angular.$injector } $injector
@@ -1261,6 +1262,7 @@ describe('$mdPanel', function() {
1261
1262
myButton = '<button>myButton</button>' ;
1262
1263
attachToBody ( myButton ) ;
1263
1264
myButton = angular . element ( document . querySelector ( 'button' ) ) ;
1265
+ myButton . css ( 'margin' , '100px' ) ;
1264
1266
myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1265
1267
} ) ;
1266
1268
@@ -1310,6 +1312,7 @@ describe('$mdPanel', function() {
1310
1312
expect ( panelRect . top ) . toBeApproximately ( myButtonRect . top ) ;
1311
1313
expect ( panelRect . left ) . toBeApproximately ( myButtonRect . left ) ;
1312
1314
1315
+
1313
1316
var newPosition = $mdPanel . newPanelPosition ( )
1314
1317
. relativeTo ( myButton )
1315
1318
. addPanelPosition ( null , yPosition . ABOVE ) ;
@@ -1669,6 +1672,7 @@ describe('$mdPanel', function() {
1669
1672
myButton = '<button>myButton</button>' ;
1670
1673
attachToBody ( myButton ) ;
1671
1674
myButton = angular . element ( document . querySelector ( 'button' ) ) ;
1675
+ myButton . css ( 'margin' , '100px' ) ;
1672
1676
myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1673
1677
1674
1678
xPosition = $mdPanel . xPosition ;
@@ -1717,100 +1721,108 @@ describe('$mdPanel', function() {
1717
1721
expect ( panelCss . top ) . toBeApproximately ( myButtonRect . top ) ;
1718
1722
} ) ;
1719
1723
1720
- it ( 'rejects offscreen position left of target element ', function ( ) {
1721
- var position = mdPanelPosition
1722
- . relativeTo ( myButton )
1723
- . addPanelPosition ( xPosition . OFFSET_START , yPosition . ALIGN_TOPS )
1724
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1724
+ describe ( 'fallback positions ', function ( ) {
1725
+ beforeEach ( function ( ) {
1726
+ myButton . css ( 'margin' , 0 ) ;
1727
+ myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1728
+ } ) ;
1725
1729
1726
- config [ 'position' ] = position ;
1730
+ it ( 'rejects offscreen position left of target element' , function ( ) {
1731
+ var position = mdPanelPosition
1732
+ . relativeTo ( myButton )
1733
+ . addPanelPosition ( xPosition . OFFSET_START , yPosition . ALIGN_TOPS )
1734
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1727
1735
1728
- openPanel ( config ) ;
1736
+ config [ 'position' ] = position ;
1737
+
1738
+ openPanel ( config ) ;
1739
+
1740
+ expect ( position . getActualPosition ( ) ) . toEqual ( {
1741
+ x : xPosition . ALIGN_START ,
1742
+ y : yPosition . ALIGN_TOPS ,
1743
+ } ) ;
1729
1744
1730
- expect ( position . getActualPosition ( ) ) . toEqual ( {
1731
- x : xPosition . ALIGN_START ,
1732
- y : yPosition . ALIGN_TOPS ,
1745
+ var panelCss = document . querySelector ( PANEL_EL ) . style ;
1746
+ expect ( panelCss . left ) . toBeApproximately ( myButtonRect . left ) ;
1747
+ expect ( panelCss . top ) . toBeApproximately ( myButtonRect . top ) ;
1733
1748
} ) ;
1734
- var panelCss = document . querySelector ( PANEL_EL ) . style ;
1735
- expect ( panelCss . left ) . toBeApproximately ( myButtonRect . left ) ;
1736
- expect ( panelCss . top ) . toBeApproximately ( myButtonRect . top ) ;
1737
- } ) ;
1738
1749
1739
- it ( 'rejects offscreen position above target element' , function ( ) {
1740
- var position = mdPanelPosition
1741
- . relativeTo ( myButton )
1742
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . ABOVE )
1743
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1750
+ it ( 'rejects offscreen position above target element' , function ( ) {
1751
+ var position = mdPanelPosition
1752
+ . relativeTo ( myButton )
1753
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ABOVE )
1754
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1744
1755
1745
- config [ 'position' ] = position ;
1756
+ config [ 'position' ] = position ;
1746
1757
1747
- openPanel ( config ) ;
1758
+ openPanel ( config ) ;
1748
1759
1749
- expect ( position . getActualPosition ( ) ) . toEqual ( {
1750
- x : xPosition . ALIGN_START ,
1751
- y : yPosition . ALIGN_TOPS ,
1760
+ expect ( position . getActualPosition ( ) ) . toEqual ( {
1761
+ x : xPosition . ALIGN_START ,
1762
+ y : yPosition . ALIGN_TOPS ,
1763
+ } ) ;
1752
1764
} ) ;
1753
- } ) ;
1754
1765
1755
- it ( 'rejects offscreen position below target element' , function ( ) {
1756
- // reposition button at the bottom of the screen
1757
- $rootEl [ 0 ] . style . height = "100%" ;
1758
- myButton [ 0 ] . style . position = 'absolute' ;
1759
- myButton [ 0 ] . style . bottom = '0px' ;
1760
- myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1766
+ it ( 'rejects offscreen position below target element' , function ( ) {
1767
+ // reposition button at the bottom of the screen
1768
+ $rootEl [ 0 ] . style . height = "100%" ;
1769
+ myButton [ 0 ] . style . position = 'absolute' ;
1770
+ myButton [ 0 ] . style . bottom = '0px' ;
1771
+ myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1761
1772
1762
- var position = mdPanelPosition
1763
- . relativeTo ( myButton )
1764
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . BELOW )
1765
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1773
+ var position = mdPanelPosition
1774
+ . relativeTo ( myButton )
1775
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . BELOW )
1776
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1766
1777
1767
- config [ 'position' ] = position ;
1778
+ config [ 'position' ] = position ;
1768
1779
1769
- openPanel ( config ) ;
1780
+ openPanel ( config ) ;
1770
1781
1771
- expect ( position . getActualPosition ( ) ) . toEqual ( {
1772
- x : xPosition . ALIGN_START ,
1773
- y : yPosition . ALIGN_TOPS ,
1782
+ expect ( position . getActualPosition ( ) ) . toEqual ( {
1783
+ x : xPosition . ALIGN_START ,
1784
+ y : yPosition . ALIGN_TOPS ,
1785
+ } ) ;
1774
1786
} ) ;
1775
- } ) ;
1776
1787
1777
- it ( 'rejects offscreen position right of target element' , function ( ) {
1778
- // reposition button at the bottom of the screen
1779
- $rootEl [ 0 ] . style . width = "100%" ;
1780
- myButton [ 0 ] . style . position = 'absolute' ;
1781
- myButton [ 0 ] . style . right = '0px' ;
1782
- myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1788
+ it ( 'rejects offscreen position right of target element' , function ( ) {
1789
+ // reposition button at the bottom of the screen
1790
+ $rootEl [ 0 ] . style . width = "100%" ;
1791
+ myButton [ 0 ] . style . position = 'absolute' ;
1792
+ myButton [ 0 ] . style . right = '0px' ;
1793
+ myButtonRect = myButton [ 0 ] . getBoundingClientRect ( ) ;
1783
1794
1784
- var position = mdPanelPosition
1785
- . relativeTo ( myButton )
1786
- . addPanelPosition ( xPosition . OFFSET_END , yPosition . ALIGN_TOPS )
1787
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1795
+ var position = mdPanelPosition
1796
+ . relativeTo ( myButton )
1797
+ . addPanelPosition ( xPosition . OFFSET_END , yPosition . ALIGN_TOPS )
1798
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1788
1799
1789
- config [ 'position' ] = position ;
1800
+ config [ 'position' ] = position ;
1790
1801
1791
- openPanel ( config ) ;
1802
+ openPanel ( config ) ;
1792
1803
1793
- expect ( position . getActualPosition ( ) ) . toEqual ( {
1794
- x : xPosition . ALIGN_START ,
1795
- y : yPosition . ALIGN_TOPS ,
1804
+ expect ( position . getActualPosition ( ) ) . toEqual ( {
1805
+ x : xPosition . ALIGN_START ,
1806
+ y : yPosition . ALIGN_TOPS ,
1807
+ } ) ;
1796
1808
} ) ;
1797
- } ) ;
1798
1809
1799
- it ( 'should choose last position if none are on-screen' , function ( ) {
1800
- var position = mdPanelPosition
1801
- . relativeTo ( myButton )
1802
- // off-screen to the left
1803
- . addPanelPosition ( xPosition . OFFSET_START , yPosition . ALIGN_TOPS )
1804
- // off-screen at the top
1805
- . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1810
+ it ( 'should choose last position if none are on-screen' , function ( ) {
1811
+ var position = mdPanelPosition
1812
+ . relativeTo ( myButton )
1813
+ // off-screen to the left
1814
+ . addPanelPosition ( xPosition . OFFSET_START , yPosition . ALIGN_TOPS )
1815
+ // off-screen at the top
1816
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1806
1817
1807
- config [ 'position' ] = position ;
1818
+ config [ 'position' ] = position ;
1808
1819
1809
- openPanel ( config ) ;
1820
+ openPanel ( config ) ;
1810
1821
1811
- expect ( position . getActualPosition ( ) ) . toEqual ( {
1812
- x : xPosition . ALIGN_START ,
1813
- y : yPosition . ALIGN_TOPS ,
1822
+ expect ( position . getActualPosition ( ) ) . toEqual ( {
1823
+ x : xPosition . ALIGN_START ,
1824
+ y : yPosition . ALIGN_TOPS ,
1825
+ } ) ;
1814
1826
} ) ;
1815
1827
} ) ;
1816
1828
@@ -1887,6 +1899,49 @@ describe('$mdPanel', function() {
1887
1899
. getBoundingClientRect ( ) ;
1888
1900
expect ( panelRect . top ) . toBeApproximately ( myButtonRect . bottom ) ;
1889
1901
} ) ;
1902
+
1903
+ it ( 'element outside the left boundry of the viewport' , function ( ) {
1904
+ var position = mdPanelPosition
1905
+ . relativeTo ( myButton )
1906
+ . addPanelPosition ( xPosition . ALIGN_END , yPosition . ALIGN_TOPS ) ;
1907
+
1908
+ config [ 'position' ] = position ;
1909
+
1910
+ myButton . css ( {
1911
+ position : 'absolute' ,
1912
+ left : '-100px' ,
1913
+ margin : 0
1914
+ } ) ;
1915
+
1916
+ openPanel ( config ) ;
1917
+
1918
+ var panel = document . querySelector ( PANEL_EL ) ;
1919
+
1920
+ expect ( panel . offsetLeft ) . toBe ( MdPanelPosition . viewportMargin ) ;
1921
+ expect ( panel ) . toHaveClass ( ADJUSTED_CLASS ) ;
1922
+ } ) ;
1923
+
1924
+ it ( 'element outside the right boundry of the viewport' , function ( ) {
1925
+ var position = mdPanelPosition
1926
+ . relativeTo ( myButton )
1927
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ALIGN_TOPS ) ;
1928
+
1929
+ config [ 'position' ] = position ;
1930
+
1931
+ myButton . css ( {
1932
+ position : 'absolute' ,
1933
+ right : '-100px' ,
1934
+ margin : 0
1935
+ } ) ;
1936
+
1937
+ openPanel ( config ) ;
1938
+
1939
+ var panel = document . querySelector ( PANEL_EL ) ;
1940
+ var panelRect = panel . getBoundingClientRect ( ) ;
1941
+
1942
+ expect ( panelRect . left + panelRect . width ) . toBeLessThan ( window . innerWidth ) ;
1943
+ expect ( panel ) . toHaveClass ( ADJUSTED_CLASS ) ;
1944
+ } ) ;
1890
1945
} ) ;
1891
1946
1892
1947
describe ( 'horizontally' , function ( ) {
@@ -1963,6 +2018,49 @@ describe('$mdPanel', function() {
1963
2018
expect ( panelRect . left ) . toBeApproximately ( myButtonRect . right ) ;
1964
2019
} ) ;
1965
2020
2021
+ it ( 'element outside the top boundry of the viewport' , function ( ) {
2022
+ var position = mdPanelPosition
2023
+ . relativeTo ( myButton )
2024
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . ABOVE ) ;
2025
+
2026
+ config [ 'position' ] = position ;
2027
+
2028
+ myButton . css ( {
2029
+ position : 'absolute' ,
2030
+ top : 0 ,
2031
+ margin : 0
2032
+ } ) ;
2033
+
2034
+ openPanel ( config ) ;
2035
+
2036
+ var panel = document . querySelector ( PANEL_EL ) ;
2037
+
2038
+ expect ( panel . offsetTop ) . toBe ( MdPanelPosition . viewportMargin ) ;
2039
+ expect ( panel ) . toHaveClass ( ADJUSTED_CLASS ) ;
2040
+ } ) ;
2041
+
2042
+ it ( 'element outside the bottom boundry of the viewport' , function ( ) {
2043
+ var position = mdPanelPosition
2044
+ . relativeTo ( myButton )
2045
+ . addPanelPosition ( xPosition . ALIGN_START , yPosition . BELOW ) ;
2046
+
2047
+ config [ 'position' ] = position ;
2048
+
2049
+ myButton . css ( {
2050
+ position : 'absolute' ,
2051
+ bottom : 0 ,
2052
+ margin : 0
2053
+ } ) ;
2054
+
2055
+ openPanel ( config ) ;
2056
+
2057
+ var panel = document . querySelector ( PANEL_EL ) ;
2058
+ var panelRect = panel . getBoundingClientRect ( ) ;
2059
+
2060
+ expect ( panelRect . top + panelRect . height ) . toBeLessThan ( window . innerHeight ) ;
2061
+ expect ( panel ) . toHaveClass ( ADJUSTED_CLASS ) ;
2062
+ } ) ;
2063
+
1966
2064
describe ( 'rtl' , function ( ) {
1967
2065
beforeEach ( function ( ) {
1968
2066
setRTL ( ) ;
0 commit comments