]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Fix opening the emoji picker scrolling the single-column view to the top
authorClaire <claire.github-309c@sitedethib.com>
Wed, 16 Feb 2022 20:44:47 +0000 (21:44 +0100)
committerClaire <claire.github-309c@sitedethib.com>
Thu, 17 Feb 2022 10:05:47 +0000 (11:05 +0100)
Port aa86cf955755cd05ed9c274daebbec248c39d863 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
app/javascript/flavours/glitch/features/emoji_picker/index.js

index 78f691c9800b7c3e5c61e9249739a02d12fa5955..5de9fe107ffd238140df96ca70b2c839aaaa5e74 100644 (file)
@@ -250,7 +250,7 @@ class EmojiPickerMenu extends React.PureComponent {
 
   state = {
     modifierOpen: false,
-    placement: null,
+    readyToFocus: false,
   };
 
   handleDocumentClick = e => {
@@ -262,6 +262,16 @@ class EmojiPickerMenu extends React.PureComponent {
   componentDidMount () {
     document.addEventListener('click', this.handleDocumentClick, false);
     document.addEventListener('touchend', this.handleDocumentClick, listenerOptions);
+
+    // Because of https://github.com/react-bootstrap/react-bootstrap/issues/2614 we need
+    // to wait for a frame before focusing
+    requestAnimationFrame(() => {
+      this.setState({ readyToFocus: true });
+      if (this.node) {
+        const element = this.node.querySelector('input[type="search"]');
+        if (element) element.focus();
+      }
+    });
   }
 
   componentWillUnmount () {
@@ -361,7 +371,7 @@ class EmojiPickerMenu extends React.PureComponent {
           showSkinTones={false}
           backgroundImageFn={backgroundImageFn}
           notFound={notFoundFn}
-          autoFocus
+          autoFocus={this.state.readyToFocus}
           emojiTooltip
           native={useSystemEmojiFont}
         />
@@ -396,6 +406,7 @@ class EmojiPickerDropdown extends React.PureComponent {
   state = {
     active: false,
     loading: false,
+    placement: null,
   };
 
   setRef = (c) => {