0

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?

1 Answers1

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();
                                      }
                                }
                  }}
/>