ok right now the tooltip.left or right is not correctly updating on display... why?…
- User
ok right now the tooltip.left or right is not correctly updating on display... why? const Highlight = ({ children, id }: { children: React.ReactNode, id: string }) => { const [isVisible, setIsVisible] = useState(false); const tooltipRef = useRef<HTMLSpanElement | null>(null);
useEffect(() => { if (isVisible) { const tooltip = document.getElementById('ignore'+id) console.log(tooltip) if (tooltip) { const parent = document.getElementById(id); const ancestor = document.getElementById(MESSAGE_LIST_CONTAINER_ID+"ANNOT"); console.log(parent) console.log(ancestor) if (parent && ancestor) { const parentRect = parent.getBoundingClientRect(); const ancestorRect = ancestor.getBoundingClientRect(); const tooltipRect = tooltip.getBoundingClientRect();
codeconsole.log(tooltipRect) console.log("board rect") console.log(ancestorRect) let top = parentRect.bottom; let left = parentRect.left; let right = parentRect.right; if (tooltipRect.right > ancestorRect.right) { right = ancestorRect.right; tooltip.style.right = `${right}px` } if (tooltipRect.left < ancestorRect.left) { left = ancestorRect.left; tooltip.style.left = `${left}px`; } console.log(left) console.log(right) } } }}, [isVisible, id]);
return ( <span id={id} className='highlight' onMouseEnter={() => setIsVisible(true)} onMouseLeave={() => setIsVisible(false)}> {children} {isVisible && ( <span id={'ignore'+id} className='tooltip' aria-hidden='true'> This is an annotation and its super cool!!! Blah blah blah. random test here. something something something. this is a text. )} ); };
- Assistant
- User
instead could i modify the tooltip.left and then like re render it or re apply it or something? Because i grab the element successfully im just not sure if my code overwrites it.
- Assistant
- User
your code still doesnt work, i have tooltips being rendered with left < ancestor.left...
- Assistant
- User
what happens when you set right and left ?
- Assistant