From 65b0d24903aa1df18febf37bb66b830982fd20ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 24 Jul 2022 18:07:42 +0200 Subject: [PATCH] fix(frontend): crash when resetting DateSelect values --- frontend/src/components/inputs/DateSelect.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/inputs/DateSelect.tsx b/frontend/src/components/inputs/DateSelect.tsx index 8ab7f2a..18e21ac 100644 --- a/frontend/src/components/inputs/DateSelect.tsx +++ b/frontend/src/components/inputs/DateSelect.tsx @@ -24,7 +24,16 @@ export const DateSelect: React.FC = ({ className="block appearance-none min-w-full md:win-w-0 md:w-1/4 bg-white border border-gray-400 hover:border-gray-500 p-2 rounded shadow leading-tight focus:outline-none focus:ring" type="date" value={formatDateForDateInput(value)} - onChange={(e) => onChange(parseDateFromDateInput(e.target.value))} + onChange={(e) => { + if (e.target.value === "") { + // Firefox includes "reset" buttons in date inputs, which set the value to "", + // is does not make sense to clear the value in our case. + e.target.value = formatDateForDateInput(value); + e.preventDefault(); + return; + } + onChange(parseDateFromDateInput(e.target.value)); + }} /> );