diff --git a/core/src/components/item/item.tsx b/core/src/components/item/item.tsx index c3c3a02fb32..b73f3453a23 100644 --- a/core/src/components/item/item.tsx +++ b/core/src/components/item/item.tsx @@ -205,10 +205,16 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac * A non-clickable item renders a `div`, which ARIA doesn't allow a name on, so an * `aria-label` written after load also stays on the Host, which is a `listitem` * when the item is in an `ion-list`. + * + * `aria-expanded` is copied to the native element for the same reason `aria-label` + * is: it is a state the assistive technology reads off the element that takes the + * action, and the Host's `role="listitem"` doesn't carry it. A `listitem` has no + * expanded state, so the attribute was ignored where it was written and the item + * read as neither expanded nor collapsed. */ this.ariaController = createAttributeController( this.el, - ['aria-label'], + ['aria-label', 'aria-expanded'], () => forceUpdate(this), [], undefined, diff --git a/core/src/components/item/test/a11y/item.e2e.ts b/core/src/components/item/test/a11y/item.e2e.ts index 6e011b72da8..cc8cf50c36f 100644 --- a/core/src/components/item/test/a11y/item.e2e.ts +++ b/core/src/components/item/test/a11y/item.e2e.ts @@ -55,6 +55,36 @@ configs({ directions: ['ltr'] }).forEach(({ config, screenshot, title }) => { expect(await item1.getAttribute('aria-label')).toEqual('test'); expect(await item2.getAttribute('aria-label')).toEqual('test'); }); + + test('should reflect aria-expanded', async ({ page }) => { + await page.setContent( + ` + + + `, + config + ); + + const item1 = page.locator('#item-1 .item-native'); + const item2 = page.locator('#item-2 .item-native'); + + expect(await item1.getAttribute('aria-expanded')).toEqual('false'); + expect(await item2.getAttribute('aria-expanded')).toEqual('true'); + }); + + test('should reflect aria-expanded written after load', async ({ page }) => { + await page.setContent( + ` + + `, + config + ); + + await page.locator('#item-1').evaluate((el) => el.setAttribute('aria-expanded', 'true')); + + const item1 = page.locator('#item-1 .item-native'); + expect(await item1.getAttribute('aria-expanded')).toEqual('true'); + }); }); test.describe(title('item: font scaling'), () => {