react-code-input icon indicating copy to clipboard operation
react-code-input copied to clipboard

SOLVED: Component fails on second key pressing in the last input field

Open mvarakin opened this issue 4 years ago • 2 comments

Hi there,

[For solution please see below]

here is part of my code

... const [code, setCode] = useState(''); const onChange = (code) => { setCode(code) } ...

  <ReactCodeInput
    key={1}
    type="number"
    fields={4}
    name="name"
    disabled={false}
    onChange={onChange}
    style={{ width: 212 }}
    inputStyle={{ width: 44, fontSize: '1.5em' }}
  />
  

It renders 4 fields as supposed to.

When I type four numbers everything goes well - onChange invokes, code changes.

But when I press any keyboard key in the last input field once more I always got the following error (it happens also if you start to type from the last field and just press key twice)

Uncaught TypeError: Cannot assign to read only property 'display' of object '#<Object>'
at Function.assign (<anonymous>)
at t.value (ReactCodeInput.js:271)

Also this error occurs even on 1st key press if I change onChange to const onChange = (code) => null

SOLUTION

this prop style={{ width: 212 }} caused the above error

I removed it and everything worked fine

Hopefully the author fix it

Best regards..

mvarakin avatar Feb 18 '21 08:02 mvarakin

@mvarakin please create pr if you think it should be in codebase

40818419 avatar Mar 26 '21 14:03 40818419

same problem

its look like happening when use the style prop.

marefati110 avatar Jul 13 '23 17:07 marefati110