diff --git a/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx b/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx index bd0311e210bb..d9736f41ad51 100644 --- a/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx +++ b/packages/x-date-pickers/src/TimeField/tests/editing.TimeField.test.tsx @@ -621,6 +621,13 @@ describe(' - Editing', () => { keyStrokes: [{ value: 'p', expected: 'PM' }], }); }); + + it('should not edit when pressing the Space key', () => { + testFieldChange({ + format: adapter.formats.hours24h, + keyStrokes: [{ value: ' ', expected: 'hh' }], + }); + }); }); describeAdapters( diff --git a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts index 34b84f4fa72d..1d5719f585e8 100644 --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts +++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts @@ -169,7 +169,8 @@ export const applyLocalizedDigits = (valueStr: string, localizedDigits: string[] export const isStringNumber = (valueStr: string, localizedDigits: string[]) => { const nonLocalizedValueStr = removeLocalizedDigits(valueStr, localizedDigits); - return !Number.isNaN(Number(nonLocalizedValueStr)); + // `Number(' ')` returns `0` even if ' ' is not a valid number. + return nonLocalizedValueStr !== ' ' && !Number.isNaN(Number(nonLocalizedValueStr)); }; /**