Skip to content

feat: Add support for onToggleSort to DataTable #5991

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 1 commit into
base: main
Choose a base branch
from

Conversation

veryfancy
Copy link

@veryfancy veryfancy commented Apr 30, 2025

Add support for onToggleSort prop to DataTable.

Changelog

New

  • Add support for onToggleSort prop to DataTable.

Changed

Removed

Rollout strategy

  • Minor release

Testing & Reviewing

Merge checklist

@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 21:20
@veryfancy veryfancy requested a review from a team as a code owner April 30, 2025 21:20
@veryfancy veryfancy requested a review from jonrohan April 30, 2025 21:20
Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: 42642de

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

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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

@veryfancy veryfancy self-assigned this Apr 30, 2025
@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Apr 30, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a callback to notify consumers when a sortable column header is clicked.

  • Introduces an optional onToggleSort prop in DataTableProps.
  • Invokes onToggleSort with the column ID and new direction on header clicks.
  • Covers the new behavior with a unit test and a Storybook story.

Reviewed Changes

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

File Description
packages/react/src/DataTable/DataTable.tsx Added onToggleSort prop and callback invocation in header logic
packages/react/src/DataTable/tests/DataTable.test.tsx New test verifying onToggleSort calls with correct parameters
packages/react/src/DataTable/DataTable.features.stories.tsx Added WithSortEvents Storybook example using onToggleSort
.changeset/salty-bikes-learn.md Changelog entry for the onToggleSort addition
Comments suppressed due to low confidence (2)

packages/react/src/DataTable/tests/DataTable.test.tsx:891

  • [nitpick] The variable name handler is generic; consider renaming it to onToggleSortMock or onToggleSortHandler to clarify its purpose.
const handler = jest.fn()

packages/react/src/DataTable/tests/DataTable.test.tsx:921

  • Consider adding an assertion to verify that clicking the same column header a second time toggles back to ASC, e.g., a third click on 'First' calls onToggleSort('first', 'ASC').
expect(handler).toHaveBeenCalledTimes(2)

Copy link
Contributor

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 98.94 KB (0%)
packages/react/dist/browser.umd.js 99.08 KB (0%)

@github-actions github-actions bot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels May 1, 2025
@primer-integration
Copy link

👋 Hi from github/github! Your integration PR is ready: https://github.com/github/github/pull/375773

@primer-integration
Copy link

🟢 golden-jobs completed with status success.

@github-actions github-actions bot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: failing Changes in this PR cause breaking changes in gh/gh labels May 1, 2025
@veryfancy
Copy link
Author

Int tests were failing due to a date-related Flake, not this change. (Although the failing test used DataTable, which sparked extra investigation! 😅 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant