diff --git a/core/src/components/action-sheet/action-sheet.tsx b/core/src/components/action-sheet/action-sheet.tsx index beda9b01ac0..963932b4fdd 100644 --- a/core/src/components/action-sheet/action-sheet.tsx +++ b/core/src/components/action-sheet/action-sheet.tsx @@ -564,7 +564,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface { id={buttonId} class={{ ...buttonClass(b), - 'action-sheet-selected': isActiveRadio, + ...(isRadio && { 'action-sheet-selected': isActiveRadio }), }} onClick={() => { if (isRadio) { diff --git a/core/src/components/action-sheet/test/basic/action-sheet.spec.tsx b/core/src/components/action-sheet/test/basic/action-sheet.spec.tsx index fce291525f2..551b0d1fcfa 100644 --- a/core/src/components/action-sheet/test/basic/action-sheet.spec.tsx +++ b/core/src/components/action-sheet/test/basic/action-sheet.spec.tsx @@ -59,3 +59,36 @@ describe('action sheet: disabled buttons', () => { await expect(cancelButton.hasAttribute('disabled')).toBe(false); }); }); + +describe('action sheet: selected role', () => { + // https://github.com/ionic-team/ionic-framework/issues/31090 + it('should add the `action-sheet-selected` class to a button with `role="selected"`', async () => { + const page = await newSpecPage({ + components: [ActionSheet], + template: () => ( + + ), + }); + + const actionSheet = page.body.querySelector('ion-action-sheet')!; + + await actionSheet.present(); + + const buttons = Array.from(actionSheet.querySelectorAll('.action-sheet-button')); + const selectedButton = buttons.find((btn) => btn.textContent?.trim() === 'Option B'); + + await expect(selectedButton).toBeDefined(); + await expect(selectedButton!.classList.contains('action-sheet-selected')).toBe(true); + + const optionA = buttons.find((btn) => btn.textContent?.trim() === 'Option A'); + await expect(optionA!.classList.contains('action-sheet-selected')).toBe(false); + }); +});