๐Ÿ› /Dev Tool

[ESLint] jsx-eslint/eslint-plugin-jsx-a11y A form label must be associated with a control

ํ•œ๋‚˜ 2022. 2. 10. 18:00

<label
    className="inline-flex items-center cursor-pointer"
    htmlFor="customCheckLogin"
></label>
<input
    id="customCheckLogin"
    type="checkbox"
    className="form-checkbox border-0 rounded text-blueGray-700 ml-1 w-5 h-5 ease-linear transition-all duration-150"
/>

 

 

react ํ”„๋กœ์ ํŠธ์— ๊ด€๋ฆฌ์ž ๋Œ€์‹œ๋ณด๋“œ ํ…œํ”Œ๋ฆฟ์„ ํ•˜๋‚˜ ๊ฐ€์ง€๊ณ  ์™€์„œ ์ปค์Šคํ…€ํ•˜๋ ค๊ณ  ์ค€๋น„ ์ค‘์— ๋งŒ๋‚œ ESLint ์—๋Ÿฌ. tailwindCSS๋กœ ์Šคํƒ€์ผ๋ง๋„ ํ•˜๊ณ  ์žˆ๋‹ค.

label-has-associated-control

  • <label> ํƒœ๊ทธ๊ฐ€ ํ…์ŠคํŠธ ๋ผ๋ฒจ + ๊ด€๋ จ ์žˆ๋Š” control๋กœ ๊ตฌ์„ฑ๋˜๋„๋ก ๊ฐ•์ œํ•˜๋Š” ๋ฃฐ์ด๋‹ค.
  • ๋งŒ์ผ ์ด๊ฒŒ ๋˜์ง€ ์•Š์œผ๋ฉด, ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉํ–ฅ์€ ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

<label> ์•ˆ์— control ํƒœ๊ทธ๋ฅผ ๊ฐ์‹ธ๋Š” ๋ฐฉ๋ฒ•

<label
    className="inline-flex items-center cursor-pointer"
    htmlFor="customCheckLogin"
>
<input
    id="customCheckLogin"
    type="checkbox"
    className="form-checkbox border-0 rounded text-blueGray-700 ml-1 w-5 h-5 ease-linear transition-all duration-150"
/>
</label>

<label> ํƒœ๊ทธ ์•ˆ์— htmlFor ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์ปจํŠธ๋กค ํƒœ๊ทธ์— DOM id๋ฅผ ๋ถ™์ด๋Š” ๋ฐฉ๋ฒ•

์œ„ ์˜ˆ์‹œ์—์„œ htmlFor์™€ id๋ฅผ ๋‘˜๋‹ค ์“ฐ๊ณ  ์žˆ๋‹ค.

Reference

eslint-plugin-jsx-a11y์—์„œ ๋” ์ž์„ธํ•œ ์„ค๋ช…์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.