Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap tooltip is not working with react.js

I was trying to use bootstrap tooltip on button to display complete information. But it is not working. Tooltip is not getting displayed.

Here is my react code:

<button type="button" ref="data" value={this.props.data} onClick={this.submit} className="btn btn-default btn-block" data-toggle="tooltip" data-placement="top" title={ this.props.data }>
{ this.props.data.length > 20 ?
this.props.data.substring(0, 20)+'...' : this.props.data }
</button>

I even try to include it using bootstrap's javascript method like:

<script>
$(function () {
    $('[data-toggle="tooltip"]').tooltip()
})
</script>

What should I do for it? Thank you..

like image 290
Swapnil Bhikule Avatar asked Oct 14 '15 11:10

Swapnil Bhikule


People also ask

How do I use Bootstrap Tooltip in react?

We can use the following approach in ReactJS to use the react-bootstrap Tooltip Component. Tooltip Props: arrowProps: It is used to position the tooltip arrow. id: It is just an HTML id attribute that is necessary for accessibility.

How do I enable Bootstrap Tooltip?

Initialize tooltips in bootstrap disabled buttons with the specified element and call the tooltip() method. To trigger tooltip on disabled button by wraping them in <span> span tag and <div> div tag and then adding 'data-toggle','data-placement' and 'title' attributes to it along with its values respectively.

How does Bootstrap Tooltip work?

Tooltips are opt-in for performance reasons, so you must initialize them yourself. Tooltips with zero-length titles are never displayed. Specify container: 'body' to avoid rendering problems in more complex components (like our input groups, button groups, etc). Triggering tooltips on hidden elements will not work.


Video Answer


1 Answers

I can only guess without a demo that you are calling .tooltip on document ready, but before the component has actually rendered.

Try:

componentDidMount: function() {
  this.attachTooltip();
},

componentDidUpdate: function() {
  this.attachTooltip();
},

attachTooltip: function() {
  $(this.refs.data).tooltip();
  // Or for React <0.14 -
  // $(this.refs.data.getDOMNode()).tooltip();
}

PS consider giving your button ref a more meaningful name than 'data'

like image 186
Dominic Avatar answered Sep 21 '22 13:09

Dominic