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
4 changes: 3 additions & 1 deletion core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,16 @@ export class Select implements ComponentInterface {
.filter((cls) => cls !== 'hydrated')
.join(' ');
const optClass = `${OPTION_CLASS} ${copyClasses}`;
const isSelected = isOptionSelected(selectValue, value, this.compareWith);

return {
role: isOptionSelected(selectValue, value, this.compareWith) ? 'selected' : '',
role: isSelected ? 'selected' : '',
text: option.textContent,
cssClass: optClass,
handler: () => {
this.setValue(value);
},
...(isSelected ? { htmlAttributes: { 'aria-description': 'selected' } } : {}),
} as ActionSheetButton;
});

Expand Down
38 changes: 37 additions & 1 deletion core/src/components/select/test/a11y/select.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

configs({ directions: ['ltr'], palettes: ['light', 'dark'] }).forEach(({ title, config }) => {
test.describe(title('textarea: a11y'), () => {
test.describe(title('select: a11y'), () => {
test('default layout should not have accessibility violations', async ({ page }) => {
await page.setContent(
`
Expand Down Expand Up @@ -111,3 +111,39 @@ configs({ directions: ['ltr'] }).forEach(({ title, config, screenshot }) => {
});
});
});

/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('select: aria attributes'), () => {
test('should have a aria-description on the selected option when action sheet interface is open', async ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('should have a aria-description on the selected option when action sheet interface is open', async ({
test('should have an aria-description on the selected option when action sheet interface is open', async ({

page,
}) => {
await page.setContent(
`
<ion-select label="Fruit" value="apple" interface="action-sheet">
<ion-select-option value="apple">Apple</ion-select-option>
<ion-select-option value="banana">Banana</ion-select-option>
<ion-select-option value="orange">Orange</ion-select-option>
</ion-select>
`,
config
);

const ionActionSheetDidPresent = await page.spyOnEvent('ionActionSheetDidPresent');

const select = page.locator('ion-select');

await select.click();
await ionActionSheetDidPresent.next();

const selectedOption = page.locator('.action-sheet-selected');
await expect(selectedOption).toHaveAttribute('aria-description', 'selected');

// Check that the attribut is not added to non-selected option
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check that the attribut is not added to non-selected option
// Check that the attribute is not added to non-selected option

const nonSelectedOption = page.locator('.select-interface-option:not(.action-sheet-selected)').first();
await expect(nonSelectedOption).not.toHaveAttribute('aria-description');
});
});
});
Loading