about summary refs log tree commit diff
path: root/app/javascript/mastodon/features/compose/components/compose_form.js
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-02-25 00:51:01 +0100
committerGitHub <noreply@github.com>2022-02-25 00:51:01 +0100
commit2cd31b31778cec3b282a44f03a03844d92a4e8cc (patch)
tree4b0d299e6ea1f064c80ab5bd62ae61ea7ade197a /app/javascript/mastodon/features/compose/components/compose_form.js
parentd4592bbfcd091c4eaef8c8f24c47d5c2ce1bacd3 (diff)
Fix reply button on media modal not giving focus to compose form (#17626)
* Avoid compose form and modal management fighting for focus

* Fix reply button on media modal footer not giving focus to compose form
Diffstat (limited to 'app/javascript/mastodon/features/compose/components/compose_form.js')
-rw-r--r--app/javascript/mastodon/features/compose/components/compose_form.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js
index d75145a09..d7635da40 100644
--- a/app/javascript/mastodon/features/compose/components/compose_form.js
+++ b/app/javascript/mastodon/features/compose/components/compose_form.js
@@ -163,8 +163,13 @@ class ComposeForm extends ImmutablePureComponent {
         selectionStart = selectionEnd;
       }
 
-      this.autosuggestTextarea.textarea.setSelectionRange(selectionStart, selectionEnd);
-      this.autosuggestTextarea.textarea.focus();
+      // Because of the wicg-inert polyfill, the activeElement may not be
+      // immediately selectable, we have to wait for observers to run, as
+      // described in https://github.com/WICG/inert#performance-and-gotchas
+      Promise.resolve().then(() => {
+        this.autosuggestTextarea.textarea.setSelectionRange(selectionStart, selectionEnd);
+        this.autosuggestTextarea.textarea.focus();
+      }).catch(console.error);
     } else if(prevProps.isSubmitting && !this.props.isSubmitting) {
       this.autosuggestTextarea.textarea.focus();
     } else if (this.props.spoiler !== prevProps.spoiler) {