Fix tooltip vertical positioning.
This commit is contained in:
parent
d77ab891a0
commit
78ae1ada3c
1 changed files with 21 additions and 2 deletions
|
@ -21,6 +21,8 @@ var ReactDOM = require('react-dom');
|
||||||
var dis = require('matrix-react-sdk/lib/dispatcher');
|
var dis = require('matrix-react-sdk/lib/dispatcher');
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
const MIN_TOOLTIP_HEIGHT = 25;
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'RoomTooltip',
|
displayName: 'RoomTooltip',
|
||||||
|
|
||||||
|
@ -41,6 +43,12 @@ module.exports = React.createClass({
|
||||||
document.body.appendChild(this.tooltipContainer);
|
document.body.appendChild(this.tooltipContainer);
|
||||||
window.addEventListener('scroll', this._renderTooltip, true);
|
window.addEventListener('scroll', this._renderTooltip, true);
|
||||||
|
|
||||||
|
const parent = ReactDOM.findDOMNode(this).parentNode;
|
||||||
|
this.state={
|
||||||
|
parent,
|
||||||
|
parentBox: parent.getBoundingClientRect(),
|
||||||
|
};
|
||||||
|
|
||||||
this._renderTooltip();
|
this._renderTooltip();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -61,6 +69,17 @@ module.exports = React.createClass({
|
||||||
window.removeEventListener('scroll', this._renderTooltip, true);
|
window.removeEventListener('scroll', this._renderTooltip, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_updatePosition(style) {
|
||||||
|
const parentBox = this.state.parent.getBoundingClientRect();
|
||||||
|
let offset = 0;
|
||||||
|
if (parentBox.height > MIN_TOOLTIP_HEIGHT) {
|
||||||
|
offset = Math.floor((parentBox.height - MIN_TOOLTIP_HEIGHT) / 2);
|
||||||
|
}
|
||||||
|
style.top = (parentBox.top - 2) + window.pageYOffset + offset;
|
||||||
|
style.left = 6 + parentBox.right + window.pageXOffset;
|
||||||
|
return style;
|
||||||
|
},
|
||||||
|
|
||||||
_renderTooltip: function() {
|
_renderTooltip: function() {
|
||||||
var label = this.props.room ? this.props.room.name : this.props.label;
|
var label = this.props.room ? this.props.room.name : this.props.label;
|
||||||
|
|
||||||
|
@ -70,8 +89,8 @@ module.exports = React.createClass({
|
||||||
// tooltips chevron
|
// tooltips chevron
|
||||||
var parent = ReactDOM.findDOMNode(this).parentNode;
|
var parent = ReactDOM.findDOMNode(this).parentNode;
|
||||||
var style = {};
|
var style = {};
|
||||||
style.top = parent.getBoundingClientRect().top + window.pageYOffset;
|
console.warn('Bounding box', parent.getBoundingClientRect());
|
||||||
style.left = 6 + parent.getBoundingClientRect().right + window.pageXOffset;
|
style = this._updatePosition(style);
|
||||||
style.display = "block";
|
style.display = "block";
|
||||||
|
|
||||||
const tooltipClasses = classNames(
|
const tooltipClasses = classNames(
|
||||||
|
|
Loading…
Add table
Reference in a new issue