i have an input container, how do i detect when its open and if the user presses escape…
- User
i have an input container, how do i detect when its open and if the user presses escape close it? <input type='text' style={{ fontSize: '14px', // Adjust the font size as needed height: '2rem', // Adjust the height as needed width: '200px', // Adjust the width as needed padding: '0.5rem', // Adjust the padding as needed lineHeight: '150%', // Adjust the line height as needed fontFamily: 'Arial, sans-serif' // Adjust the font family as needed }} className={cn( 'min-h-[1rem] md:min-h-[2rem]', "w-auto", 'self-center', 'rounded', 'px-1 px-2', 'border', 'bg-danger-50', 'text-lg', 'w-full',
'border-secondary-400', 'transition ease-in-out', 'focus:border-secondary-700', 'focus:outline-none', 'placeholder-base' )} placeholder="Add annotation . . ." onKeyDown={(e) => { if (e.key === "Enter") { const target = e.target as HTMLInputElement; console.log(annotationKey) console.log("TEXT",message.text) setAnnotDict(prevDict => ({ ...prevDict, [annotationKey]: { ...prevDict[annotationKey], annotation: target.value } })); //Temporary dict for this single render. let ad = annotDict ad[annotationKey].annotation = target.value ad = sortAnnotDict(ad) setSortAnnotDict(ad) setAnnotationVisible(false); setAnnotationKey("") target.value = ""; } else if(e.key === "Escape"){ removeAnnotation(annotationKey, annotSortDict) setAnnotationKey("") } }} - Assistant
- User
like in particular, when the annotation box is showing. I want escape to close it. Right now it closes when the user is typing inside and presses escape.
- Assistant
- User
what is the logic window.addEvent and removeEvent for?
- Assistant
- User
useEffect(() => { const handleEscape = (event) => { if (event.key === 'Escape' && annotationVisible) { // Logic to close the annotation box and clean up setAnnotationVisible(false); removeAnnotation(annotationKey, annotSortDict); setAnnotationKey(''); } }; Parameter 'event' implicitly has an 'any' type.ts(7006) (parameter) event: any
- Assistant
- User
I need to hide the textConent of this span from my react nodes. How? <span id={'tool'+id} className='tooltip' aria-hidden='true'> {annotation}
- Assistant
- User
ok modify this code and implement it here: export const Highlight = ({ children, id, annotation }: { children: React.ReactNode, id: string, annotation:string }) => { const [isVisible, setIsVisible] = useState(false);
return ( <span id={id} className='highlight' onMouseEnter={() => setIsVisible(true)} onMouseLeave={() => setIsVisible(false)}> {children} {isVisible && ( <span id={'tool'+id} className='tooltip' aria-hidden='true'> {annotation} </span> )} </span> );};
- Assistant