1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-14 07:23:45 +00:00

fix scroll positon after delete

This commit is contained in:
jaasen-livefront
2026-02-03 17:14:34 -08:00
parent d1d104ad69
commit e59a72eeed
2 changed files with 6 additions and 24 deletions

View File

@@ -108,27 +108,6 @@ describe("VaultPopupScrollPositionService", () => {
});
expect((scrollElement as any).scrollTop).toBe(500);
}));
it("forces scroll to top on next start when requested", fakeAsync(() => {
service["scrollPosition"] = 500;
service.start(scrollElement);
tick();
expect((scrollElement as any).scrollTo).toHaveBeenCalledWith({
behavior: "instant",
top: 0,
});
expect((scrollElement as any).scrollTop).toBe(0);
// A follow-up scroll is scheduled to defeat Firefox scroll restoration.
((scrollElement as any).scrollTo as jest.Mock).mockClear();
tick(300);
expect((scrollElement as any).scrollTo).toHaveBeenCalledWith({
behavior: "instant",
top: 0,
});
}));
});
describe("scroll listener", () => {

View File

@@ -31,9 +31,12 @@ export class VaultPopupScrollPositionService {
/** Scrolls the user to the stored scroll position and starts tracking scroll of the page. */
start(scrollElement: HTMLElement) {
setTimeout(() => {
scrollElement.scrollTo({ top: this.scrollPosition!, behavior: "instant" });
});
if (this.hasScrollPosition()) {
// Use `setTimeout` to scroll after rendering is complete
setTimeout(() => {
scrollElement.scrollTo({ top: this.scrollPosition, behavior: "instant" });
});
}
this.scrollSubscription?.unsubscribe();