UNPKG

@carbon/ibm-products

Version:
31 lines (29 loc) 840 B
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { useEffect, useState } from "react"; //#region src/global/js/hooks/useActiveElement.js /** * Copyright IBM Corp. 2022, 2022 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const useActiveElement = () => { const [active, setActive] = useState(document.activeElement); const handleFocusIn = () => { setActive(document.activeElement); }; useEffect(() => { document.addEventListener("focusin", handleFocusIn); return () => { document.removeEventListener("focusin", handleFocusIn); }; }, []); return active; }; //#endregion export { useActiveElement };