Skip to content

[pagination] Manage focus whenever first / last / next / previous buttons become disabled - #48877

Open
silviuaavram wants to merge 4 commits into
mui:masterfrom
silviuaavram:fix/manage-focus-pagination
Open

[pagination] Manage focus whenever first / last / next / previous buttons become disabled#48877
silviuaavram wants to merge 4 commits into
mui:masterfrom
silviuaavram:fix/manage-focus-pagination

Conversation

@silviuaavram

@silviuaavram silviuaavram commented Jul 29, 2026

Copy link
Copy Markdown
Member

Pagination needs to have focus managed whenever the first / next / last / previous buttons are focused, pressed, and they become disabled. Currently, the focus is lost to the <body> so we manage it to the active item whenever that happens.

On click even, we store the button pressed, then on the subsequent render, in effect, we check if we need to manage focus (focused element is either body or disabled button), and we focus the button that has aria-current="page".

Also update the usePagination docs example since that needs its focus to be managed.

Repro:

  • go to pagination example with back / next buttons
  • set active page to be equal or greater than 2
  • focus back button
  • hit enter until the back button becomes disabled

Expected: focus should be managed to an active element
Actual: focus is lost to the body.

Fix: focus is managed to

the first page button (when back becomes disabled) or the last page button (when next page becomes disabled).

Before:

Screen.Recording.2026-08-04.at.10.21.07.mov

After:

Screen.Recording.2026-08-04.at.10.22.31.mov

@silviuaavram silviuaavram self-assigned this Jul 29, 2026
Copilot AI review requested due to automatic review settings July 29, 2026 06:34
@silviuaavram silviuaavram added accessibility a11y scope: pagination Changes related to the pagination. labels Jul 29, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+581B(+0.11%) 🔺+185B(+0.12%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about 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 improves keyboard/focus accessibility for Pagination by restoring focus to the currently selected page when a navigation control (first/previous/next/last) becomes disabled after activation, preventing focus from being lost to <body>. It also updates the usePagination docs example and adds regression tests to cover the new behavior.

Changes:

  • Add focus-restoration logic in Pagination after navigation buttons become disabled.
  • Add unit tests covering boundary-navigation focus behavior (including controlled usage and “don’t override consumer-managed focus”).
  • Update the usePagination docs demo to manage focus when navigating to the first/last page via previous/next.

Reviewed changes

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

File Description
packages/mui-material/src/Pagination/Pagination.js Tracks the triggering control and restores focus to the selected page when focus is lost due to a control becoming disabled.
packages/mui-material/src/Pagination/Pagination.test.js Adds focused regression tests for disabled-navigation focus restoration, including controlled and boundary-count scenarios.
docs/data/material/components/pagination/UsePagination.tsx Updates the usePagination example to keep focus on a stable page target when previous/next navigation reaches a boundary.
docs/data/material/components/pagination/UsePagination.js Keeps the generated JS demo in sync with the updated TS demo logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@silviuaavram silviuaavram changed the title Fix/manage focus pagination [pagination] Manage focus whenever first / last / next / previous buttons become disabled Jul 29, 2026

@ZeeshanTamboli ZeeshanTamboli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you give a video recording of what we are trying to solve here? Or maybe reproductions with steps? I didn't understand this issue. Also, how did you find this issue? Were you experimenting with the Pagination component?

@silviuaavram

Copy link
Copy Markdown
Member Author

Can you give a video recording of what we are trying to solve here? Or maybe reproductions with steps? I didn't understand this issue. Also, how did you find this issue? Were you experimenting with the Pagination component?

Done, check the description. I'm auditing our components for a11y issues.

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

Labels

accessibility a11y scope: pagination Changes related to the pagination.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants