How to place a tooltip for the react-bootstrap tab component

馋奶兔 提交于 2021-01-29 09:40:46

问题


I have three tabs , I need to place a tool tip on hover on those tabs,I am using bootstrap tabs.(Its a react application.)

import { Tabs,Tab} from "react-bootstrap";
// inside return
 <Tabs
      variant="pills"
      className="mb-3"
      activeKey={key}
     >
        <Tab eventKey="managed" title="Managed" Tooltip="hello"/>
        <Tab eventKey="unmanaged" title="Unmanaged"/>
        <Tab eventKey="source" title="Source"/>
</Tabs>

I need a tool tip appear whenever the Mouse pointer is placed on the Tab Header, for example I need a tooltip when the mouse pointer is on Managed tab . Here are the tabs


回答1:


you can use TabContainer along with OverlayTrigger to show a tooltip on top,

const TooltipTopNavItem = ({title, tooltipMessage, eventKey}) => {
  return (
    <OverlayTrigger
      key={`${eventKey}-top`}
      placement={'top'}
      overlay={
        <Tooltip id={`tooltip-top`}>
         {tooltipMessage}
        </Tooltip>
      }
  >
    <Nav.Item>
      <Nav.Link eventKey={eventKey}>{title}</Nav.Link>
    </Nav.Item>
  </OverlayTrigger>
  )
}

and use the above custom component in the TabContainer,

<Tab.Container id="tabs-example" activeKey={key}>
  <Row>
    <Col sm={3}>
      <Nav variant="pills" className="flex-column">
        <TooltipTopNavItem title={'Managed'} tooltipMessage={'Managed tooltip'} eventKey={"managed"} />
        <TooltipTopNavItem title={'Unmanaged'} tooltipMessage={'Unmanaged tooltip'} eventKey={"unmanaged"} />
        <TooltipTopNavItem title={'Source'} tooltipMessage={'Source tooltip'} eventKey={"source"} />
      </Nav>
    </Col>
    <Col sm={9}>
      <Tab.Content>
        <Tab.Pane eventKey="managed">
           In managed tab
        </Tab.Pane>
        <Tab.Pane eventKey="unmanaged">
          In Unmanaged tab
        </Tab.Pane>
        <Tab.Pane eventKey="source">
          In source tab
        </Tab.Pane>
      </Tab.Content>
    </Col>
  </Row>
</Tab.Container>

this is just an example, you can modify the TabContainer and TooltipTopNavItem based on your use-case.



来源:https://stackoverflow.com/questions/60770136/how-to-place-a-tooltip-for-the-react-bootstrap-tab-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!