问题
Seems impossible to place <Tooltip>
"on top" (stacked/layered above) the triggering anchor element.
It always appears outside the parent, using "placement"
to decide where. I believe it's the Flip tool within Popper that manages placement and ensures visibility. I've tried passing Popper option modifiers to disable flip, and adjusting the offset. Some recommendations were to skip preventing overflow, and disable GPU acceleration. I'm down a rabbit-hole of MaterialUI internals to accomplish this. I commented out what seems like unlikely overkill solutions.
Example outside MUI: react-tooltip (includes pointer tracking, beyond this question).
<Tooltip title="My Label" placement="top" PopperProps={{
popperOptions: {
modifiers: {
flip: { enabled: false },
// computeStyle: {
// gpuAcceleration: false
// },
// preventOverflow: {
// enabled: false,
// padding: 0
// },
offset: {
offset: '-20px -20px'
}
}
}
}}></Tooltip>
<h3>My Text</h3>
</Tooltip>
回答1:
You need to enable the offset like this:
<Tooltip title="My Label" placement="top" PopperProps={{
popperOptions: {
modifiers: {
flip: { enabled: false },
offset: {
enabled: true,
offset: '0px -60px'
}
}
}
}}>
<h3>My Text</h3>
</Tooltip>
this will enable you to place the tooltip on top
来源:https://stackoverflow.com/questions/61112311/place-materialui-tooltip-on-top-of-anchor-element-react