diff --git a/core/src/components/select/select.tsx b/core/src/components/select/select.tsx index 6b1fe925e3b..fddd1f383c4 100644 --- a/core/src/components/select/select.tsx +++ b/core/src/components/select/select.tsx @@ -320,7 +320,7 @@ export class Select implements ComponentInterface { } private setValue(value?: any | null) { - if (this.isValueEqual(this.value, value)) { + if (this.disabled || this.isValueEqual(this.value, value)) { return; } this.value = value; diff --git a/core/src/components/select/test/select.spec.tsx b/core/src/components/select/test/select.spec.tsx index f214e289501..02b13c1d14c 100644 --- a/core/src/components/select/test/select.spec.tsx +++ b/core/src/components/select/test/select.spec.tsx @@ -307,6 +307,30 @@ describe('ion-select: overlay option labels', () => { jest.restoreAllMocks(); }); + it('should ignore a selection when disabled after opening', async () => { + const createAlert = stubAlertController(); + const page = await newSpecPage({ + components: [Select, SelectOption], + html: ` + Apple + Orange + `, + }); + const select = page.body.querySelector('ion-select')!; + const onChange = jest.fn(); + select.addEventListener('ionChange', onChange); + await select.open(); + const { buttons } = createAlert.mock.calls[0][0]; + + select.disabled = true; + await page.waitForChanges(); + (buttons![1] as any).handler('orange'); + await page.waitForChanges(); + + expect(select.value).toBe('apple'); + expect(onChange).not.toHaveBeenCalled(); + }); + it('should label alert inputs with the text the option renders', async () => { const createAlert = stubAlertController();