-
Notifications
You must be signed in to change notification settings - Fork 344
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
Conversation
There was a problem hiding this 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, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
414f64b
to
772658c
Compare
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. |
772658c
to
cf21687
Compare
(Rebased, so the diff here is cleaner and doesn't include the other fix) |
Fixes #38.