Skip to content

fix(DataTable): fix duplicate expanded row id for multiple tables #19416

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Rudra1402
Copy link

@Rudra1402 Rudra1402 commented May 18, 2025

Issue:

Changelog

Changed

  • Refactored the way the id and aria-controls attributes are set for expanded rows when multiple tables with expandable rows are present.
  • Appended the instanceId to each row’s id to ensure uniqueness within the DOM.
  • Appended the instanceId to the aria-controls attribute to correctly associate it with the corresponding row id.

Testing / Reviewing

Before making changes:

  • Use multiple tables with row expansion.
  • Inspect the elements and search for expanded-row-a. You’ll notice that multiple rows have the same id value.

After making changes:

  • You’ll notice that appending the instanceId makes each id unique.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

@Rudra1402 Rudra1402 requested review from a team as code owners May 18, 2025 18:57
Copy link
Contributor

github-actions bot commented May 18, 2025

All contributors have signed the DCO.
Posted by the DCO Assistant Lite bot.

@Rudra1402
Copy link
Author

I have read the DCO document and I hereby sign the DCO.

Copy link

netlify bot commented May 18, 2025

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit db9c0aa
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6832125a7a35400008f4bddc
😎 Deploy Preview https://deploy-preview-19416--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented May 18, 2025

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit db9c0aa
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6832125a20ff77000805615c
😎 Deploy Preview https://deploy-preview-19416--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Rudra1402 Rudra1402 force-pushed the rudra-a11y-datatable branch from b364b6e to ca49f4d Compare May 18, 2025 19:38
@tay1orjones
Copy link
Member

Please do not remove checklist items from the pr template. If some do not apply, just ~strike out the text with tildes~

@jinhua-ibm
Copy link

Thanks for submitting the PR! Since I initially reported the issue, I wanted to point out that the problem isn’t limited to just id attributes—there are also violations related to headers attributes. I'm not entirely sure how Carbon performs its checks, but I'd recommend running an IBM Equal Access Accessibility Checker scan to catch and address all remaining violations comprehensively.

@Rudra1402
Copy link
Author

Thanks for submitting the PR! Since I initially reported the issue, I wanted to point out that the problem isn’t limited to just id attributes—there are also violations related to headers attributes. I'm not entirely sure how Carbon performs its checks, but I'd recommend running an IBM Equal Access Accessibility Checker scan to catch and address all remaining violations comprehensively.

Thanks for the note! I actually had a local fix ready for the specific id attribute issue, so I submitted that as a starting point. I agree that a full scan would be helpful to catch broader violations like headers attributes, but I’d suggest treating those as a separate effort to keep the changes focused. Happy to help where I can!

@@ -612,7 +612,7 @@ class DataTable<RowType, ColTypes extends any[]> extends React.Component<
}) => {
return {
...rest,
id: `expanded-row-${row.id}`,
id: `expanded-row-${row.id}-${this.instanceId}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion to store this ID in a variable to keep the implementation DRY and ensure consistency.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! I’ve updated to use a variable for the expanded row ID.

@Rudra1402 Rudra1402 requested a review from adamalston May 24, 2025 18:41
@Gururajj77
Copy link
Contributor

Hey @Rudra1402 , could you please add the steps to test this PR

@Rudra1402
Copy link
Author

Hey @Rudra1402 , could you please add the steps to test this PR

Hello, create 2 DataTables with expandable rows for comparative analysis use case. Run the IBM A11y Checker, you'll notice duplicate id violations.
After the fix, run the IBM scanner again, the instanceId will never allow 2 rows from 2 different tables with same id even if they use the same dataset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants