Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function useFocusManager(ref, props = {}, opts = {}) {
const isMounted = useMounted()
const [focused, setFocus] = useState(false)
const events = useFocusManagerBase({
...opts,
onChange: focused => {
if (isMounted()) setFocus(focused)
},
isDisabled: () =>
props.disabled === true || isInDisabledFieldset(ref.current),
didHandle(focused, event) {
let handler = props[focused ? 'onFocus' : 'onBlur']
if (handler) handler(event)
if (opts.didHandle && !event.isWidgetDefaultPrevented)
opts.didHandle(focused, event)
},
})
return [events, focused, setFocus]