I use popper.js to attach a tooltip to a text selection.
function generateGetBoundingClientRect(rangeRect) {
return () => ({
width: rangeRect.width,
height: rangeRect.height,
top: rangeRect.top,
right: rangeRect.right,
bottom: rangeRect.bottom,
left: rangeRect.left,
});
}
const range = document.getSelection().getRangeAt(0)
const positionElement = {
getBoundingClientRect: this.generateGetBoundingClientRect(range.getBoundingClientRect()),
};
const instance = createPopper(positionElement, menu, {placement: 'top'});
Unfortunately, the so-created menu is not fixed to the selection but scrolls with the viewport. As this is achieved by translate()
, I assume there is an option in popper.js to turn that of?