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..
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.
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With