Skip to content

Keep the selected row centered when scrolling with keyboard #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2018

Conversation

DanTup
Copy link
Contributor

@DanTup DanTup commented Oct 3, 2018

  • tests.

Fixes #38.

@DanTup DanTup requested a review from devoncarew October 3, 2018 09:17
Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

Added a comment about a tweak to make sure that each up/down arrow doesn't cause a scroll (only if the selection is near the top or bottom of the visible area).

@@ -420,10 +420,25 @@ class Table<T> extends Object with SetStateMixin {
/// and not necessarily for rows[] since it may be being rendered in reverse.
/// This way, +1 will always move down the visible table.
@visibleForTesting
void selectByIndex(int newIndex) {
void selectByIndex(int newIndex,
Copy link
Member

Choose a reason for hiding this comment

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

For the dartdoc, reference the docs for HtmlElement.scrollTo? Or, mention that valid values for scrollBehavior are auto and smooth.

final CoreElement row = _rowForIndex[newIndex];
final T data = rows[_translateRowIndex(newIndex)];
_select(row?.element, data, newIndex);

if (keepVisible) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we probably only want to auto-scroll if the selection is close to the bottom or top of the visible area.

@DanTup DanTup force-pushed the keep-selection-visible branch from 414f64b to 772658c Compare October 8, 2018 12:49
@DanTup
Copy link
Contributor Author

DanTup commented Oct 8, 2018

Note: This PR includes the changset from #48; I'll rebase it after that lands.

I've updated the comment as requested, and also made it only scroll when you get near the edges. It currently scrolls to the middle when you hit the edges - I think this works well but I don't know if you'd prefer it the other way (scroll by a single row each time, rather than infrequently scrolling back to the middle). Try it out and LMK what you think.

@DanTup DanTup force-pushed the keep-selection-visible branch from 772658c to cf21687 Compare October 8, 2018 17:27
@DanTup
Copy link
Contributor Author

DanTup commented Oct 8, 2018

(Rebased, so the diff here is cleaner and doesn't include the other fix)

@DanTup DanTup merged commit 9cdb437 into flutter:master Oct 9, 2018
@DanTup DanTup deleted the keep-selection-visible branch October 9, 2018 06:33
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