I am using Datetime of "react-datetime" and would like to close the calendar when I press enter on the input. How to do this?
Asked
Active
Viewed 235 times
1 Answers
0
Resolved using useRef and with the function _closeCalendar():
const refDataInicial=useRef();
...
<Datetime
ref={refDataInicial}
closeOnSelect={true}
dateFormat='DD/MM/YYYY'
timeFormat={false}
value={dataInicial}
onChange={handleChangeDataInicial}
onClose={handleCloseDataInicial}
inputProps={{
placeholder: "Data Inicial",
onKeyPress:(e)=>{
if (e.key === 'Enter'){
refDataInicial.current?._closeCalendar();
}
}
}}
/>

Ronnei Peterson
- 11
- 1