react: Removing tabIndex from component's attributes does not remove tabIndex once set

Once a tab index has been put in place “removing” by the method seen below only ever sets it to -1, which does what I’d expect in that the element isn’t focused when tabbing, but it is still focusable by clicking directly on the element.

var attributes = {}
if (this.props.focusable) {
  attributes.tabIndex = 0;
}

return React.createElement("div", attributes, "test");

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

Maybe this changed recently, but I just tried this and it worked perfectly fine. tabindex was either there and set to ‘0’ or in the other case it was not there.

tabIndex={selected ? '0' : null}