Framework/React

[React] Input elements should have autocomplete attributes (suggested: "current-password") Error ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

yuri lee 2024. 2. 16. 09:02
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. React์—์„œ MUI์˜ TextField๋ฅผ ์‚ฌ์šฉํ•˜๋˜ ๋„์ค‘ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.  

 

Input elements should have autocomplete attributes (suggested: "current-password")

 

  <TextField
    value={value}
    onBlur={onBlur}
    label='์‚ฌ์šฉ์ž ๊ณ„์ •(์•„์ด๋””)'
    placeholder='์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”'
    onChange={onChange}
    error={Boolean(errors.userId)}
    type={'text'}
    color='secondary'
    variant='standard'
    autoComplete='on'
  />

 

How to solve problem

ํ•ด๋‹น ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ์ด์œ ๋Š” autocomplete ์†์„ฑ์„ ๋ช…์‹œํ•˜์ง€ ์•Š์•„์„œ์ž…๋‹ˆ๋‹ค.  autoComplete ์†์„ฑ์ด๋ž€  ํผ ํ•„๋“œ์— ๋ธŒ๋ผ์šฐ์ €์˜ ์ž๋™ ์™„์„ฑ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

 

๋ธŒ๋ผ์šฐ์ €๋Š” ์ข…์ข… ์‚ฌ์šฉ์ž๊ฐ€ ์ด์ „์— ์ž…๋ ฅํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ์–ตํ•˜๊ณ , ์œ ์‚ฌํ•œ ์ž…๋ ฅ ํ•„๋“œ๊ฐ€ ๋‚˜ํƒ€๋‚  ๋•Œ ์ด๋ฅผ ์ž๋™์œผ๋กœ ์™„์„ฑํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž๊ฐ€ ์ด์ „์— ์ž…๋ ฅํ•œ ์ด๋ฉ”์ผ ์ฃผ์†Œ๋‚˜ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ๊ธฐ์–ตํ•˜์—ฌ ๋‹ค์Œ์— ํ•ด๋‹น ํ•„๋“œ์— ๋‹ค์‹œ ์ž…๋ ฅํ•  ๋•Œ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ž๋™์œผ๋กœ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

autoComplete ์†์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐ’๋“ค์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • on: ๋ธŒ๋ผ์šฐ์ €์˜ ์ž๋™ ์™„์„ฑ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.
  • off: ๋ธŒ๋ผ์šฐ์ €์˜ ์ž๋™ ์™„์„ฑ ๊ธฐ๋Šฅ์„ ๋น„ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.

**autoComplete="off"**์„ ์„ค์ •ํ•˜๋ฉด ํ•ด๋‹น ํผ ํ•„๋“œ์— ๋Œ€ํ•œ ์ž๋™ ์™„์„ฑ์ด ๋น„ํ™œ์„ฑํ™”๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๋ณด์•ˆ์ƒ์˜ ์ด์œ ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ ํ•„๋“œ์™€ ๊ฐ™์ด ๋ฏผ๊ฐํ•œ ์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ์™„์ „ํžˆ ๋น„ํ™œ์„ฑํ™”ํ•˜๊ณ ์ž ํ•  ๋•Œ์—๋„ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. autoComplete ์†์„ฑ์€ ํผ ํ•„๋“œ๋งˆ๋‹ค ๊ฐœ๋ณ„์ ์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฏผ๊ฐํ•œ ์ •๋ณด๋‚˜ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ์ œ์–ดํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

  <TextField
    value={value}
    onBlur={onBlur}
    label='์‚ฌ์šฉ์ž ๊ณ„์ •(์•„์ด๋””)'
    placeholder='์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”'
    onChange={onChange}
    error={Boolean(errors.userId)}
    type={'text'}
    color='secondary'
    variant='standard'
    autoComplete='on'
  />

 

๋‹ค์Œ๊ณผ ๊ฐ™์ด TextFeild ํƒœ๊ทธ์— autoComplete ์†์„ฑ์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ์—๋Ÿฌ๊ฐ€ ์‚ฌ๋ผ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. 


https://bobbyhadz.com/blog/input-elements-should-have-autocomplete-attributes

๋ฐ˜์‘ํ˜•