Skip to content

Retain list row focus when scrolling#15641

Merged
niik merged 2 commits intodevelopmentfrom
retain-list-row-focus
Dec 2, 2022
Merged

Retain list row focus when scrolling#15641
niik merged 2 commits intodevelopmentfrom
retain-list-row-focus

Conversation

@niik
Copy link
Member

@niik niik commented Nov 18, 2022

Closes #2957

Description

While scrolling in our virtualized lists items get unmounted and recreated constantly. For the most part this works well but if the user has focused a list item the focus reverts back to the body when the element is unmounted. I could have sworn it used to be that it reverted to the closest focusable ancestor and that's why we made it so that list items are styled as if they selected+focused as long as the list component has focus anywhere inside of it but something somewhere sure has changed.

In #15604 @markhicken did some great work which resolved the selection issue but the issue with keyboard focus being reset to the body element (as long as the selected item was out of view) remained. In this PR I'm attempting to fix both issues by explicitly detecting when the selected+focused item is unmounted and moving the focus to the List component (instead of body). This lets keyboard selection continue to work even though the selected list item has been unmounted.

Screenshots

Release notes

Notes: [Fixed] Ensure selected list items stay selected when scrolling

niik and others added 2 commits November 15, 2022 17:34
Turns out e11038a introduced a regression where the intention was changed from "selection not included" to "selection included"
Moves focus away from unmounted list items to the grid such that keyboard navigation still works after scrolling

Co-Authored-By: Mark Hicken <849930+markhicken@users.noreply.github.com>
Copy link
Contributor

@tidy-dev tidy-dev left a comment

Choose a reason for hiding this comment

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

✨ Works great! Awesome that it keeps the keyboard navigation. :)

@markhicken
Copy link
Contributor

👍🏼 Yes! Very nice @niik! I tested on Mac and Windows, but didn't have a Linux machine to test on.

@Jimimaku

This comment was marked as off-topic.

this.props.onSelectionChanged
) {
this.props.onSelectionChanged([row], { kind: 'hover', event })
if (!this.props.selectedRows.includes(row)) {
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering about this ! change until I remembered e11038a 😳

Leaving it here for reference in case someone else wonders!

Copy link
Member

@sergiou87 sergiou87 left a comment

Choose a reason for hiding this comment

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

Looks great to me! 😄

@niik niik merged commit a5a7a73 into development Dec 2, 2022
@niik niik deleted the retain-list-row-focus branch December 2, 2022 15:25
Copy link

@momof3887 momof3887 left a comment

Choose a reason for hiding this comment

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

\overscanner={©``}

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.

Scrolling in sidebar, selected item loses focus if out of view

7 participants