about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/compose/components/compose_form.js
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-02-25 00:51:01 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-02-26 09:54:48 +0100
commit8e04ba87b709365facbbe28682b2809225f209bc (patch)
treeef813144eaa86e7ee5b8527ea7fd74ac22817668 /app/javascript/flavours/glitch/features/compose/components/compose_form.js
parent2e2b8a9a40ecdd2a7a63ecccb252af46179bbdb5 (diff)
[Glitch] Fix reply button on media modal not giving focus to compose form
Port 2cd31b31778cec3b282a44f03a03844d92a4e8cc to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch/features/compose/components/compose_form.js')
-rw-r--r--app/javascript/flavours/glitch/features/compose/components/compose_form.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.js b/app/javascript/flavours/glitch/features/compose/components/compose_form.js
index c75906ce7..b03bc34b8 100644
--- a/app/javascript/flavours/glitch/features/compose/components/compose_form.js
+++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.js
@@ -246,9 +246,14 @@ class ComposeForm extends ImmutablePureComponent {
         selectionStart = selectionEnd = text.length;
       }
       if (textarea) {
-        textarea.setSelectionRange(selectionStart, selectionEnd);
-        textarea.focus();
-        if (!singleColumn) textarea.scrollIntoView();
+        // 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(() => {
+          textarea.setSelectionRange(selectionStart, selectionEnd);
+          textarea.focus();
+          if (!singleColumn) textarea.scrollIntoView();
+        }).catch(console.error);
       }
 
     //  Refocuses the textarea after submitting.