@@ -180,6 +180,47 @@ describe('MdRipple', () => {
180180 expect ( pxStringToFloat ( ripple . style . width ) ) . toBeCloseTo ( 2 * expectedRadius , 1 ) ;
181181 expect ( pxStringToFloat ( ripple . style . height ) ) . toBeCloseTo ( 2 * expectedRadius , 1 ) ;
182182 } ) ;
183+
184+ it ( 'create ripple with correct position when page is scrolled' , ( ) => {
185+ let elementTop = 600 ;
186+ let elementLeft = 750 ;
187+ let pageScrollTop = 500 ;
188+ let pageScrollLeft = 500 ;
189+ let left = 50 ;
190+ let top = 75 ;
191+
192+ // Add a very large element to make the page scroll
193+ let veryLargeElement : HTMLElement = document . createElement ( 'div' ) ;
194+ veryLargeElement . style . width = '4000px' ;
195+ veryLargeElement . style . height = '4000px' ;
196+ document . body . appendChild ( veryLargeElement ) ;
197+ document . body . scrollTop = pageScrollTop ;
198+ document . body . scrollLeft = pageScrollLeft ;
199+
200+ rippleElement . style . left = `${ elementLeft } px` ;
201+ rippleElement . style . top = `${ elementTop } px` ;
202+
203+ // Simulate a keyboard-triggered click by setting event coordinates to 0.
204+ const clickEvent = createMouseEvent ( 'click' , {
205+ clientX : left + elementLeft - pageScrollLeft ,
206+ clientY : top + elementTop - pageScrollTop ,
207+ screenX : left + elementLeft ,
208+ screenY : top + elementTop
209+ } ) ;
210+ rippleElement . dispatchEvent ( clickEvent ) ;
211+
212+ const expectedRadius = Math . sqrt ( 250 * 250 + 125 * 125 ) ;
213+ const expectedLeft = left - expectedRadius ;
214+ const expectedTop = top - expectedRadius ;
215+
216+ const ripple = < HTMLElement > rippleElement . querySelector ( '.md-ripple-foreground' ) ;
217+ expect ( pxStringToFloat ( ripple . style . left ) ) . toBeCloseTo ( expectedLeft , 1 ) ;
218+ expect ( pxStringToFloat ( ripple . style . top ) ) . toBeCloseTo ( expectedTop , 1 ) ;
219+ expect ( pxStringToFloat ( ripple . style . width ) ) . toBeCloseTo ( 2 * expectedRadius , 1 ) ;
220+ expect ( pxStringToFloat ( ripple . style . height ) ) . toBeCloseTo ( 2 * expectedRadius , 1 ) ;
221+
222+ document . body . removeChild ( veryLargeElement ) ;
223+ } ) ;
183224 } ) ;
184225
185226 describe ( 'configuring behavior' , ( ) => {
0 commit comments