so right now on hover the tooltip displays, however for other chidlren of higlight, can…
- User
so right now on hover the tooltip displays, however for other chidlren of higlight, can i not display the hover? bc rn when i interact with other child elements it displays the tooltip which isnt what i want. import { useState, useEffect } from 'react'; import React from 'react';
export const Highlight = ({ children, id, annotation }: { children: React.ReactNode, id: string, annotation:string }) => { const [isVisible, setIsVisible] = useState(false);
return ( <span id={id} className='highlight non-selectable' onMouseEnter={() => setIsVisible(true)} onMouseLeave={() => setIsVisible(false)}> {children} {isVisible && ( <span id={'tool'+id} className='tooltip non-selectable' aria-hidden='true'> {annotation} </span> )} </span> );};
- Assistant
Your issue arises because the tooltip visibility is controlled by the hover state of the parent
spanwith classhighlight. When you interact with any children within this parent, theonMouseEnterandonMouseLeaveevents are triggered, causing the tooltip to appear or disappear even when hovering over these child elements.To fix this, you can add a condition to only show the tooltip when hovering over the
Highlightspan directly and not its children. One way to accomplish this is by checking the event target in the and handlers. - User
that code did not work?
- Assistant
I apologize for the inconvenience. If the previous solution did not work, we can try another approach where we use event delegation and careful control of the hover state.
- User
what input box types are there?
- Assistant
- User
i have an input box, how do i set it so only alpha numerica characters are allowed? and brackets and stuff but no backticks asterisks or <>
- Assistant