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

feat: add accessibleName property to Grid #8230

Merged
merged 6 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions packages/grid/src/vaadin-grid-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ export interface GridMixinClass<TItem>
*/
allRowsVisible: boolean;

/**
* String used to label the grid to screen reader users.
* @attr {string} accessible-name
*/
accessibleName: string;

/**
* Updates the `width` of all columns which have `autoWidth` set to `true`.
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ export const GridMixin = (superClass) =>
reflectToAttribute: true,
},

/**
* String used to label the grid to screen reader users.
* @attr {string} accessible-name
*/
accessibleName: {
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved
type: String,
},

/** @private */
__pendingRecalculateColumnWidths: {
type: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/src/vaadin-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Grid extends GridMixin(ElementMixin(ThemableMixin(ControllerMixin(PolymerE
column-reordering-allowed$="[[columnReorderingAllowed]]"
empty-state$="[[__emptyState]]"
>
<table id="table" role="treegrid" aria-multiselectable="true" tabindex="0">
<table id="table" role="treegrid" aria-multiselectable="true" tabindex="0" aria-label="[[accessibleName]]">
<caption id="sizer" part="row"></caption>
<thead id="header" role="rowgroup"></thead>
<tbody id="items" role="rowgroup"></tbody>
Expand Down
9 changes: 8 additions & 1 deletion packages/grid/src/vaadin-lit-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import './vaadin-lit-grid-column.js';
import { html, LitElement } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
import { isIOS, isSafari } from '@vaadin/component-base/src/browser-utils.js';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
Expand Down Expand Up @@ -42,7 +43,13 @@ class Grid extends GridMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElement)
column-reordering-allowed="${this.columnReorderingAllowed}"
?empty-state="${this.__emptyState}"
>
<table id="table" role="treegrid" aria-multiselectable="true" tabindex="0">
<table
id="table"
role="treegrid"
aria-multiselectable="true"
tabindex="0"
aria-label="${ifDefined(this.accessibleName)}"
>
<caption id="sizer" part="row"></caption>
<thead id="header" role="rowgroup"></thead>
<tbody id="items" role="rowgroup"></tbody>
Expand Down
29 changes: 29 additions & 0 deletions packages/grid/test/accessibility.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,33 @@ describe('accessibility', () => {
});
});
});

describe('accessibleName', () => {
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved
it('should not define aria-label on the table when accessibleName is not set', async () => {
await nextFrame();
expect(grid.$.table.getAttribute('aria-label')).to.be.null;
});

it('should define aria-label on the table when accessibleName is set', async () => {
grid.accessibleName = 'Grid accessible name';
await nextFrame();
expect(grid.$.table.getAttribute('aria-label')).to.equal('Grid accessible name');
});

it('should update aria-label on the table when accessibleName is updated', async () => {
grid.accessibleName = 'Grid accessible name';
await nextFrame();
grid.accessibleName = 'Updated accessible name';
await nextFrame();
expect(grid.$.table.getAttribute('aria-label')).to.equal('Updated accessible name');
});

it('should remove aria-label on the table when accessibleName is removed', async () => {
grid.accessibleName = 'Grid accessible name';
await nextFrame();
grid.accessibleName = null;
await nextFrame();
expect(grid.$.table.getAttribute('aria-label')).to.be.null;
});
});
});
Loading