Skip to content

Don't scroll table element into view if focused by mouse click#2872

Open
m-akinc wants to merge 5 commits intomainfrom
users/makinc/fix-table-focus-scroll-bug
Open

Don't scroll table element into view if focused by mouse click#2872
m-akinc wants to merge 5 commits intomainfrom
users/makinc/fix-table-focus-scroll-bug

Conversation

@m-akinc
Copy link
Contributor

@m-akinc m-akinc commented Feb 25, 2026

Pull Request

🤨 Rationale

An SLE user reported a bug where clicking on the horizontal scrollbar of a table (which itself was within a scrollable viewport) caused the containing scrollable viewport to scroll to the top of the table.

👩‍💻 Implementation

We have a bunch of special logic to make keyboard navigation within the table nice. This involves manually setting the focus on different subelements of the table (rows, menu buttons, cell content, column headers) in response to events like keystrokes and focus-ins. The reported buggy symptom is due to us focusing the first column header (or the last subelement that previously had focus) when the table gets focused. When you click a part of the table that isn't a cell, such as a scrollbar, or the empty space below the rows, that's what happens.

We still want to scroll the focused element into view if navigating by keyboard, so my fix is to set a flag whenever the table gets a pointerdown event and use that flag to suppress scrolling when calling focus() on an element. This seems preferable to using keydown, since that would require detecting tab keypresses that occur outside the table (in addition to the ones within it). We clear the flag at the end of the table's focusin handler, so subsequent keyboard navigation will continue to scroll elements into view as needed. It is only when the table gains focus from outside that we now suppress scrolling, and only when clicking.

Note: I also did some refactoring of the keyboard navigation manager to help me better understand it. That is all captured in a separate commit, so I would recommend reviewing each commit separately.

🧪 Testing

Added test cases, and existing tests still pass.

@m-akinc m-akinc marked this pull request as ready for review February 25, 2026 20:59
@@ -0,0 +1,7 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

@msmithNI you up for reviewing these changes to keyboard-navigation-manager?

@msmithNI msmithNI self-requested a review February 25, 2026 22:43
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.

2 participants