diff --git a/core/src/components/select/select.tsx b/core/src/components/select/select.tsx index 5bf8699c19..90f4f3783b 100644 --- a/core/src/components/select/select.tsx +++ b/core/src/components/select/select.tsx @@ -1,5 +1,5 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core'; -import { Component, Element, Event, Host, Method, Prop, State, Watch, h } from '@stencil/core'; +import { Component, Element, Event, Host, Method, Prop, State, Watch, h, forceUpdate } from '@stencil/core'; import { getIonMode } from '../../global/ionic-global'; import type { @@ -166,6 +166,14 @@ export class Select implements ComponentInterface { this.mutationO = watchForOptions(this.el, 'ion-select-option', async () => { this.updateOverlayOptions(); + + /** + * We need to re-render the component + * because one of the new ion-select-option + * elements may match the value. In this case, + * the rendered selected text should be updated. + */ + forceUpdate(this); }); } diff --git a/core/src/components/select/test/async/index.html b/core/src/components/select/test/async/index.html index 5293fb9bdb..2938aacd84 100644 --- a/core/src/components/select/test/async/index.html +++ b/core/src/components/select/test/async/index.html @@ -29,11 +29,15 @@ + + + + diff --git a/core/src/components/select/test/async/select.e2e.ts b/core/src/components/select/test/async/select.e2e.ts index 8db1aa8966..f35ee77508 100644 --- a/core/src/components/select/test/async/select.e2e.ts +++ b/core/src/components/select/test/async/select.e2e.ts @@ -2,16 +2,23 @@ import { expect } from '@playwright/test'; import { test } from '@utils/test/playwright'; test.describe('select: async', () => { - test('should correctly set the value after a delay', async ({ page, skip }) => { + test.beforeEach(async ({ page, skip }) => { skip.rtl('This is checking internal logic. RTL tests are not needed'); + skip.mode('md'); await page.goto(`/src/components/select/test/async`); - const selectValueSet = await page.spyOnEvent('selectValueSet'); - - const select = await page.locator('#default'); - - await selectValueSet.next(); + }); + test('should correctly set the value after a delay', async ({ page }) => { + const select = page.locator('#default'); + await page.click('#set-contents'); await expect(select).toHaveJSProperty('value', 'bird'); }); + + test('should re-render when options update but value is already set', async ({ page }) => { + const select = page.locator('#with-value'); + await page.click('#set-contents'); + + await expect(select.locator('.select-text')).toHaveText('bird'); + }); });