diff --git a/CHANGES.md b/CHANGES.md index dcda53f4d..944c042f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ - Message deduplication bugfixes and improvements - Continuously retry (in 2s intervals) to fetch login credentials (via [credentials_url](https://conversejs.org/docs/html/configuration.html#credentials-url)) in case of failure - Replace `moment` with [DayJS](https://github.com/iamkun/dayjs). +- New config option [auto_focus](https://conversejs.org/docs/html/configuration.html#auto-focus). - New config option [enable_smacks](https://conversejs.org/docs/html/configuration.html#enable-smacks). - New config option [muc_show_join_leave_status](https://conversejs.org/docs/html/configuration.html#muc-show-join-leave-status) - New config option [message_limit](https://conversejs.org/docs/html/configuration.html#message-limit) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 9e092a82b..7d3b1422e 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -231,6 +231,20 @@ autocomplete_add_contact Determines whether search suggestions are shown in the "Add Contact" modal. + +auto_focus +---------- + +* Default: ``true`` + +If set to ``true``, the textarea for composing chat messages will automatically +become focused as soon as a chat is opened. This means you don't need to click +the textarea first before starting to type a message. + +For applications where chat is not the main feature, automatic focus of the +chat box might be undesired. + + auto_list_rooms --------------- diff --git a/src/converse-chatview.js b/src/converse-chatview.js index ca0a6653e..a5a1f231a 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -56,6 +56,7 @@ converse.plugins.add('converse-chatview', { { __ } = _converse; _converse.api.settings.update({ + 'auto_focus': true, 'emoji_image_path': twemoji.default.base, 'message_limit': 0, 'show_send_button': false, @@ -1290,13 +1291,17 @@ converse.plugins.add('converse-chatview', { this.model.clearUnreadMsgCounter(); this.setChatState(_converse.ACTIVE); this.scrollDown(); - this.focus(); + if (_converse.auto_focus) { + this.focus(); + } }, _show () { /* Inner show method that gets debounced */ if (u.isVisible(this.el)) { - this.focus(); + if (_converse.auto_focus) { + this.focus(); + } return; } u.fadeIn(this.el, _.bind(this.afterShown, this)); diff --git a/src/converse-muc-views.js b/src/converse-muc-views.js index 3a412ba14..65f5e04e7 100644 --- a/src/converse-muc-views.js +++ b/src/converse-muc-views.js @@ -684,7 +684,9 @@ converse.plugins.add('converse-muc-views', { show () { if (u.isVisible(this.el)) { - this.focus(); + if (_converse.auto_focus) { + this.focus(); + } return; } // Override from converse-chatview in order to not use @@ -704,7 +706,9 @@ converse.plugins.add('converse-muc-views', { } else if (conn_status === converse.ROOMSTATUS.ENTERED) { this.hideSpinner(); this.setChatState(_converse.ACTIVE); - this.focus(); + if (_converse.auto_focus) { + this.focus(); + } } else if (conn_status === converse.ROOMSTATUS.DISCONNECTED) { this.showDisconnectMessage(); } else if (conn_status === converse.ROOMSTATUS.DESTROYED) {