Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(combobox): fix accessibility when an item's heading or label changes #11289

Merged
merged 7 commits into from
Jan 14, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export class ComboboxItem extends LitElement implements InteractiveComponent {
if (
(changes.has("disabled") && this.hasUpdated) ||
(changes.has("selected") && this.hasUpdated) ||
(changes.has("textLabel") && this.hasUpdated)
(changes.has("textLabel") && this.hasUpdated) ||
(changes.has("heading") && this.hasUpdated) ||
(changes.has("label") && this.hasUpdated)
) {
this.calciteInternalComboboxItemChange.emit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,62 @@ describe("calcite-combobox", () => {
});
});

it("should update screen reader list items", async () => {
const page = await newE2EPage();

await page.setContent(
html`<calcite-combobox>
<calcite-combobox-item id="item-0" value="item-0"></calcite-combobox-item>
</calcite-combobox>`,
);

const item = await page.find("calcite-combobox-item");
let a11yItem = await page.find(`calcite-combobox >>> ul.${CSS.screenReadersOnly} li`);

expect(a11yItem).not.toBeNull();
expect(await a11yItem.getProperty("ariaSelected")).toBe("false");
expect(await a11yItem.getProperty("ariaLabel")).toBe(null);
expect(await a11yItem.getProperty("textContent")).toBe("");

item.setProperty("selected", true);
await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE.nextTick);
a11yItem = await page.find(`calcite-combobox >>> ul.${CSS.screenReadersOnly} li`);

expect(await a11yItem.getProperty("ariaSelected")).toBe("true");

const label = "label";
item.setProperty("label", label);
await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE.nextTick);
a11yItem = await page.find(`calcite-combobox >>> ul.${CSS.screenReadersOnly} li`);

expect(await a11yItem.getProperty("ariaLabel")).toBe(label);

const textLabel = "textLabel";
item.setProperty("textLabel", textLabel);
await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE.nextTick);
a11yItem = await page.find(`calcite-combobox >>> ul.${CSS.screenReadersOnly} li`);

expect(await a11yItem.getProperty("textContent")).toBe(textLabel);

const heading = "heading";
item.setProperty("heading", heading);
await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE.nextTick);
a11yItem = await page.find(`calcite-combobox >>> ul.${CSS.screenReadersOnly} li`);

expect(await a11yItem.getProperty("textContent")).toBe(heading);

item.setProperty("disabled", true);
await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE.nextTick);
a11yItem = await page.find(`calcite-combobox >>> ul.${CSS.screenReadersOnly} li`);

expect(a11yItem).toBeNull();
});

it("should control max items displayed", async () => {
const maxItems = 7;
const page = await newE2EPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@ export class Combobox
private renderListBoxOptions(): JsxNode {
return this.filteredItems.map((item) => (
<li
ariaLabel={item.label}
ariaSelected={item.selected}
id={item.guid ? `${itemUidPrefix}${item.guid}` : null}
role="option"
Expand Down Expand Up @@ -1784,7 +1785,7 @@ export class Combobox
this.renderAllSelectedIndicatorChipCompact(),
]}
<label
class="screen-readers-only"
class={CSS.screenReadersOnly}
htmlFor={`${inputUidPrefix}${guid}`}
id={`${labelUidPrefix}${guid}`}
>
Expand All @@ -1805,7 +1806,7 @@ export class Combobox
<ul
aria-labelledby={`${labelUidPrefix}${guid}`}
ariaMultiSelectable="true"
class="screen-readers-only"
class={CSS.screenReadersOnly}
id={`${listboxUidPrefix}${guid}`}
role="listbox"
tabIndex={-1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CSS = {
placeholderIcon: "placeholder-icon",
selectedIcon: "selected-icon",
floatingUIContainer: "floating-ui-container",
screenReadersOnly: "screen-readers-only",
};

export const IDS = {
Expand Down
Loading