Skip to content

Commit

Permalink
fix(router): default scroll position restoration to disabled (#25586)
Browse files Browse the repository at this point in the history
Fixes #25145
FW-305 #resolve

PR Close #25586
  • Loading branch information
jasonaden committed Aug 21, 2018
1 parent 46b0ce9 commit 7e61645
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/router/src/router_scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export class RouterScroller implements OnDestroy {
/** @docsNotRequired */ public readonly viewportScroller: ViewportScroller, private options: {
scrollPositionRestoration?: 'disabled' | 'enabled' | 'top',
anchorScrolling?: 'disabled'|'enabled'
} = {}) {}
} = {}) {
// Default both options to 'disabled'
options.scrollPositionRestoration = options.scrollPositionRestoration || 'disabled';
options.anchorScrolling = options.anchorScrolling || 'disabled';
}

init(): void {
// we want to disable the automatic scrolling because having two places
Expand Down
18 changes: 18 additions & 0 deletions packages/router/test/router_scroller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ import {Scroll} from '../src/events';
import {RouterScroller} from '../src/router_scroller';

describe('RouterScroller', () => {
it('defaults to disabled', () => {
const events = new Subject<RouterEvent>();
const router = <any>{
events,
parseUrl: (url: any) => new DefaultUrlSerializer().parse(url),
triggerEvent: (e: any) => events.next(e)
};

const viewportScroller = jasmine.createSpyObj(
'viewportScroller',
['getScrollPosition', 'scrollToPosition', 'scrollToAnchor', 'setHistoryScrollRestoration']);
setScroll(viewportScroller, 0, 0);
const scroller = new RouterScroller(router, router);

expect((scroller as any).options.scrollPositionRestoration).toBe('disabled');
expect((scroller as any).options.anchorScrolling).toBe('disabled');
});

describe('scroll to top', () => {
it('should scroll to the top', () => {
const {events, viewportScroller} =
Expand Down

0 comments on commit 7e61645

Please sign in to comment.