@@ -21,6 +21,8 @@ var ReactDOM = require('react-dom');
2121var dis = require ( 'matrix-react-sdk/lib/dispatcher' ) ;
2222import classNames from 'classnames' ;
2323
24+ const MIN_TOOLTIP_HEIGHT = 25 ;
25+
2426module . exports = React . createClass ( {
2527 displayName : 'RoomTooltip' ,
2628
@@ -39,6 +41,9 @@ module.exports = React.createClass({
3941 this . tooltipContainer = document . createElement ( "div" ) ;
4042 this . tooltipContainer . className = "mx_RoomTileTooltip_wrapper" ;
4143 document . body . appendChild ( this . tooltipContainer ) ;
44+ window . addEventListener ( 'scroll' , this . _renderTooltip , true ) ;
45+
46+ this . parent = ReactDOM . findDOMNode ( this ) . parentNode ;
4247
4348 this . _renderTooltip ( ) ;
4449 } ,
@@ -57,6 +62,18 @@ module.exports = React.createClass({
5762
5863 ReactDOM . unmountComponentAtNode ( this . tooltipContainer ) ;
5964 document . body . removeChild ( this . tooltipContainer ) ;
65+ window . removeEventListener ( 'scroll' , this . _renderTooltip , true ) ;
66+ } ,
67+
68+ _updatePosition ( style ) {
69+ const parentBox = this . parent . getBoundingClientRect ( ) ;
70+ let offset = 0 ;
71+ if ( parentBox . height > MIN_TOOLTIP_HEIGHT ) {
72+ offset = Math . floor ( ( parentBox . height - MIN_TOOLTIP_HEIGHT ) / 2 ) ;
73+ }
74+ style . top = ( parentBox . top - 2 ) + window . pageYOffset + offset ;
75+ style . left = 6 + parentBox . right + window . pageXOffset ;
76+ return style ;
6077 } ,
6178
6279 _renderTooltip : function ( ) {
@@ -66,10 +83,9 @@ module.exports = React.createClass({
6683 // positioned, also taking into account any window zoom
6784 // NOTE: The additional 6 pixels for the left position, is to take account of the
6885 // tooltips chevron
69- var parent = ReactDOM . findDOMNode ( this ) ;
86+ var parent = ReactDOM . findDOMNode ( this ) . parentNode ;
7087 var style = { } ;
71- style . top = parent . getBoundingClientRect ( ) . top + window . pageYOffset ;
72- style . left = 6 + parent . getBoundingClientRect ( ) . right + window . pageXOffset ;
88+ style = this . _updatePosition ( style ) ;
7389 style . display = "block" ;
7490
7591 const tooltipClasses = classNames (
@@ -97,8 +113,8 @@ module.exports = React.createClass({
97113 render : function ( ) {
98114 // Render a placeholder
99115 return (
100- < div className = { this . props . className } >
116+ < div className = { this . props . className } >
101117 </ div >
102118 ) ;
103- }
119+ } ,
104120} ) ;
0 commit comments