diff --git a/core/src/components/picker-internal/picker-internal.tsx b/core/src/components/picker-internal/picker-internal.tsx index ae91d97845..764cfde9c6 100644 --- a/core/src/components/picker-internal/picker-internal.tsx +++ b/core/src/components/picker-internal/picker-internal.tsx @@ -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; diff --git a/core/src/components/picker-internal/test/keyboard-entry/picker-internal.e2e.ts b/core/src/components/picker-internal/test/keyboard-entry/picker-internal.e2e.ts index 24be31b39d..710c0f6937 100644 --- a/core/src/components/picker-internal/test/keyboard-entry/picker-internal.e2e.ts +++ b/core/src/components/picker-internal/test/keyboard-entry/picker-internal.e2e.ts @@ -89,4 +89,35 @@ test.describe('picker-internal: keyboard entry', () => { await expect(secondIonChange).toHaveReceivedEventDetail({ text: '24', value: 24 }); await expect(secondColumn).toHaveJSProperty('value', 24); }); + + test('should select 00', async ({ page }) => { + await page.setContent(` + + + + + + `); + + const column = page.locator('ion-picker-column-internal'); + const ionChange = await page.spyOnEvent('ionChange'); + await column.focus(); + + await page.keyboard.press('Digit0'); + + await expect(ionChange).toHaveReceivedEventDetail({ text: '00', value: 12 }); + await expect(column).toHaveJSProperty('value', 12); + }); });