Ok so have done it this way see if that helps you. Not a very react(y) way of doing it though.
return (
<OverlayTrigger placement="top" overlay={this.tooltip} onEntering={this.entering}>
<Button">Hover on me</Button>
</OverlayTrigger>
);
tooltip = (
<Tooltip id="tooltip"><strong>This is the tooltip. Yeah!</Tooltip>
);
// Set your color here
entering = (e) => {
e.children[0].style.borderTopColor = 'green';
e.children[1].style.backgroundColor = 'green';
};
Answer from hendrixchord on Stack OverflowOk so have done it this way see if that helps you. Not a very react(y) way of doing it though.
return (
<OverlayTrigger placement="top" overlay={this.tooltip} onEntering={this.entering}>
<Button">Hover on me</Button>
</OverlayTrigger>
);
tooltip = (
<Tooltip id="tooltip"><strong>This is the tooltip. Yeah!</Tooltip>
);
// Set your color here
entering = (e) => {
e.children[0].style.borderTopColor = 'green';
e.children[1].style.backgroundColor = 'green';
};
.tooltip > div.tooltip-inner {
background-color: @accentColor !important;
color: @whiteColor !important;
}
.tooltip.show {
opacity: 1 !important;
}
.tooltip > div.arrow::before {
border-bottom-color: @accentColor !important;
color: @whiteColor !important;
}
<html></html>
Without using refs / React DOM, you can select tooltips by data-toggle attribute:
componentDidMount() {
$('[data-toggle="tooltip"]').tooltip();
}
componentDidUpdate() {
$('[data-toggle="tooltip"]').tooltip();
}
Source: Bootstrap documentation
Note, if you're loading jQuery by CDN, you can refer to it by window.$ as well.
I know it s an old question, but to avoid side effects with bootstrap/jquery/react, if you want tooltips, use this :
https://www.npmjs.com/package/react-tooltip
It's very easy to use and works better than bootstrap tooltip in a react project
» npm install react-bootstrap-tooltip-button
You don't need to use react-bootstrap at all since Bootstrap 5 is now vanilla JavaScript...
You can import Bootstrap 5 JS components like this (note .esm version for modular importing)...
import { Tooltip } from 'bootstrap.esm.min.js'
then you can refer to the Tooltip like this...
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
return () => {
tooltipList.map(t => t.dispose())
}
React Bootstrap Tooltip example
This is my vanilla TypeScript version.
Install and import bootstrap & typings
npm i @types/bootstrap bootstrapimport "bootstrap" import "bootstrap/dist/css/bootstrap.css"Create
Tooltipcomponentimport { Tooltip as BsTooltip } from "bootstrap" import React, { useEffect, useRef } from "react" export const Tooltip = (p: {children: JSX.Element, text: string}) => { const childRef = useRef(undefined as unknown as Element) useEffect(() => { const t = new BsTooltip(childRef.current, { title: p.text, placement: "right", trigger: "hover" }) return () => t.dispose() }, [p.text]) return React.cloneElement(p.children, { ref: childRef }) }Use
<Tooltip text="Tooltip text"> <button className="btn btn-primary" type="button">My button</button> </Tooltip>