Skip to content
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

Closed
SamvelRaja opened this issue Jan 6, 2016 · 10 comments
Closed

Updating the position on window resize. #54

SamvelRaja opened this issue Jan 6, 2016 · 10 comments

Comments

@SamvelRaja
Copy link

It will be better to adjust the position based on the based on window resize event.

@jquense
Copy link
Member

jquense commented Jan 6, 2016

adjust the position of what?

@SamvelRaja
Copy link
Author

Right now i am using the overlays to position my tooltips, which are not adjusting by themselves when the window size gets resized.

@saltycrane
Copy link

@jquense here is an animated gif showing what I think @SamvelRaja is talking about:
egh04t4uii

@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>
    );
  }
}

@SamvelRaja
Copy link
Author

Exactly @saltycrane and toggling the state creating a flick which is not good a approach as well 😞

@jquense
Copy link
Member

jquense commented Jan 15, 2016

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 container prop to "attach" the tooltip to an element that moves with the flow of the document. (notice this example: http://react-bootstrap.github.io/components.html#popovers-in-container)

The downside to doing resize is the performance cost, which matters with lots of tooltips on screen

ref: twbs/bootstrap#9517

@taion
Copy link
Member

taion commented Jan 15, 2016

You'd need both that and listening to the resize event, right?

@jquense
Copy link
Member

jquense commented Jan 15, 2016

I suppose it depends on the situation, but yeah, maybe this is something we turn on with shouldPositionUpdate?

@taion
Copy link
Member

taion commented Jan 15, 2016

I feel like attaching a window resize listener automatically is a little janky though.

Maybe offer some utility component for this functionality?

@saltycrane
Copy link

Thanks for the responses. I'm still struggling with getting the positioning right, but I think using the container prop solves my window resizing problem. I did not know about that prop. Thanks.

@SamvelRaja
Copy link
Author

Thanks all.. It really helps a lot. Go ahead and close the issue if you needs to.

@taion taion closed this as completed Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants