我正在使用"react- Datetime“的datetime,当我在输入上按enter时,我想关闭日历。该怎么做呢?
发布于 2021-07-29 01:20:32
使用useRef和_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();
}
}
}}
/>https://stackoverflow.com/questions/68552660
复制相似问题