Fix issue with calling window.scroll with options object (#51060) (#51107)

This commit is contained in:
patrykkopycinski 2019-11-19 22:42:18 +01:00 committed by GitHub
parent 35c49b2bc6
commit 1d6f852160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 8 deletions

View file

@ -23,10 +23,7 @@ describe('Scroll to top', () => {
Object.defineProperty(globalNode.window, 'scroll', { value: spyScroll });
mount(<HookWrapper hook={() => scrollToTop()} />);
expect(spyScroll).toHaveBeenCalledWith({
top: 0,
left: 0,
});
expect(spyScroll).toHaveBeenCalledWith(0, 0);
});
test('scrollTo have been called', () => {

View file

@ -10,10 +10,7 @@ export const scrollToTop = () => {
useEffect(() => {
// trying to use new API - https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo
if (window.scroll) {
window.scroll({
top: 0,
left: 0,
});
window.scroll(0, 0);
} else {
// just a fallback for older browsers
window.scrollTo(0, 0);