Answers for "how to trigger on Blur only when clicked outside parent component and not child component in react js"

0

how to trigger on Blur only when clicked outside parent component and not child component in react js

// assign handleBlur to parent's onBlur i.e. <Parent onBlur={handleBlur} />
handleBlur(event) {
    // currentTarget is the parent element, relatedTarget is the clicked element
    if (!event.currentTarget.contains(event.relatedTarget)) {
        // code when clicked outside parent and children components
    }
}
Posted by: Guest on August-23-2021

Code answers related to "how to trigger on Blur only when clicked outside parent component and not child component in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language