Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #trigger #Blur #clicked #parent #component #child #component #react #js
ADD COMMENT
Topic
Name
1+8 =