UNPKG

@sberdevices/plasma-temple

Version:

SberDevices CanvasApp Templates.

30 lines (29 loc) 1.08 kB
import React from 'react'; export var useFocusOnMount = function useFocusOnMount(ref) { var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var preventScroll = params.preventScroll, _params$delay = params.delay, delay = _params$delay === void 0 ? 150 : _params$delay, _params$prevent = params.prevent, prevent = _params$prevent === void 0 ? false : _params$prevent, _params$callOnce = params.callOnce, callOnce = _params$callOnce === void 0 ? false : _params$callOnce; var calledOnce = React.useRef(false); React.useEffect(function () { if (callOnce && calledOnce.current) { return; } var timer = setTimeout(function () { if (!prevent && ref.current instanceof HTMLElement) { ref.current.focus({ preventScroll: preventScroll }); calledOnce.current = true; } }, delay); return function () { return clearTimeout(timer); }; }, [ref, prevent, preventScroll, delay, callOnce]); }; //# sourceMappingURL=useFocusOnMount.js.map