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

Manual displaying with OverlayTrigger. #155

Closed
Nutelac opened this issue Jul 19, 2014 · 8 comments
Closed

Manual displaying with OverlayTrigger. #155

Nutelac opened this issue Jul 19, 2014 · 8 comments

Comments

@Nutelac
Copy link

Nutelac commented Jul 19, 2014

How should I manually control OverlayTrigger displaying (show / hide)?

E.g if I want to show only one popover on page:

var UniquePopover = React.createClass({
    render: function() {
        return (
            <ReactBootstrap.OverlayTrigger container={document.body} trigger="manual" placement="right" overlay={
                <ReactBootstrap.Popover>
                    foobar
                </ReactBootstrap.Popover>
            }>
                <ReactBootstrap.Button onClick={this.handleClick} bsStyle="default">unique popover</ReactBootstrap.Button>
            </ReactBootstrap.OverlayTrigger>
        );
    },
    handleClick: function() {
        /* Abstract */
        showCurrentPopover();
        hideOtherPopovers();
    }
});

Is that possible and how can I access to show and hide methods? Thank you.

@Nutelac Nutelac changed the title Manual display control with OverlayTrigger. Question: manual display control with OverlayTrigger. Jul 19, 2014
@Nutelac Nutelac changed the title Question: manual display control with OverlayTrigger. Question: manual displaying control with OverlayTrigger. Jul 19, 2014
@Nutelac Nutelac changed the title Question: manual displaying control with OverlayTrigger. Question: manual displaying with OverlayTrigger. Jul 19, 2014
@pieterv
Copy link
Contributor

pieterv commented Jul 20, 2014

Hey @Nutelac you can get access to the OverlayTrigger hide and show methods via a ref, something like the following should work:

var uniquePopoverStore = {};
var uniqueKey = 1;

var UniquePopover = React.createClass({
    render: function() {
        return (
            <ReactBootstrap.OverlayTrigger ref='myPopover' container={document.body} trigger="manual" placement="right" overlay={
                <ReactBootstrap.Popover>
                    foobar
                </ReactBootstrap.Popover>
            }>
                <ReactBootstrap.Button onClick={this.handleClick} bsStyle="default">unique popover</ReactBootstrap.Button>
            </ReactBootstrap.OverlayTrigger>
        );
    },
    handleClick: function() {
        /* Abstract */

        // hideOtherPopovers();
        Object.keys(uniquePopoverStore)
          .forEach(function(key) {
            if (key !== this.__uniqueKey) {
              uniquePopoverStore[key].hide();
            }
          }, this);

        // showCurrentPopover();
        this.refs.myPopover.show();
    },

    componentDidMount: function() {
      this.__uniqueKey = uniqueKey++;
      uniquePopoverStore[this.__uniqueKey] = this.refs.myPopover;
    },

    componentWillUnmount: function() {
      delete uniquePopoverStore[this.__uniqueKey];
    }
});

@Nutelac
Copy link
Author

Nutelac commented Jul 20, 2014

Thank you very much, this help me alot.

@Nutelac Nutelac closed this as completed Jul 20, 2014
@Nutelac Nutelac changed the title Question: manual displaying with OverlayTrigger. Manual displaying with OverlayTrigger. Jul 20, 2014
@haizi-zh
Copy link

Thanks! it really helps!

@avk
Copy link

avk commented Aug 10, 2016

Still works today! Wish this was documented under OverlayTrigger.

@jquense
Copy link
Member

jquense commented Aug 10, 2016

the show/hide methods are not really public, if you need to control the overlay state directly use the Overlay component directly

@stuphys1729
Copy link

Just in case anyone is looking at this later, it seems OverlayTrigger now only accepts set inputs for trigger and 'manual' isn't one of them. A workaround is to use null instead and still use the show/hide methods.

@charlie632
Copy link

How do you use the show/hide methods? I can't seem to make it work.

@eugeneborodkin
Copy link

What are the possible values for trigger=... for OverlayTrigger? They only show click in their examples, are there others? And also, how do you pre-open a popover in an initial state? I created a StackOverflow thread on this, https://stackoverflow.com/questions/69121013/react-bootstrap-popover-pre-open-popover-on-initialization I need to pre-open a popover on initialization.

aryad14 pushed a commit to aryad14/react-bootstrap that referenced this issue Oct 11, 2023
* moved to ES2016

* removed all react.createClass warnings

* removed incorrectly named compiled file

* removed ES5 example from README. Updated example with ES6 code
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

8 participants