A platform for community discussion. Free, open, simple.
UX: prevent iOS from scrolling modal out of view on dropdown input focus (#39382)
Kris487e57d3605a
diff --git a/frontend/discourse/app/components/d-modal.gjs b/frontend/discourse/app/components/d-modal.gjsindex b511bf3603d..77020622620 100644--- a/frontend/discourse/app/components/d-modal.gjs+++ b/frontend/discourse/app/components/d-modal.gjs@@ -29,6 +29,8 @@ export const CLOSE_INITIATED_BY_SWIPE_DOWN = "initiatedBySwipeDown";const SWIPE_VELOCITY_THRESHOLD = 0.4;export default class DModal extends Component {+ @service appEvents;+ @service capabilities;@service modal;@service site;@@ -46,11 +48,40 @@ export default class DModal extends Component {lock(el);+ if (this.capabilities.isIOS) {+ this.lockedScrollY = window.scrollY;+ this.appEvents.on(+ "keyboard-visibility-change",+ this,+ this.resetDocumentScrollOnIOS+ );+ }+return () => {unlock(el);++ if (this.capabilities.isIOS) {+ this.appEvents.off(+ "keyboard-visibility-change",+ this,+ this.resetDocumentScrollOnIOS+ );+ }};});+ @action+ resetDocumentScrollOnIOS(visible) {+ // iOS scrolls the page to the focused input when the keyboard opens+ // as a result when an input is within a dropdown within a modal, the modal is scrolled out of view.+ // This forces the modal back to the correct visible position.+ if (!visible) {+ return;+ }++ window.scrollTo(0, this.lockedScrollY ?? 0);+ }+@actionasync setupModal(el) {document.documentElement.addEventListener(