Skip to content

Instantly share code, notes, and snippets.

View josephfraser's full-sized avatar

Joseph Fraser josephfraser

View GitHub Profile
@pstoica
pstoica / OnBlurComponent.jsx
Last active August 1, 2023 21:00
onBlur for entire react element
function OnBlurComponent({ onBlur }) {
const handleBlur = (e) => {
const currentTarget = e.currentTarget;
// Check the newly focused element in the next tick of the event loop
setTimeout(() => {
// Check if the new activeElement is a child of the original container
if (!currentTarget.contains(document.activeElement)) {
// You can invoke a callback or add custom logic here
onBlur();