UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

25 lines (21 loc) 623 B
/** * Copyright IBM Corp. 2020, 2025 * * 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 { useState, useEffect } from 'react'; 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; }; export { useActiveElement };