-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating the position on window resize. #54
Comments
adjust the position of what? |
Right now i am using the overlays to position my tooltips, which are not adjusting by themselves when the window size gets resized. |
@jquense here is an animated gif showing what I think @SamvelRaja is talking about: @SamvelRaja probably noticed this since he created #55, but #42 is useful for solving this issue. It allows me to do: class HelpWidget extends Component {
componentDidMount() {
util.throttleEvent('resize', 'throttledResize');
window.addEventListener('throttledResize', this._onResize);
}
_onResize = () => {
this.forceUpdate();
};
render() {
return (
<span>
<OverlayTrigger shouldUpdatePosition={true} trigger="click" rootClose placement="bottom" overlay={ <MyPopover /> } >
<a tabIndex="0" role="button" className="popover-help-trigger"></a>
</OverlayTrigger>
</span>
);
}
} Without #42 I need to use a hack to make it work: class HelpWidget extends Component {
state = {
placement: "bottom"
};
componentDidMount() {
util.throttleEvent('resize', 'throttledResize');
window.addEventListener('throttledResize', this._onResize);
}
_onResize = () => {
// HACK: to make open popover move when resizing the window
this.setState({placement: 'right'});
this.setState({placement: 'bottom'});
};
render() {
return (
<span>
<OverlayTrigger trigger="click" rootClose placement={this.state.placement} overlay={ <MyPopover /> } >
<a tabIndex="0" role="button" className="popover-help-trigger"></a>
</OverlayTrigger>
</span>
);
}
} |
Exactly @saltycrane and toggling the state creating a flick which is not good a approach as well 😞 |
Hey folks, thanks for the responses I am inclined to say that the right way to deal with this is to make use of the The downside to doing resize is the performance cost, which matters with lots of tooltips on screen ref: twbs/bootstrap#9517 |
You'd need both that and listening to the resize event, right? |
I suppose it depends on the situation, but yeah, maybe this is something we turn on with shouldPositionUpdate? |
I feel like attaching a window resize listener automatically is a little janky though. Maybe offer some utility component for this functionality? |
Thanks for the responses. I'm still struggling with getting the positioning right, but I think using the |
Thanks all.. It really helps a lot. Go ahead and close the issue if you needs to. |
It will be better to adjust the position based on the based on window resize event.
The text was updated successfully, but these errors were encountered: