React-tooltip: Hide Tooltip after button click

Created on 2 May 2017  路  5Comments  路  Source: wwayne/react-tooltip

I want to show a 'Copied!' tool-tip adjacent to a "Copy URL" button. I can get the tool tip to show on click with the code below, but it will only hide after a delay if I click the button again.

<CopyToClipboard text={viewState.copyUrl}>
    <RaisedButton
        label="Copy URL"
        primary={true}
        data-tip
        data-event='click'
        data-for='copyToClipboard'
        onClick={viewState.copyClick}
        style={{ width: '150px' }} />
</CopyToClipboard>
<ReactTooltip id='copyToClipboard' delayHide={1000}>
    <p>Copied!</p>
</ReactTooltip>

Any thoughts on how I can get this to hide?

Most helpful comment

Same issue here.
<Flex row nowrap> <br> <a data-tip data-for='confirmation' data-event='click' > <Button /> </a> <ReactTooltip id='confirmation' data-html={true} data-effect='solid' class='confirm-buttons' multiline={true} > <span> Permanently delete? <br /> <buttonOne onClick={() => this.deleteItems(arguments)}>Yes</buttonOne> <buttonTwo onClick={() => ReactTooltip.hide()}>No</buttonTwo> </span> </ReactTooltip> ``
(Flex component imported from styled-flex-components library).

My deleteItems function works just fine, but the ReactTooltip.hide() only takes effect if i move the mouse away from the tooltip. If I don't call ReactTooltip.hide(), the tooltip stays on screen indefinitely so something is happening.Just not when I want it to. Any thoughts?

All 5 comments

Try use ref on ReactTooltip and hideTooltip function:

<CopyToClipboard text={viewState.copyUrl}>
    <RaisedButton
        label="Copy URL"
        primary={true}
        data-tip
        data-event='click'
        data-for='copyToClipboard'
        onClick={() => {this.tooltip.hideTooltip(); viewState.copyClick();}}
        style={{ width: '150px' }} />
</CopyToClipboard>
<ReactTooltip ref={(node) => this.tooltip = node} id='copyToClipboard' delayHide={1000}>
    <p>Copied!</p>
</ReactTooltip>

Is there a way to prevent the tooltip from showing up when data-delay-show is defined and you clicked before the tooltip is actually shown? It seems that when I hide the tooltip programmatically (e.g. using Tooltip.hide(ref)) on click, it still shows up after that given delay. I also tried using data-event-off="click" without success.

Same issue here.
<Flex row nowrap> <br> <a data-tip data-for='confirmation' data-event='click' > <Button /> </a> <ReactTooltip id='confirmation' data-html={true} data-effect='solid' class='confirm-buttons' multiline={true} > <span> Permanently delete? <br /> <buttonOne onClick={() => this.deleteItems(arguments)}>Yes</buttonOne> <buttonTwo onClick={() => ReactTooltip.hide()}>No</buttonTwo> </span> </ReactTooltip> ``
(Flex component imported from styled-flex-components library).

My deleteItems function works just fine, but the ReactTooltip.hide() only takes effect if i move the mouse away from the tooltip. If I don't call ReactTooltip.hide(), the tooltip stays on screen indefinitely so something is happening.Just not when I want it to. Any thoughts?

I was able to manage this with a function that handle click :

handleTooltip = () => {
    const node = findDOMNode(this.refs.clippedText);
    ReactTooltip.show(node);
    setTimeout(() => {
        ReactTooltip.hide(node);
    }, 750);
};

Then I add this to my component:

<Component
    ...
    onClick={() => {
         this.copyToClipboard();
         this.handleTooltip();
    }}
    data-tip="Text copied!"
    ref="clippedText"
/>

Finally, the "trick" is to add an unknown event to event prop so hover will not trigger show function of tooltip:

<ReactTooltip place="bottom" effect="solid" event="no-event" />

It should maybe also work specifically with the data-event prop.

Same issue here.
`
Permanently delete?
```
(Flex component imported from styled-flex-components library).

My deleteItems function works just fine, but the ReactTooltip.hide() only takes effect if i move the mouse away from the tooltip. If I don't call ReactTooltip.hide(), the tooltip stays on screen indefinitely so something is happening.Just not when I want it to. Any thoughts?

i have the same problem.do u solve the problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmyoji picture mmyoji  路  4Comments

abijames picture abijames  路  3Comments

Joseppi83 picture Joseppi83  路  4Comments

donilan picture donilan  路  4Comments

Ganasist picture Ganasist  路  3Comments