javascript - React-bootstrap tooltip not firing - Stack Overflow

I have a piece of code here which is supposed to display a tooltip when the user hovers over a td cell.

I have a piece of code here which is supposed to display a tooltip when the user hovers over a td cell.

import { DropdownButton, Tooltip } from 'react-bootstrap';

...

$(e.currentTarget).parent().prev().hover(() => {
    this.showTooltip(tooltipContent);
});

...

showTooltip(tooltipContent) {
    console.log(tooltipContent);
    return (
        <Tooltip placement="top" className="in" id="tooltip-top">
            tooltipContent
        </Tooltip>
    );
}

The console.log is showing the right text, but the tooltip does not show, and there is no error in the console. Am I calling the ponent correctly? Please help!

UPDATE:

Based on 1 answer, I changed my code to this:

import { DropdownButton, OverlayTrigger, Tooltip } from 'react-bootstrap';

showTooltip(tooltipContent) {
    console.log(tooltipContent);
    const tooltip = <Tooltip />;
    return (
        <OverlayTrigger placement="top" overlay={tooltip}>
            <span>tooltipContent</span>
        </OverlayTrigger>
    );
}

The calling function is the same:

$(e.currentTarget).parent().prev().hover(() => {
    this.showTooltip(tooltipContent);
});

But I still don't see any tooltip..

I have a piece of code here which is supposed to display a tooltip when the user hovers over a td cell.

import { DropdownButton, Tooltip } from 'react-bootstrap';

...

$(e.currentTarget).parent().prev().hover(() => {
    this.showTooltip(tooltipContent);
});

...

showTooltip(tooltipContent) {
    console.log(tooltipContent);
    return (
        <Tooltip placement="top" className="in" id="tooltip-top">
            tooltipContent
        </Tooltip>
    );
}

The console.log is showing the right text, but the tooltip does not show, and there is no error in the console. Am I calling the ponent correctly? Please help!

UPDATE:

Based on 1 answer, I changed my code to this:

import { DropdownButton, OverlayTrigger, Tooltip } from 'react-bootstrap';

showTooltip(tooltipContent) {
    console.log(tooltipContent);
    const tooltip = <Tooltip />;
    return (
        <OverlayTrigger placement="top" overlay={tooltip}>
            <span>tooltipContent</span>
        </OverlayTrigger>
    );
}

The calling function is the same:

$(e.currentTarget).parent().prev().hover(() => {
    this.showTooltip(tooltipContent);
});

But I still don't see any tooltip..

Share Improve this question edited Oct 9, 2016 at 12:05 user3033194 asked Oct 9, 2016 at 11:30 user3033194user3033194 1,8297 gold badges44 silver badges66 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You don't actually need to write a custom method for that, react-bootstrap has that built in. Check out the documentation: https://react-bootstrap.github.io/ponents.html#tooltips

You will have to put a <Tooltip/> element as an overlay prop in an OverlayTrigger.

var tooltip = <Tooltip />;
// ...
<OverlayTrigger placement="left" overlay={tooltip}>
  <td>Holy guacamole!</td>
</OverlayTrigger>

Or, if that breaks the layout:

var tooltip = <Tooltip />;
// ...

<td>
  <OverlayTrigger placement="left" overlay={tooltip}>
    Holy guacamole!
  </OverlayTrigger>
</td>

This code will have to be in the render() method. What you are doing right now is you just return a JSX element into nowhere, that's why the tooltip doesn't show up. It's not rendered or referenced properly in the render() method of your ponent.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745143599a4613544.html

相关推荐

  • javascript - React-bootstrap tooltip not firing - Stack Overflow

    I have a piece of code here which is supposed to display a tooltip when the user hovers over a td cell.

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信