Skip to content

Commit

Permalink
🐛 fix(bal-nav): Opening menu scrolls page back to top (#1433)
Browse files Browse the repository at this point in the history
* Create PR for #1428

* fix(nav): will not scroll to top when open nav flyout

* chore: format files

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Gery Hirschfeld <gerhard.hirschfeld@baloise.ch>
  • Loading branch information
github-actions[bot] and hirsch88 authored Aug 13, 2024
1 parent 4fa149b commit 3b22ce6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-dancers-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': patch
---

**nav**: will not scroll to top when open nav flyout
10 changes: 7 additions & 3 deletions packages/core/src/utils/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class BalScrollHandler {
}

private target: HTMLElement | Document | undefined
private x = 0
private y = 0
private x: number | undefined = undefined
private y: number | undefined = undefined
private disabled = false

connect(el?: HTMLElement) {
Expand Down Expand Up @@ -62,7 +62,11 @@ export class BalScrollHandler {
document.body.style.position = ''
document.body.style.top = ''
document.body.style.width = ''
window.scrollTo(this.x, this.y)
if (this.x !== undefined && this.y !== undefined) {
window.scrollTo(this.x, this.y)
this.x = undefined
this.y = undefined
}
this.disabled = false
}
}
Expand Down

0 comments on commit 3b22ce6

Please sign in to comment.