mardi 11 août 2015

Why will focus() not work in ComponentDidUpdate in ReactJS?

I'm very new to ReactJS.

In a Parent React Component, I have the following in the render function:

<div className="logos-wrapper" key="logos-wrapper">
</div>

In a Child React Component I have:

componentDidUpdate: function(){
  var targetElement = document.getElementsByClassName('hello-world-div')[0];
  var focusElement = document.activeElement;
  console.log("currently focused on: ");
  console.log(focusElement); //this shows the body element  

  targetElement.focus();
  console.log("forced focus on: ");
  console.log(focusElement); // this still shows the body element
}

Why?




Aucun commentaire:

Enregistrer un commentaire