Action on blur except when specific element clicked with react OR how to get clicked element onBlur

Viewed 1056

I want to prevent onBlur event when I click on a specific element:

<input type="text" onBlur={<call when I click outside of element except when I click on a specific element>} />
1 Answers

What you could do is give the element that would stop the call an ID and then check for that ID via event.relatedTarget.id

    const doSomething = (event) => {
        if(event.relatedTarget.id === "badButton"){
            return
        }
        //Do things
    }

    return(
        <div className="DashboardHeader" onBlur={(e) => doSomething(e)}>
            <button id="badButton">newbutton</button>
        </div>
    )
Related