fix(router): default scroll position restoration to disabled (#25586)
Fixes #25145 FW-305 #resolve PR Close #25586
This commit is contained in:
parent
f54f3856cb
commit
fc89479044
@ -29,7 +29,11 @@ export class RouterScroller implements OnDestroy {
|
|||||||
/** @docsNotRequired */ public readonly viewportScroller: ViewportScroller, private options: {
|
/** @docsNotRequired */ public readonly viewportScroller: ViewportScroller, private options: {
|
||||||
scrollPositionRestoration?: 'disabled' | 'enabled' | 'top',
|
scrollPositionRestoration?: 'disabled' | 'enabled' | 'top',
|
||||||
anchorScrolling?: 'disabled'|'enabled'
|
anchorScrolling?: 'disabled'|'enabled'
|
||||||
} = {}) {}
|
} = {}) {
|
||||||
|
// Default both options to 'disabled'
|
||||||
|
options.scrollPositionRestoration = options.scrollPositionRestoration || 'disabled';
|
||||||
|
options.anchorScrolling = options.anchorScrolling || 'disabled';
|
||||||
|
}
|
||||||
|
|
||||||
init(): void {
|
init(): void {
|
||||||
// we want to disable the automatic scrolling because having two places
|
// we want to disable the automatic scrolling because having two places
|
||||||
|
@ -15,6 +15,24 @@ import {Scroll} from '../src/events';
|
|||||||
import {RouterScroller} from '../src/router_scroller';
|
import {RouterScroller} from '../src/router_scroller';
|
||||||
|
|
||||||
describe('RouterScroller', () => {
|
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', () => {
|
describe('scroll to top', () => {
|
||||||
it('should scroll to the top', () => {
|
it('should scroll to the top', () => {
|
||||||
const {events, viewportScroller} =
|
const {events, viewportScroller} =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user