UNPKG

@braineet/ui

Version:

Braineet design system

27 lines 696 B
import { useRef } from 'react'; export var useManageFocus = function useManageFocus() { var refs = useRef([]); var addToRefs = function addToRefs(val) { if (val.el && !refs.current.find(function (v) { return v.id === val.id; })) { refs.current.push(val); } }; var removeFromRefs = function removeFromRefs(index) { refs.current.splice(index, 1); }; var focusOnPrev = function focusOnPrev(index) { if (refs.current.length > 0) { if (refs.current[index - 1]) { refs.current[index - 1].el.focus(); } } }; return { refs: refs, addToRefs: addToRefs, removeFromRefs: removeFromRefs, focusOnPrev: focusOnPrev }; };