From a3a6ee4a24d71739d1f04a348e23cec159aedbb4 Mon Sep 17 00:00:00 2001 From: ShaneK Date: Wed, 26 Mar 2025 09:38:48 -0700 Subject: [PATCH] fix(picker): fixing up comments, test annotations --- core/src/components/picker/picker.tsx | 15 +++++++++++++-- .../picker/test/keyboard-entry/picker.e2e.ts | 12 ++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/src/components/picker/picker.tsx b/core/src/components/picker/picker.tsx index 5e12754c80..71db6a3cac 100644 --- a/core/src/components/picker/picker.tsx +++ b/core/src/components/picker/picker.tsx @@ -431,7 +431,7 @@ export class Picker implements ComponentInterface { /** * Attempts to intelligently search the first and second * column as if they're number columns for the provided numbers - * where the first two numbers inpu are the first column + * where the first two numbers are the first column * and the last 2 are the last column. Tries to allow for the first * number to be ignored for situations where typos occurred. */ @@ -446,20 +446,31 @@ export class Picker implements ComponentInterface { const inputArray = input.split(''); const hourValue = inputArray.slice(0, 2).join(''); + // Try to find a match for the first two digits in the first column const foundHour = this.searchColumn(firstColumn, hourValue); + // If we have more than 2 digits and found a match for hours, + // use the remaining digits for the second column (minutes) if (inputArray.length > 2 && foundHour) { const minuteValue = inputArray.slice(2, 4).join(''); this.searchColumn(secondColumn, minuteValue); - } else if (!foundHour && inputArray.length >= 1) { + } + // If we couldn't find a match for the two-digit hour, try single digit approaches + else if (!foundHour && inputArray.length >= 1) { + // First try the first digit as a single-digit hour let singleDigitHour = inputArray[0]; let singleDigitFound = this.searchColumn(firstColumn, singleDigitHour); + + // If that didn't work, try the second digit as a single-digit hour + // (handles case where user made a typo in the first digit, or they typed over themselves) if (!singleDigitFound) { inputArray.shift(); singleDigitHour = inputArray[0]; singleDigitFound = this.searchColumn(firstColumn, singleDigitHour); } + // If we found a single-digit hour and have remaining digits, + // use up to 2 of the remaining digits for the second column if (singleDigitFound && inputArray.length > 1) { const remainingDigits = inputArray.slice(1, 3).join(''); this.searchColumn(secondColumn, remainingDigits); diff --git a/core/src/components/picker/test/keyboard-entry/picker.e2e.ts b/core/src/components/picker/test/keyboard-entry/picker.e2e.ts index 036d80bf54..eaaad1f047 100644 --- a/core/src/components/picker/test/keyboard-entry/picker.e2e.ts +++ b/core/src/components/picker/test/keyboard-entry/picker.e2e.ts @@ -164,7 +164,11 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => await expect(column).toHaveJSProperty('value', 12); }); - test('should allow typing 22 in a column where the max value is 23 and not just set it to 2', async ({ page }) => { + test('should allow typing 22 in a column where the max value is 23 and not just set it to 2', async ({ page }, testInfo) => { + testInfo.annotations.push({ + type: 'issue', + description: 'https://github.com/ionic-team/ionic-framework/issues/28877', + }); await page.setContent( ` @@ -208,7 +212,11 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => await expect(column).toHaveJSProperty('value', 22); }); - test('should set value to 2 and not wait for another digit when max value is 12', async ({ page }) => { + test('should set value to 2 and not wait for another digit when max value is 12', async ({ page }, testInfo) => { + testInfo.annotations.push({ + type: 'issue', + description: 'https://github.com/ionic-team/ionic-framework/issues/28877', + }); await page.setContent( `