about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-04-10 20:04:55 +0200
committerThibaut Girka <thib@sitedethib.com>2018-04-10 20:52:31 +0200
commite74e5c7eb903d6e9aa88629e975a81574fe49159 (patch)
tree960ece361f14728dc0f4367c88afa0ed5fd6a05d /app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js
parent3ab6a8b8bed37d048909b178693af8411325eb38 (diff)
Place composer dropdown menus top if they are closer to the bottom of the viewport
Diffstat (limited to 'app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js')
-rw-r--r--app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js b/app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js
index b3a472999..b76410561 100644
--- a/app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js
+++ b/app/javascript/flavours/glitch/features/composer/options/dropdown/content/index.js
@@ -13,7 +13,6 @@ import { assignHandlers } from 'flavours/glitch/util/react_helpers';
 
 //  Handlers.
 const handlers = {
-
   //  When the document is clicked elsewhere, we close the dropdown.
   handleDocumentClick ({ target }) {
     const { node } = this;
@@ -45,6 +44,10 @@ export default class ComposerOptionsDropdownContent extends React.PureComponent
 
     //  Instance variables.
     this.node = null;
+
+    this.state = {
+      mounted: false,
+    };
   }
 
   //  On mounting, we add our listeners.
@@ -52,6 +55,7 @@ export default class ComposerOptionsDropdownContent extends React.PureComponent
     const { handleDocumentClick } = this.handlers;
     document.addEventListener('click', handleDocumentClick, false);
     document.addEventListener('touchend', handleDocumentClick, withPassive);
+    this.setState({ mounted: true });
   }
 
   //  On unmounting, we remove our listeners.
@@ -63,6 +67,7 @@ export default class ComposerOptionsDropdownContent extends React.PureComponent
 
   //  Rendering.
   render () {
+    const { mounted } = this.state;
     const { handleRef } = this.handlers;
     const {
       items,
@@ -87,13 +92,16 @@ export default class ComposerOptionsDropdownContent extends React.PureComponent
         }}
       >
         {({ opacity, scaleX, scaleY }) => (
+          // It should not be transformed when mounting because the resulting
+          // size will be used to determine the coordinate of the menu by
+          // react-overlays
           <div
             className='composer--options--dropdown--content'
             ref={handleRef}
             style={{
               ...style,
               opacity: opacity,
-              transform: `scale(${scaleX}, ${scaleY})`,
+              transform: mounted ? `scale(${scaleX}, ${scaleY})` : null,
             }}
           >
             {items ? items.map(