File tree browser focus and keyboard navigation issues

Summary

The file tree browser has several focus and keyboard navigation issues that affect accessibility and user experience. These issues appear to exist on both the master branch and in the pagination implementation MR.

Issues Identified

See !203513 (comment 2732963331)

  • after clicking Show more the focus doesn't land on the newly loaded items, but it also doesn't seem to land on the item that was previously the next one
  • FTB does not scroll to have a focused element in view
  • at some point I landed on the RefSelector, but shift+tab didn't move me to the last file in the FTB, but something like 20 from the bottom of it
  • at some point when I was going back with shift+tab the focus move to the send top directory ("AI Testing"), and then down to the first file outside of folders (".DS_Store")
  • at some point there was a black space between some directories and items in them (see 00:48 of the recording)

Steps to Reproduce

  1. Enable the repository_file_tree_browser feature flag
  2. Navigate to a repository with many files/directories
  3. Use keyboard navigation (Tab/Shift+Tab) to move through the file tree
  4. Try clicking "Show more" (if pagination is available) and observe focus behavior
  5. Use Shift+Tab to navigate backwards through the tree

Expected Behavior

  • Focus should be maintained logically when new content is loaded
  • Focused elements should remain visible (scroll into view)
  • Shift+Tab should move to the previous focusable element in logical order
  • No visual rendering artifacts during navigation

Current Behavior

  • Focus jumps unpredictably after "Show more" clicks
  • Focused elements can be scrolled out of view
  • Shift+Tab navigation is inconsistent and sometimes skips many elements
  • Visual artifacts (black spaces) appear during navigation

Additional Context

This issue was identified during review of MR !203513 (merged) (file tree pagination implementation), but the problems appear to exist on the master branch as well, indicating these are pre-existing accessibility issues.

Screen recording showing the issues: Screen_Recording_2025-09-05_at_16.20.52

Edited by 🤖 GitLab Bot 🤖