fix(datetime): keyboard can select hour 00 (#26423)

resolves #26409
This commit is contained in:
Liam DeBeasi
2022-12-07 15:09:27 -05:00
committed by GitHub
parent 409d813103
commit 2fc96b7714
2 changed files with 40 additions and 2 deletions

View File

@ -356,9 +356,16 @@ export class PickerInternal implements ComponentInterface {
* is "1" and we entered "2", then the complete value
* is "12" and we should select hour 12.
*
* Regex removes any leading zeros from values like "02".
* Regex removes any leading zeros from values like "02",
* but it keeps a single zero if there are only zeros in the string.
* 0+(?=[1-9]) --> Match 1 or more zeros that are followed by 1-9
* 0+(?=0$) --> Match 1 or more zeros that must be followed by one 0 and end.
*/
const findItemFromCompleteValue = values.find(({ text }) => text.replace(/^0+/, '') === inputEl.value);
const findItemFromCompleteValue = values.find(({ text }) => {
const parsedText = text.replace(/^0+(?=[1-9])|0+(?=0$)/, '');
return parsedText === inputEl.value;
});
if (findItemFromCompleteValue) {
inputModeColumn.setValue(findItemFromCompleteValue.value);
return;