Mirror: React hooks for accessible, common web interactions. UI super powers without the UI.

Add ref.current element to hook dependencies

+1 -1
src/useDialogFocus.ts
···
document.body.removeEventListener('focusin', onFocus);
document.removeEventListener('keydown', onKey);
};
-
}, [ref, disabled, hasPriority]);
+
}, [ref.current!, disabled, hasPriority]);
}
+1 -1
src/useDismissable.ts
···
document.removeEventListener('touchstart', onClick);
document.removeEventListener('keydown', onKey);
};
-
}, [ref.current, hasPriority, disabled, focusLoss]);
+
}, [ref.current!, hasPriority, disabled, focusLoss]);
}
+1 -1
src/useMenuFocus.ts
···
document.body.removeEventListener('focusin', onFocus);
document.removeEventListener('keydown', onKey);
};
-
}, [ref, disabled]);
+
}, [ref.current!, disabled]);
}
+1 -1
src/useModalFocus.ts
···
document.body.removeEventListener('focusout', onBlur);
document.removeEventListener('keydown', onKeyDown);
};
-
}, [ref, hasPriority, disabled]);
+
}, [ref.current!, hasPriority, disabled]);
}
+1 -1
src/usePriority.ts
···
listeners.delete(onChange);
listeners.forEach(fn => fn());
};
-
}, [ref, isDisabled]);
+
}, [ref.current!, isDisabled]);
return hasPriority;
};
+7 -5
src/useScrollRestoration.ts
···
export function useScrollRestoration<T extends HTMLElement>(
ref: 'window' | Ref<T>
) {
+
const target = ref !== 'window' ? ref.current : ref;
+
useLayoutEffect(() => {
let unsubscribe: void | (() => void);
-
if (ref !== 'window' && !ref.current) return;
+
if (!target) return;
-
const addonId = ref === 'window' ? 'window' : ref.current!.id || '';
-
const eventTarget = ref === 'window' ? window : ref.current!;
-
const scrollTarget = ref === 'window' ? document.body : ref.current!;
+
const addonId = target === 'window' ? 'window' : target.id || '';
+
const eventTarget = target === 'window' ? window : target;
+
const scrollTarget = target === 'window' ? document.body : target;
function restoreScroll(event?: PopStateEvent) {
const id = addonId + getIdForState(event ? event.state : history.state);
···
window.removeEventListener('popstate', restoreScroll);
if (unsubscribe) unsubscribe();
};
-
}, [ref]);
+
}, [target]);
}