Skip to content

Commit a3a6ee4

Browse files
committed
fix(picker): fixing up comments, test annotations
1 parent 4b430a3 commit a3a6ee4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

core/src/components/picker/picker.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ export class Picker implements ComponentInterface {
431431
/**
432432
* Attempts to intelligently search the first and second
433433
* column as if they're number columns for the provided numbers
434-
* where the first two numbers inpu are the first column
434+
* where the first two numbers are the first column
435435
* and the last 2 are the last column. Tries to allow for the first
436436
* number to be ignored for situations where typos occurred.
437437
*/
@@ -446,20 +446,31 @@ export class Picker implements ComponentInterface {
446446

447447
const inputArray = input.split('');
448448
const hourValue = inputArray.slice(0, 2).join('');
449+
// Try to find a match for the first two digits in the first column
449450
const foundHour = this.searchColumn(firstColumn, hourValue);
450451

452+
// If we have more than 2 digits and found a match for hours,
453+
// use the remaining digits for the second column (minutes)
451454
if (inputArray.length > 2 && foundHour) {
452455
const minuteValue = inputArray.slice(2, 4).join('');
453456
this.searchColumn(secondColumn, minuteValue);
454-
} else if (!foundHour && inputArray.length >= 1) {
457+
}
458+
// If we couldn't find a match for the two-digit hour, try single digit approaches
459+
else if (!foundHour && inputArray.length >= 1) {
460+
// First try the first digit as a single-digit hour
455461
let singleDigitHour = inputArray[0];
456462
let singleDigitFound = this.searchColumn(firstColumn, singleDigitHour);
463+
464+
// If that didn't work, try the second digit as a single-digit hour
465+
// (handles case where user made a typo in the first digit, or they typed over themselves)
457466
if (!singleDigitFound) {
458467
inputArray.shift();
459468
singleDigitHour = inputArray[0];
460469
singleDigitFound = this.searchColumn(firstColumn, singleDigitHour);
461470
}
462471

472+
// If we found a single-digit hour and have remaining digits,
473+
// use up to 2 of the remaining digits for the second column
463474
if (singleDigitFound && inputArray.length > 1) {
464475
const remainingDigits = inputArray.slice(1, 3).join('');
465476
this.searchColumn(secondColumn, remainingDigits);

core/src/components/picker/test/keyboard-entry/picker.e2e.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
164164
await expect(column).toHaveJSProperty('value', 12);
165165
});
166166

167-
test('should allow typing 22 in a column where the max value is 23 and not just set it to 2', async ({ page }) => {
167+
test('should allow typing 22 in a column where the max value is 23 and not just set it to 2', async ({ page }, testInfo) => {
168+
testInfo.annotations.push({
169+
type: 'issue',
170+
description: 'https://github.com/ionic-team/ionic-framework/issues/28877',
171+
});
168172
await page.setContent(
169173
`
170174
<ion-picker>
@@ -208,7 +212,11 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
208212
await expect(column).toHaveJSProperty('value', 22);
209213
});
210214

211-
test('should set value to 2 and not wait for another digit when max value is 12', async ({ page }) => {
215+
test('should set value to 2 and not wait for another digit when max value is 12', async ({ page }, testInfo) => {
216+
testInfo.annotations.push({
217+
type: 'issue',
218+
description: 'https://github.com/ionic-team/ionic-framework/issues/28877',
219+
});
212220
await page.setContent(
213221
`
214222
<ion-picker>

0 commit comments

Comments
 (0)