Home > front end >  How todisable keyboard in react-datetime
How todisable keyboard in react-datetime

Time:09-29

I'm using react date time to select a year. The problem is if I press any button with keyboard, it shows an error. Is there a way to disable keyboard on that input?

 <Datetime initialValue='' timeFormat={false} dateFormat="YYYY" onChange={(date) => setYear(date.year())} />

thank you

CodePudding user response:

I had same issue once. Passing readyOnly prop to the component solved it for me.

InputProps={{readOnly: true}}

CodePudding user response:

It worked like this

<Datetime initialValue='' timeFormat={false} dateFormat="YYYY" onChange={(date) => setYear(date.year())} inputProps={{ onKeyDown: (e) => { e.preventDefault() } }} />
  • Related