Skip to content

A platform for community discussion. Free, open, simple.

FIX: removes body scroll lock for composer (#36219)

Joffrey JAFFEUX462a8140b183
diff --git a/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs b/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs
index f3f27dc03e9..2b427e6221b 100644
--- a/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs
+++ b/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs
@@ -22,7 +22,6 @@ import { EditorState } from "prosemirror-state";
import * as ProsemirrorTransform from "prosemirror-transform";
import * as ProsemirrorView from "prosemirror-view";
import { EditorView } from "prosemirror-view";
-import { lock, unlock } from "discourse/lib/body-scroll-lock";
import { getExtensions } from "discourse/lib/composer/rich-editor-extensions";
import { bind } from "discourse/lib/decorators";
import forceScrollingElementPosition from "discourse/modifiers/force-scrolling-element-position";
@@ -212,10 +211,6 @@ export default class ProsemirrorEditor extends Component {
},
handleDOMEvents: {
focus: (view) => {
- if (this.capabilities.isIOS && !this.capabilities.isIpadOS) {
- lock(view.dom);
- }
-
if (this.capabilities.isIOS) {
// prevents ios to attempt to scroll
focusOffScreen(view.dom);
@@ -224,11 +219,7 @@ export default class ProsemirrorEditor extends Component {
this.args.focusIn?.();
return false;
},
- blur: (view) => {
- if (this.capabilities.isIOS && !this.capabilities.isIpadOS) {
- unlock(view.dom);
- }
-
+ blur: () => {
next(() => this.args.focusOut?.());
return false;
},
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-composer.gjs
index 1583267b0ae..1439024e607 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.gjs
@@ -349,13 +349,28 @@ export default class ChatComposer extends Component {
}
}
+ forceScrollPosition() {
+ if (!this.capabilities.isIOS || this.capabilities.isIpadOS) {
+ return;
+ }
+
+ // attempts to reposition body
+ if (window.pageYOffset <= 100) {
+ // on iOS scrolling to 0 doesn’t work correctly
+ // scrolling to -1 is more consistent
+ window.scrollTo(0, -1);
+ }
+ }
+
@action
onTextareaFocusOut() {
+ this.forceScrollPosition();
this.isFocused = false;
}
@action
onTextareaFocusIn() {
+ this.forceScrollPosition();
this.isFocused = true;
}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs
index 716ca612a38..b76a1db8390 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs
@@ -1,37 +1,18 @@
-import Component from "@glimmer/component";
import { hash } from "@ember/helper";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
-import { service } from "@ember/service";
-import { modifier as modifierFn } from "ember-modifier";
-import { lock, unlock } from "discourse/lib/body-scroll-lock";
import ChatScrollableList from "../modifiers/chat/scrollable-list";
-export default class ChatMessagesScroller extends Component {
- @service capabilities;
+const ChatMessagesScroller = <template>
+ <div
+ class="chat-messages-scroller popper-viewport"
+ {{didInsert @onRegisterScroller}}
+ {{this.setupLock}}
+ {{ChatScrollableList
+ (hash onScroll=@onScroll onScrollEnd=@onScrollEnd reverse=true)
+ }}
+ >
+ {{yield}}
+ </div>
+</template>;
- setupLock = modifierFn((element) => {
- if (!this.capabilities.isIOS || this.capabilities.isIpadOS) {
- return;
- }
-
- // scroller is using flex-direction: column-reverse
- lock(element, { reverseColumn: true });
-
- return () => {
- unlock(element);
- };
- });
-
- <template>
- <div
- class="chat-messages-scroller popper-viewport"
- {{didInsert @onRegisterScroller}}
- {{this.setupLock}}
- {{ChatScrollableList
- (hash onScroll=@onScroll onScrollEnd=@onScrollEnd reverse=true)
- }}
- >
- {{yield}}
- </div>
- </template>
-}
+export default ChatMessagesScroller;