4
rated 0 times
[
6]
[
2]
/ answers: 1 / hits: 64719
/ 8 Years ago, sat, april 9, 2016, 12:00:00
How would I set the tabIndex
attribute on a React component conditionally in the same way, say the disabled
attribute is set?
I need to be able to set the value and/or remove the attribute all together.
First try was to make the entire attribute key and value a variable:
<div { tabIndex } ></div>
but the compiler complains.
Second thought was to:
const div;
if( condition ){
div = <div tabIndex="1"></div>
}else{
div = <div></div>
}
However, this is not desirable since my actual components have tons of attributes on them and I'd end up having large amounts of duplicate code.
My only other thought was to use a ref, then use jQuery to set the tabindex
attributes, but I would rather not have to do it that way.
Any Ideas?
More From » reactjs