A platform for community discussion. Free, open, simple.
FIX: Modal-based chat composer buttons not working on mobile (#37378)
Régis Hanol8de9ea2fc30c
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer-dropdown.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-composer-dropdown.gjsindex e3f869c4663..885453715c4 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer-dropdown.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer-dropdown.gjs@@ -9,13 +9,17 @@ import { i18n } from "discourse-i18n";export default class ChatComposerDropdown extends Component {@action- onButtonClick(button, closeFn) {- // ⚠️ Do not use async/await here ⚠️+ async onButtonClick(button, closeFn) {// Safari requires file input clicks to happen synchronously// within the user gesture event chain. Using await breaks this// chain and prevents the file picker from opening.// See: https://webkit.org/blog/13862/the-user-activation-api/- closeFn();+ if (button.synchronous) {+ closeFn();+ } else {+ await closeFn();+ }+button.action();}diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.jsindex f28796f4b7d..89198297dcf 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js@@ -94,6 +94,7 @@ class ChatSetupInit {label: "chat.upload",position: "dropdown",action: "uploadClicked",+ synchronous: true,dependentKeys: ["canAttachUploads"],displayed() {return this.canAttachUploads;diff --git a/plugins/chat/assets/javascripts/discourse/lib/chat-composer-buttons.js b/plugins/chat/assets/javascripts/discourse/lib/chat-composer-buttons.jsindex 478947e9798..4e9b9613ed4 100644--- a/plugins/chat/assets/javascripts/discourse/lib/chat-composer-buttons.js+++ b/plugins/chat/assets/javascripts/discourse/lib/chat-composer-buttons.js@@ -27,6 +27,7 @@ export function registerChatComposerButton(button) {displayed: true,disabled: false,priority: 0,+ synchronous: false,};const normalizedButton = Object.assign(defaultButton, button);@@ -111,6 +112,7 @@ export function chatComposerButtons(composer, position, context) {result.icon = computeButton(composer, button, "icon");result.disabled = computeButton(composer, button, "disabled");result.priority = computeButton(composer, button, "priority");+ result.synchronous = computeButton(composer, button, "synchronous");if (isFunction(button.action)) {result.action = () => {