From 554ca1e4258179804cc4daac764b61c70de6dbb6 Mon Sep 17 00:00:00 2001 From: delangle Date: Mon, 6 Feb 2023 17:50:57 +0100 Subject: [PATCH] [fields] Support Backspace key on Android --- .../x-date-pickers/src/internals/hooks/useField/useField.ts | 6 ++++++ .../src/internals/hooks/useField/useFieldState.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/packages/x-date-pickers/src/internals/hooks/useField/useField.ts b/packages/x-date-pickers/src/internals/hooks/useField/useField.ts index c811d4a511daa..6922276d01d96 100644 --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.ts +++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.ts @@ -372,6 +372,12 @@ export const useField = < return () => window.clearTimeout(focusTimeoutRef.current); }, []); // eslint-disable-line react-hooks/exhaustive-deps + React.useEffect(() => { + if (state.tempValueStrAndroid != null && selectedSectionIndexes != null) { + clearActiveSection(); + } + }, [state.tempValueStrAndroid]); // eslint-disable-line react-hooks/exhaustive-deps + const valueStr = React.useMemo( () => state.tempValueStrAndroid ?? fieldValueManager.getValueStrFromSections(state.sections), [state.sections, fieldValueManager, state.tempValueStrAndroid], diff --git a/packages/x-date-pickers/src/internals/hooks/useField/useFieldState.ts b/packages/x-date-pickers/src/internals/hooks/useField/useFieldState.ts index 2dcab9e618cfe..f454b09e91ec0 100644 --- a/packages/x-date-pickers/src/internals/hooks/useField/useFieldState.ts +++ b/packages/x-date-pickers/src/internals/hooks/useField/useFieldState.ts @@ -242,6 +242,7 @@ export const useFieldState = < return setState((prevState) => ({ ...prevState, sections: newSections, + tempValueStrAndroid: null, ...newValue, })); };