Skip to content

fix(grid): Add aria-selected attribute handling for single select rows#3390

Draft
anna-lach wants to merge 14 commits into
mainfrom
fix/2896-grid-selection-missing-selected-state-for-single-select
Draft

fix(grid): Add aria-selected attribute handling for single select rows#3390
anna-lach wants to merge 14 commits into
mainfrom
fix/2896-grid-selection-missing-selected-state-for-single-select

Conversation

@anna-lach

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings May 27, 2026 11:45
@anna-lach anna-lach linked an issue May 27, 2026 that may be closed by this pull request
@changeset-bot

changeset-bot Bot commented May 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 52d54ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sl-design-system/grid Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds ARIA selection state handling to grid rows, improving accessibility for single-select rows and active-row behavior.

Changes:

  • Adds computed aria-selected values to rendered data rows.
  • Adds tests for absence/presence and updates of aria-selected in default, single select, and activate modes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/components/grid/src/grid.ts Computes and renders aria-selected for item rows based on selection or active-row state.
packages/components/grid/src/grid.spec.ts Adds regression tests for aria-selected behavior across grid configurations.

Comment thread packages/components/grid/src/grid.ts Outdated
Copilot AI review requested due to automatic review settings May 28, 2026 05:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Comment thread packages/components/grid/src/grid.ts Outdated
@anna-lach anna-lach added bug Something isn't working accessibility labels May 28, 2026
Copilot AI review requested due to automatic review settings May 28, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread packages/components/grid/src/grid.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

…on-missing-selected-state-for-single-select

# Conflicts:
#	packages/components/grid/src/grid.spec.ts
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings June 15, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

packages/components/grid/src/grid.ts:629

  • #onClickRow now expects the row index to avoid indexOf on the data source items (which can be a Proxy). The click handler should pass the already-known index + 1 into #onClickRow.
      <tr
        @click=${() => this.#onClickRow(item)}
        @dragstart=${(event: DragEvent) => this.#onDragStart(event, item)}

Comment thread packages/components/grid/src/grid.ts Outdated
Comment thread packages/components/grid/src/grid.ts Outdated
const secondRow = el.renderRoot.querySelector<HTMLTableRowElement>('tbody tr:nth-of-type(2)');
expect(secondRow?.part.contains('selected')).to.be.true;
});

Copilot AI review requested due to automatic review settings June 16, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Comment on lines +612 to +621
ariaCurrent =
this.rowAction === 'activate'
? active || selected
? 'true'
: nothing
: (this.dataSource?.selects ?? this.selects) === 'single'
? selected
? 'true'
: nothing
: nothing;
Comment on lines +64 to +67
} else if (container?.textContent?.indexOf(event.detail.message) === -1) {
messageNode.innerText = event.detail.message;
} else {
return;
}

this.#announceSelection(item, index);
this.#skipNextFocusAnnounce = true;
Comment on lines +767 to +775
#announceSelection(item: ListDataSourceDataItem<T>, index: number): void {
const selected =
this.rowAction === 'activate' ? !!this.activeRow : !!this.dataSource?.isSelected(item);

announce(
selected
? msg(str`Row ${index} activated`, { id: 'sl.grid.rowActivated' })
: msg(str`Row ${index} deactivated`, { id: 'sl.grid.rowDeactivated' }),
'assertive'
Comment on lines +109 to +113
it('should not have aria-selected when selects is not set', () => {
const rows = el.renderRoot.querySelectorAll<HTMLTableRowElement>('tbody tr');

rows.forEach(row => {
expect(row).not.to.have.attribute('aria-selected');
Copilot AI review requested due to automatic review settings June 16, 2026 14:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Comment on lines 631 to 633
aria-rowindex=${index + 1}
aria-current=${ariaCurrent}
index=${index}
Comment on lines +786 to +790
const row = (event.target as HTMLElement)?.closest?.('tr');

if (!row || !row.hasAttribute('aria-current')) {
return;
}
Comment on lines +767 to +775
#announceSelection(item: ListDataSourceDataItem<T>, index: number): void {
const selected =
this.rowAction === 'activate' ? !!this.activeRow : !!this.dataSource?.isSelected(item);

announce(
selected
? msg(str`Row ${index} activated`, { id: 'sl.grid.rowActivated' })
: msg(str`Row ${index} deactivated`, { id: 'sl.grid.rowDeactivated' }),
'assertive'
Comment on lines +767 to +801
#announceSelection(item: ListDataSourceDataItem<T>, index: number): void {
const selected =
this.rowAction === 'activate' ? !!this.activeRow : !!this.dataSource?.isSelected(item);

announce(
selected
? msg(str`Row ${index} activated`, { id: 'sl.grid.rowActivated' })
: msg(str`Row ${index} deactivated`, { id: 'sl.grid.rowDeactivated' }),
'assertive'
);
}

#onFocusIn(event: FocusEvent): void {
// Skip the focus announcement if it was triggered by a click that is already announced
if (this.#skipNextFocusAnnounce) {
this.#skipNextFocusAnnounce = false;
return;
}

const row = (event.target as HTMLElement)?.closest?.('tr');

if (!row || !row.hasAttribute('aria-current')) {
return;
}

const index = row.getAttribute('aria-rowindex');

if (index) {
announce(
msg(str`In activated row ${index}`, { id: 'sl.grid.inActivatedRow' }),
'assertive',
true
);
}
}
@@ -429,7 +437,6 @@ describe('sl-grid', () => {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Grid - Selection] Missing selected state for single select

2 participants