diff --git a/core/src/components/picker-column/picker-column.tsx b/core/src/components/picker-column/picker-column.tsx index d62e7cc8af..1f3a6398b3 100644 --- a/core/src/components/picker-column/picker-column.tsx +++ b/core/src/components/picker-column/picker-column.tsx @@ -146,6 +146,7 @@ export class PickerColumnCmp implements ComponentInterface { let translateY = 0; let translateZ = 0; const { col, rotateFactor } = this; + const prevSelected = col.selectedIndex; const selectedIndex = (col.selectedIndex = this.indexForY(-y)); const durationStr = duration === 0 ? '' : duration + 'ms'; const scaleStr = `scale(${this.scaleFactor})`; @@ -204,7 +205,7 @@ export class PickerColumnCmp implements ComponentInterface { button.classList.remove(PICKER_OPT_SELECTED); } } - this.col.prevSelected = selectedIndex; + this.col.prevSelected = prevSelected; if (saveY) { this.y = y; diff --git a/core/src/components/picker-column/test/standalone/picker-column.e2e.ts b/core/src/components/picker-column/test/standalone/picker-column.e2e.ts index e25bdcbaa7..d2b108ac25 100644 --- a/core/src/components/picker-column/test/standalone/picker-column.e2e.ts +++ b/core/src/components/picker-column/test/standalone/picker-column.e2e.ts @@ -3,9 +3,11 @@ import { configs, test } from '@utils/test/playwright'; configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => { test.describe(title('picker-column'), () => { - test('should present picker without ion-app', async ({ page }) => { - await page.goto('/src/components/picker-column/test/standalone', config); + test.beforeEach(async ({ page }) => { + await page.goto(`/src/components/picker-column/test/standalone`, config); + }); + test('should present picker without ion-app', async ({ page }) => { const ionPickerDidPresent = await page.spyOnEvent('ionPickerDidPresent'); const picker = page.locator('ion-picker'); @@ -16,5 +18,29 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => await expect(picker).toBeVisible(); }); + + test('should have the correct selectedIndex and prevSelected', async ({ page }) => { + test.info().annotations.push({ + type: 'issue', + description: 'https://github.com/ionic-team/ionic-framework/issues/21764', + }); + + const ionPickerDidPresent = await page.spyOnEvent('ionPickerDidPresent'); + const ionPickerColChangeEvent = await page.spyOnEvent('ionPickerColChange'); + + const column = page.locator('ion-picker-column'); + const secondOption = column.locator('.picker-opt').nth(1); + + await page.click('#single-column-button'); + + await ionPickerDidPresent.next(); + + await secondOption.click(); + + await ionPickerColChangeEvent.next(); + + expect(ionPickerColChangeEvent.events[0].detail.prevSelected).toBe(0); + expect(ionPickerColChangeEvent.events[0].detail.selectedIndex).toBe(1); + }); }); });