fix(router): default scroll position restoration to disabled (#25586)

Fixes #25145
FW-305 #resolve

PR Close #25586
This commit is contained in:
Jason Aden 2018-08-20 12:03:51 -07:00
parent f54f3856cb
commit fc89479044
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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} =