
const restoreNodes = [];
const restoreFocus = {
  create : ()=>{
    if(restoreNodes.indexOf(document.activeElement) == -1){
      restoreNodes.push(document.activeElement);
    }
  },
  remove : (index=0)=>{
    requestAnimationFrame(() => {
      if(document.body.contains(restoreNodes[index])){
        restoreNodes[index] && restoreNodes[index].focus();
        restoreNodes.splice(index,1);
      }
    })
  }
}

export default restoreFocus;