-
-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tooltip not placed properly if in modal #130
Comments
Do you have any code to show me? you can put the
if your modal's z-index higher than the tooltip, you need to use the attribute |
@maxmatthews I did some test, can you try |
|
This is the modal I'm using BTW: https://github.com/reactjs/react-modal |
@maxmatthews Okay, I did some experiments again using react-modal and some of your code, so here I think you can follow these three steps: 1.Move
2.Add
3.I suppose that you have built a bunch of tooltip for every modal, maybe it doesn't make sense, you can just have one The key logic here is, put |
I had the same issue today, same library used, and solved it by moving Here's my code if anyone needs help: MainComponent render() {
and the MyCustomModalContent code:
Hope it helps. |
Ok, now I feel like a real idiot and must be missing something simple after such a detailed and helpful response. Now no tooltip shows up on hover. Here's my code. Master = React.createClass({
openModal(){
this.setState({
showModal: true
}, ()=>{ReactTooltip.rebuild()})
},
render() {
return <div>
<Modal
isOpen={this.state.showModal}
onRequestClose={this.closeModal}
className="modal"
overlayClassName="modalOverlay"
>
<div className="row">
<MyModalContent/>
</div>
</Modal>
<ReactTooltip
class="tooltipContent"
place="right"
type="light"
effect="solid"
html={true}
id={"myUniqueID"}/>
}
</div>
});
MyModalContent = React.createClass({
render(){
return <div>
Some text and a tooltip
<div data-for="myUniqueID"
data-tip="This is the text in the tooltip"
className="tooltipContent"></div>
</div>
}
}); |
Well now I really feel like an idiot because I just put my example code in a blank react project and it's working fine. Ignore me for now, going to debug in my master project to figure out what's causing the issue there and then will post back here. |
When I converted my code to example code to post I put the tooltip inside the modal instead of outside of it. The above code (thanks to @wwayne and @cristiandan help) works in the modal. That may be a good misc. note to add to the readme, "If using tooltips inside of |
@maxmatthews Cool, I will add the notes to README since lots of people was stuck in this. |
My problem is that my whole page where I want to place the tooltip is the modal, is there any way to do it without moving it out? @wwayne |
@itsmichaeldiego Just wrap the modal in a fragment like this:
It is a lot easier than trying to manually override the positioning of the tooltip, plus it doesn't add another layer to your DOM structure. |
Personally i've just created a component which reflect ReactTooltip and it's work fine without rebuild |
Worth adding that if you're using const Component = () => {
// rebuild on specific data changes
useEffect(() => {
ReactTooltip.rebuild();
}, [yourData]);
return (
<>
<ReactTooltip />
<Modal onAnimationEnd={() => { // !!! IMPORTANT PART
ReactTooltip.rebuild();
}}>
<p data-tip="tooltip">Etiam porta sem malesuada magna mollis euismod. Donec ullamcorper nulla non metus auctor fringilla.</p>
</Modal>
</>
);
} |
I solved it with Portal wrapper from #268 (which basically moves Tooltip to |
I solve it by calling Here's an example. interface TooltipComponentProps
extends React.HTMLAttributes<HTMLParagraphElement> {
tooltipProps?: TooltipProps;
renderWithDataTip?: GetContentFunc;
dataTip: string;
}
const TooltipComponent: React.FC<TooltipComponentProps> = ({
id,
tooltipProps,
renderWithDataTip,
dataTip,
children,
className,
...props
}) => {
useEffect(() => {
ReactTooltip.rebuild();
}, []);
return (
<>
<p className={className} data-tip={dataTip} data-for={id} {...props}>
{children}
</p>
<ReactTooltip
id={id}
getContent={renderWithDataTip ? renderWithDataTip : () => dataTip}
place={tooltipProps?.place || 'right'}
effect={tooltipProps?.effect || 'solid'}
{...tooltipProps}
/>
</>
);
};
export default TooltipComponent; |
The tooltip is being positioned on the modal itself instead of the original tooltip (with the red box around it). Any suggestions on how to get this to anchor to the proper component?
The text was updated successfully, but these errors were encountered: