Avoid triple state: aria-selected=("true"|"false"|unset)

This commit is contained in:
Pablo Brasero 2025-07-25 22:41:19 +01:00
commit d4e8eebc9d
2 changed files with 21 additions and 0 deletions

View file

@ -322,6 +322,7 @@ const templates: TemplatesInterface = {
} else {
addClassesToElement(div, itemSelectable);
div.dataset.choiceSelectable = '';
div.setAttribute('aria-selected', 'false');
}
return div;

View file

@ -147,6 +147,26 @@ describe(`Choices - select multiple`, () => {
});
});
describe('aria attributes', () => {
const testId = 'disabled-choice';
test('aria-selected', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
await suite.input.press('ArrowDown');
await expect(suite.choices.first()).toHaveAttribute("aria-selected", "false");
await expect(suite.choices.nth(1)).toHaveAttribute("aria-selected", "true");
await expect(suite.choices.nth(2)).toHaveAttribute("aria-selected", "false");
await expect(suite.choices.nth(3)).not.toHaveAttribute("aria-selected");
await suite.input.press('ArrowUp');
await expect(suite.choices.first()).toHaveAttribute("aria-selected", "true");
await expect(suite.choices.nth(1)).toHaveAttribute("aria-selected", "false");
await expect(suite.choices.nth(2)).toHaveAttribute("aria-selected", "false");
await expect(suite.choices.nth(3)).not.toHaveAttribute("aria-selected");
});
});
describe('searching choices', () => {
const validValue = 'item2';
const validLabelForValue = 'Choice 2';