-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[table] fix: vertical scroll bug when ghostCells enabled attempt 2 #5251
[table] fix: vertical scroll bug when ghostCells enabled attempt 2 #5251
Conversation
packages/table/src/table2.tsx
Outdated
const rowIndices = this.grid.getRowIndicesInRect( | ||
viewportRect, | ||
enableGhostCells!, | ||
this.columnHeaderHeight || Grid.MIN_COLUMN_HEADER_HEIGHT, |
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.
used ||
vs ??
bc this.columnHeaderHeight
was inconsistently being 0
vs the actual height when running tests
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.
ok, that's fair, but I think I'd rather not make an exception to the strict-boolean-expressions rule here (we don't actually lint for it, but I try to enforce it manually). I find the ||
hard to read, how about something like this instead:
this.columnHeaderHeight || Grid.MIN_COLUMN_HEADER_HEIGHT, | |
this.columnHeaderHeight > 0 ? this.columnHeaderHeight : Grid.MIN_COLUMN_HEADER_HEIGHT, |
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.
actually, on second thought... we never really want this.columnHeaderHeight
to be 0
.
we could change the ref handler to prevent that from happening, and keep the min-height logic scoped to that part of this component's code:
private refHandlers = {
columnHeader: (ref: HTMLElement | null) => {
this.columnHeaderElement = ref;
if (ref != null) {
this.columnHeaderHeight = Math.max(ref.clientHeight, Grid.MIN_COLUMN_HEADER_HEIGHT);
}
PR preview links: table-dev-app, docs-app |
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.
functionality looks good in the preview build, just left some comments for code style
packages/table/src/common/grid.ts
Outdated
@@ -253,7 +253,12 @@ export class Grid { | |||
* Returns the start and end indices of rows that intersect with the given | |||
* `Rect` argument. | |||
*/ | |||
public getRowIndicesInRect(rect: Rect, includeGhostCells = false, limit = Grid.DEFAULT_MAX_ROWS): RowIndices { | |||
public getRowIndicesInRect( |
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.
this args list is getting a little unwieldy, could we refactor it to use an options object?
also, when you do, can you document this new argument/option and leave a comment about why we need it?
packages/table/src/table2.tsx
Outdated
const rowIndices = this.grid.getRowIndicesInRect( | ||
viewportRect, | ||
enableGhostCells!, | ||
this.columnHeaderHeight || Grid.MIN_COLUMN_HEADER_HEIGHT, |
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.
ok, that's fair, but I think I'd rather not make an exception to the strict-boolean-expressions rule here (we don't actually lint for it, but I try to enforce it manually). I find the ||
hard to read, how about something like this instead:
this.columnHeaderHeight || Grid.MIN_COLUMN_HEADER_HEIGHT, | |
this.columnHeaderHeight > 0 ? this.columnHeaderHeight : Grid.MIN_COLUMN_HEADER_HEIGHT, |
|
||
const isViewportUnscrolledVertically = viewportRect != null && viewportRect.top === 0; | ||
const areRowHeadersLoading = hasLoadingOption(this.props.loadingOptions, TableLoadingOption.ROW_HEADERS); | ||
const areGhostRowsVisible = enableGhostCells! && this.grid.isGhostIndex(rowIndices.rowIndexEnd - 1, 0); | ||
const areGhostRowsVisible = enableGhostCells! && this.grid.isGhostIndex(rowIndices.rowIndexEnd, 0); |
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 came to the same conclusion a little while ago when I was playing around with this code – that the - 1
is not strictly necessary – so this change lgtm 👍🏽
packages/table/src/table2.tsx
Outdated
const rowIndices = this.grid.getRowIndicesInRect( | ||
viewportRect, | ||
enableGhostCells!, | ||
this.columnHeaderHeight || Grid.MIN_COLUMN_HEADER_HEIGHT, |
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.
actually, on second thought... we never really want this.columnHeaderHeight
to be 0
.
we could change the ref handler to prevent that from happening, and keep the min-height logic scoped to that part of this component's code:
private refHandlers = {
columnHeader: (ref: HTMLElement | null) => {
this.columnHeaderElement = ref;
if (ref != null) {
this.columnHeaderHeight = Math.max(ref.clientHeight, Grid.MIN_COLUMN_HEADER_HEIGHT);
}
packages/table/src/common/grid.ts
Outdated
public getRowIndicesInRect( | ||
rect: Rect, | ||
includeGhostCells = false, | ||
rectHeightCorrection = 0, |
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 naming this columHeaderHeight
would be simpler & more explicit
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.
Makes sense, there are some other functions using getRowIndicesInRect
like invokeOnVisibleCellsChangeCallback
that aren't using this arg but maybe they should be? since a row is technically not visible after it goes behind the header column but we still consider it visible since it's in the rect
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.
yeah, I guess invokeOnVisibleCellsChangeCallback
should know about columnHeaderHeight
as well...
if we're finding that the Grid needs to know the column header height so often, then maybe we should try to pass it columnHeaderHeight
from Table / Table2 when we construct/validate the grid? hopefully this value won't get out of sync 🤞🏽, and that change might reduce some code complexity. before you do this, however, can you verify that invokeOnVisibleCellsChangeCallback
is buggy right now? i.e. that it returns the wrong range of indices when the column header is larger than the default height.
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.
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.
It still seems off after accounting for header height... the "start" should be closer to 5 or 6 when you scroll all the way down, no? we can address this in a separate PR, but it looks like it's not a high priority for this particular callback since we haven't gotten any bug reports for onVisibleCellsChange
accuracy
ad817d4
to
3af66c3
Compare
@mattskrobola please try to avoid force-pushing; I like to see all the changes in a PR branch, and sometimes a force-push will make the CI build confused (it got canceled and had to be manually re-triggered here) |
Fixes #4765 (again)
Checklist
Changes proposed in this pull request:
Adds a parameter
rectHeightCorrection
togetRowIndicesInRect
. This is utilized inshouldDisableVerticalScroll
to account for thecolumnHeaderHeight
when checking for which cells are visible to determine whether or not to disable vertical scrolling.Also reverts the table change made in #5113 that attempted to fix this issue (which it did for the case when the table used the default column header) but didn't address the root cause of the problem - that header heights weren't being accounted for when determining which rows were currently visible.
Added a smoke test table in the table-app features
Reviewers should focus on:
Screenshot
before:
after: