Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/components/item/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions core/src/components/item/test/a11y/item.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
<ion-item id="item-1" aria-expanded="false"></ion-item>
<ion-item id="item-2" aria-expanded="true" button="true"></ion-item>
`,
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(
`
<ion-item id="item-1"></ion-item>
`,
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'), () => {
Expand Down