Skip to content

Commit

Permalink
fix(table): Add aria-rowcount to virtualized tables (#4156)
Browse files Browse the repository at this point in the history
* fix: aria-rowcount on table

* fix: add explanatory comment

* fix: cleanup logic and explanatory comment

* chore: code review clean up

---------

Co-authored-by: davidx <[email protected]>
Co-authored-by: Westbrook Johnson <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent c450a09 commit b4136ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/table/src/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ export class Table extends SizedMixin(SpectrumElement, {
protected override updated(): void {
if (this.items.length) {
this.renderVirtualizedItems();
} else {
this.removeAttribute('aria-rowcount');
}
}

Expand Down Expand Up @@ -507,6 +509,11 @@ export class Table extends SizedMixin(SpectrumElement, {
}
);
}

// Ensures screenreaders can announce the true size of the table
// despite virtualization only rendering a subset of rows.
this.setAttribute('aria-rowcount', `${this.items.length}`);

const config: VirtualizeDirectiveConfig<Record<string, unknown>> = {
items: this.items,
renderItem: this.renderItem,
Expand Down
1 change: 0 additions & 1 deletion packages/table/stories/table-virtualized.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class VirtualTable extends SpectrumElement {
protected override render(): TemplateResult {
return html`
<sp-table
aria-rowcount="50"
.items=${this.items}
.renderItem=${renderItem}
size="m"
Expand Down

0 comments on commit b4136ab

Please sign in to comment.