Skip to content

Commit

Permalink
[fields] Do not apply digit editing when pressing Space (#13510)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored Jun 17, 2024
1 parent 29b9131 commit 3dd5071
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,13 @@ describe('<TimeField /> - 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

/**
Expand Down

0 comments on commit 3dd5071

Please sign in to comment.