Add listener to clear date pickers on certain keystrokes
This commit is contained in:
parent
181143935e
commit
6b6699c857
|
@ -26,12 +26,21 @@
|
||||||
fieldApi.setValue(dates[0])
|
fieldApi.setValue(dates[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearDateOnBackspace = event => {
|
||||||
|
if (["Backspace", "Clear", "Delete"].includes(event.key)) {
|
||||||
|
fieldApi.setValue(null)
|
||||||
|
flatpickr.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onOpen = () => {
|
const onOpen = () => {
|
||||||
open = true
|
open = true
|
||||||
|
document.addEventListener("keyup", clearDateOnBackspace)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
open = false
|
open = false
|
||||||
|
document.removeEventListener("keyup", clearDateOnBackspace)
|
||||||
|
|
||||||
// Manually blur all input fields since flatpickr creates a second
|
// Manually blur all input fields since flatpickr creates a second
|
||||||
// duplicate input field.
|
// duplicate input field.
|
||||||
|
|
Loading…
Reference in New Issue