0

I have read that htmlFor needs to be added to fix this error, but even with this piece of code, ESlint gives me an error. How can I fix this?

        <input readOnly type="radio" name="slider-2" id="s1-2" checked />
        <input readOnly type="radio" name="slider-2" id="s2-2" />
        <input readOnly type="radio" name="slider-2" id="s3-2" />

        <label type="text" htmlFor="s1-2" id="slide1-2">
          <div className="slider-image">
            <img src={SecendQadroFirst} alt="qadro" />
          </div>
        </label>
        <label htmlFor="s2-2" id="slide2-2">
          <div className="slider-image">
            <img src={SecendQadroSecend} alt="qadro" />
          </div>
        </label>
        <label htmlFor="s3-2" id="slide3-2">
          <div className="slider-image">
            <img src={SecendQadroThird} alt="qadro" />
          </div>
        </label>
Anta
  • 97
  • 8

2 Answers2

2

You need to put the input between the label itself and ensure that you have the htmlFor attribute for the label.

<label type="text" htmlFor="s1-2" id="slide1-2">
   <div className="slider-image">
      <img src={SecendQadroFirst} alt="qadro" />
   </div>
   <input readOnly type="radio" name="slider-2" id="s1-2" checked />
</label>
Iwalewa Fawaz
  • 82
  • 1
  • 6
-1

The attribute you want in the <label> element is simply for, and the value must be the id of the <input> element it is associated with. The input should be after the </label> closing tag

<label type="text" for="s1-2" id="slide1-2">
   <div className="slider-image">
      <img src={SecendQadroFirst} alt="qadro">
   </div>
</label>
<input readOnly type="radio" name="slider-2" id="s1-2" checked>

<label for="s2-2" id="slide2-2">
   <div className="slider-image">
      <img src={SecendQadroSecend} alt="qadro">
   </div>
</label>
<input readOnly type="radio" name="slider-2" id="s2-2">
        
        
<label for="s3-2" id="slide3-2">
   <div className="slider-image">
       <img src={SecendQadroThird} alt="qadro">
   </div>
</label>
<input readOnly type="radio" name="slider-2" id="s3-2">

nigh_anxiety
  • 1,428
  • 2
  • 4
  • 12