A platform for community discussion. Free, open, simple.
FIX: reset scrollbar position for mobile on lightbox images (#22822)
David Battersby383f48c6887b
diff --git a/app/assets/javascripts/discourse/app/components/d-lightbox.js b/app/assets/javascripts/discourse/app/components/d-lightbox.jsindex 6affacbbd75..a2cb4d8a262 100644--- a/app/assets/javascripts/discourse/app/components/d-lightbox.js+++ b/app/assets/javascripts/discourse/app/components/d-lightbox.js@@ -47,6 +47,7 @@ export default class DLightbox extends Component {elementId = LIGHTBOX_ELEMENT_ID;titleElementId = TITLE_ELEMENT_ID;animationDuration = ANIMATION_DURATION;+ scrollPosition = 0;get layoutType() {return window.innerWidth > window.innerHeight@@ -201,6 +202,7 @@ export default class DLightbox extends Component {this.isLoading = true;this.isVisible = true;+ this.scrollPosition = window.scrollY;this.#setCurrentItem(this.currentIndex);@@ -462,6 +464,8 @@ export default class DLightbox extends Component {this.isVisible = false;this.willClose = false;+ this.resetScrollPosition();+this.callbacks.onCleanup?.();this.callbacks = {};@@ -469,6 +473,16 @@ export default class DLightbox extends Component {}}+ resetScrollPosition() {+ if (window.scrollY !== this.scrollPosition) {+ window.scrollTo({+ left: 0,+ top: parseInt(this.scrollPosition, 10),+ behavior: "instant",+ });+ }+ }+willDestroy() {super.willDestroy(...arguments);this.cleanup();