@carbon/ibm-products
Version:
Carbon for IBM Products
32 lines (30 loc) • 914 B
JavaScript
/**
* 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.
*/
require("../../../_virtual/_rolldown/runtime.js");
let react = require("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] = (0, react.useState)(document.activeElement);
const handleFocusIn = () => {
setActive(document.activeElement);
};
(0, react.useEffect)(() => {
document.addEventListener("focusin", handleFocusIn);
return () => {
document.removeEventListener("focusin", handleFocusIn);
};
}, []);
return active;
};
//#endregion
exports.useActiveElement = useActiveElement;