Skip to content

feat(MainTable): add scrollToTop prop to scroll to the top on page change - #1432

Merged
Stefan3002 merged 2 commits into
canonical:mainfrom
wak327:feat/main-table-scroll-to-top
Oct 19, 2026
Merged

Stefan3002 merged 2 commits into
canonical:mainfrom
wak327:feat/main-table-scroll-to-top

Conversation

@wak327

@wak327 wak327 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Done

  • Added a scrollToTop prop to MainTable. It is passed to the table's internal Pagination, so the window scrolls to the top when the table page changes. It is off by default, so existing tables behave as before.
  • Added tests for scrolling to the top when scrollToTop is set, and not scrolling by default.

QA

Pinging @canonical/react-library-maintainers for a review.

Storybook

To see rendered examples of all react-components, run:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

QA steps

  • Render a MainTable with paginate set, enough rows for more than one page, and scrollToTop.
  • Scroll down the page and change the table page using the pagination: the window scrolls to the top.
  • Remove scrollToTop and change the page again: the scroll position doesn't change.

Percy steps

  • No visual changes expected.

Fixes

Fixes: #34

…ange

Paginated MainTables render a Pagination component internally, but there was no way to enable Pagination's scrollToTop behaviour from the table. Add a scrollToTop prop that is passed through to the pagination so the window scrolls to the top when the table page changes.

Fixes canonical#34
@wak327

wak327 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@edlerd @jmuzina could you take a look when you have a moment?

@bartaz this picks up #34, which you triaged as low effort / potentially high value. I went with an opt-in scrollToTop prop that's passed through to the table's Pagination, so existing tables aren't affected. Happy to make it the default instead if you'd prefer.

@Stefan3002 Stefan3002 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.

@wak327 Hello! Thanks for picking this up and proposing a fix! Looks good with only one suggestion: can we have a new story underMainTable.stories.tsx with a lot of rows? This would make it easier to visualize the behavior of the component. As of now, I can zoom in a lot and cause it to overflow vertically and then test this new functionality, but it would be easier if we had a dedicated story.

Other than that, looks good! Great job! 😄

Add a paginated story with enough rows for the page to scroll, so the scrollToTop behaviour is easier to see.
@wak327

wak327 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@Stefan3002 thanks for the review! I've added a "Paginated with scroll to top" story with 100 rows across 4 pages and scrollToTop enabled (it can be toggled from the controls), so you can scroll down to the pagination and change the page to see it. Percy will show one new snapshot for it.

@Stefan3002 Stefan3002 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.

Hello! Thanks for the work here! Well done!

LGTM! 😄

@Stefan3002
Stefan3002 merged commit 4c167e1 into canonical:main Oct 19, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scroll to top when paginating MainTable

2 participants