0

I have the following element in my HTML in React:

<p className={`
    cbds-c-progressStepper__stepText${step.state === 'complete' ? 
    "--complete" : ""}${step.state === 'current' ? 
    "--current" : ""}${step.state === 'incomplete' ? 
    "--incomplete" : ""}`
      }
      aria-current={`${step.state === 'current' ? 'step' : ''}`}
>

I only want to include the 'aria-current' attribute on the current step. Otherwise, I don't want it to exist on the element at all.

Here's what I have tried:

1) aria-current={`${step.state === 'current' ? 'step' : ''}`}
2) aria-current={`${step.state === 'current' ? 'step' : **null**}`}
3) I have also tried creating a prop, setting it to false and then applying it to the attribute, which, according to what I have read, should completely omit the attribute from the element -- but that didn't happen. 

Number 1 set an empty aria-current attribute with no value. Like this: aria-current, but that goes against ADA compliance. It shouldn't be there at all.

Number 2 just set it to false. It shouldn't be there at all.

Can anyone please tell me how to make this happen in React?

Thanks!

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
RB50
  • 41
  • 8
  • 1
    Have a look at the [second](https://stackoverflow.com/a/31164357/1650337) or [third](https://stackoverflow.com/a/35428331/1650337) answers on the duplicate question (the top answer will leave you with an empty prop) You can expand an object full of properties and conditionally include/exclude the prop from that object. – DBS Jul 19 '23 at 14:11
  • Removed tag 'ada' - the programming language. – Simon Wright Jul 19 '23 at 15:35

0 Answers0