import * as React from 'react'; import { getObservedElement } from 'tabster'; import { useTabster } from './useTabster'; /** * * @param name - The observed element to focus * @returns Function that will focus the */ export function useFocusObserved(name, options = {}) { const { timeout = 1000 } = options; const tabster = useTabster(); const observedAPI = tabster ? getObservedElement(tabster) : null; return React.useCallback(()=>{ if (observedAPI) { return observedAPI.requestFocus(name, timeout); } return { result: Promise.resolve(false), cancel: ()=>null }; }, [ observedAPI, name, timeout ]); }