Skip to content

Commit

Permalink
Merge pull request #9895 from marmelab/fix-selectinput-resettable
Browse files Browse the repository at this point in the history
Fix `<SelectInput resettable>` does not reset the value
  • Loading branch information
fzaninotto authored Jun 10, 2024
2 parents c4be2d1 + 9d2e2bd commit 1a879e7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/ra-ui-materialui/src/input/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,24 @@ export const SelectInput = (props: SelectInputProps) => {
]);

const handleChange = useCallback(
async (eventOrChoice: ChangeEvent<HTMLInputElement> | 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<HTMLInputElement> | 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 {
Expand Down

0 comments on commit 1a879e7

Please sign in to comment.