From 9d2e2bd043981a5ad52458cb0cae62deecfeae65 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Mon, 3 Jun 2024 16:30:50 +0200 Subject: [PATCH] Fix `` does not reset the value --- .../ra-ui-materialui/src/input/SelectInput.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/ra-ui-materialui/src/input/SelectInput.tsx b/packages/ra-ui-materialui/src/input/SelectInput.tsx index 17962aa9995..dc98787bb7a 100644 --- a/packages/ra-ui-materialui/src/input/SelectInput.tsx +++ b/packages/ra-ui-materialui/src/input/SelectInput.tsx @@ -214,17 +214,24 @@ export const SelectInput = (props: SelectInputProps) => { ]); const handleChange = useCallback( - async (eventOrChoice: ChangeEvent | RaRecord) => { - // We might receive an event from the mui component - // In this case, it will be the choice id - if (eventOrChoice?.target) { + async ( + eventOrChoice: ChangeEvent | RaRecord | '' + ) => { + if (typeof eventOrChoice === 'string') { + if (eventOrChoice === '') { + // called by the reset button + field.onChange(emptyValue); + } + } else if (eventOrChoice?.target) { + // We might receive an event from the mui component + // In this case, it will be the choice id field.onChange(eventOrChoice); } else { // Or we might receive a choice directly, for instance a newly created one field.onChange(getChoiceValue(eventOrChoice)); } }, - [field, getChoiceValue] + [field, getChoiceValue, emptyValue] ); const {