Skip to content

fix: Ensure row is visible before getting it #7260

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 5 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public void shouldPositionItemsCorrectlyAfterUpdatingComponentRenderers() {

@Test
public void shouldPositionItemsCorrectlyAfterScrollingToEnd() {
int initialLastRow = grid.getRowCount() - 1;
grid.scrollToRow(initialLastRow);
var initialLastRow = grid.getRowCount() - 1;
var row = grid.getRow(initialLastRow, true);
var expectedPosition = row.getLocation().y + row.getSize().height;

add.click();
// Expect the y position of the last row to equal the y position + the
// height of the previous row
Assert.assertEquals(
grid.getRow(initialLastRow).getLocation().y
+ grid.getRow(initialLastRow).getSize().height,
Assert.assertEquals(expectedPosition,
grid.getRow(initialLastRow + 1).getLocation().y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,40 @@ public List<GridTRElement> getRows(int firstRowIndex, int lastRowIndex)
}

/**
* Gets the <code>tr</code> element for the given row index.
* Gets the {@code tr} element for the given row index.
*
* @param rowIndex
* the row index
* @return the tr element for the row
* @return the {@code tr} element for the row, or {@code null} if the row is
* not in viewport
* @throws IndexOutOfBoundsException
* if no row with given index exists
*/
public GridTRElement getRow(int rowIndex) throws IndexOutOfBoundsException {
return getRow(rowIndex, false);
}

/**
* Gets the {@code tr} element for the given row index.
* <p>
* Returns {@code null} if the row is not in viewport and the provided
* {@code scroll} parameter is {@code false}.
*
* @param rowIndex
* the row index
* @param scroll
* whether to scroll to the row index
* @return the {@code tr} element for the row, or {@code null} if the row is
* not in viewport and the provided {@code scroll} parameter is
* {@code false}
* @throws IndexOutOfBoundsException
* if no row with given index exists
*/
public GridTRElement getRow(int rowIndex, boolean scroll)
throws IndexOutOfBoundsException {
if (scroll && !isRowInView(rowIndex)) {
scrollToFlatRow(rowIndex);
}
var rows = getRows(rowIndex, rowIndex);
return rows.size() == 1 ? rows.get(0) : null;
}
Expand Down