-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix: do not scroll when clicking cells #7717
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import '../theme/lumo/lit-all-imports.js'; | ||
import '../src/lit-all-imports.js'; | ||
import './scroll-into-view.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '../vaadin-grid.js'; | ||
import './scroll-into-view.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { expect } from '@vaadin/chai-plugins'; | ||
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers'; | ||
import { sendKeys, sendMouse } from '@web/test-runner-commands'; | ||
import { flushGrid, getContainerCell, getLastVisibleItem, getPhysicalItems } from './helpers.js'; | ||
|
||
describe('scroll into view', () => { | ||
let grid, firstCell, secondCell, secondDetailsCell; | ||
|
||
function verifyRowFullyVisible(grid, rowIndex) { | ||
const scrollerBounds = grid.$.scroller.getBoundingClientRect(); | ||
const row = getPhysicalItems(grid)[rowIndex]; | ||
const rowBounds = row.getBoundingClientRect(); | ||
expect(rowBounds.top).to.be.greaterThanOrEqual(scrollerBounds.top); | ||
expect(rowBounds.bottom).to.be.lessThanOrEqual(scrollerBounds.bottom); | ||
} | ||
|
||
function verifyRowNotFullyVisible(grid, rowIndex) { | ||
const scrollerBounds = grid.$.scroller.getBoundingClientRect(); | ||
const row = getPhysicalItems(grid)[rowIndex]; | ||
const rowBounds = row.getBoundingClientRect(); | ||
const isTopInvisible = rowBounds.top < scrollerBounds.top; | ||
const isBottomInvisible = rowBounds.bottom > scrollerBounds.bottom; | ||
expect(isTopInvisible || isBottomInvisible).to.be.true; | ||
} | ||
|
||
beforeEach(async () => { | ||
grid = fixtureSync(` | ||
<vaadin-grid style="height: 150px"> | ||
<vaadin-grid-column></vaadin-grid-column> | ||
</vaadin-grid> | ||
`); | ||
const column = grid.querySelector('vaadin-grid-column'); | ||
column.renderer = (root, _, model) => { | ||
root.innerHTML = `<div style="height: 100px">${model.item}</div>`; | ||
}; | ||
grid.rowDetailsRenderer = (root, _, model) => { | ||
root.innerHTML = `<div style="height: 30px">${model.item} details</div>`; | ||
}; | ||
grid.items = [1, 2]; | ||
grid.detailsOpenedItems = [2]; | ||
|
||
flushGrid(grid); | ||
await nextFrame(); | ||
|
||
firstCell = getContainerCell(grid.$.items, 0, 0); | ||
secondCell = getContainerCell(grid.$.items, 1, 0); | ||
secondDetailsCell = getLastVisibleItem(grid).querySelector('[part~="details-cell"]'); | ||
}); | ||
|
||
it('should scroll row into view when focusing programmatically', () => { | ||
verifyRowNotFullyVisible(grid, 1); | ||
|
||
secondCell.focus(); | ||
|
||
expect(grid.$.table.scrollTop).to.be.above(0); | ||
verifyRowFullyVisible(grid, 1); | ||
}); | ||
|
||
it('should scroll row into view when focusing with keyboard navigation', async () => { | ||
verifyRowNotFullyVisible(grid, 1); | ||
|
||
firstCell.focus(); | ||
await sendKeys({ press: 'ArrowDown' }); | ||
|
||
expect(grid.$.table.scrollTop).to.be.above(0); | ||
verifyRowFullyVisible(grid, 1); | ||
}); | ||
|
||
it('should not change scroll position when focusing row cell with click', async () => { | ||
verifyRowNotFullyVisible(grid, 1); | ||
|
||
const bounds = secondCell.getBoundingClientRect(); | ||
await sendMouse({ type: 'click', position: [bounds.x + 5, bounds.y + 5] }); | ||
|
||
expect(grid.$.table.scrollTop).to.equal(0); | ||
}); | ||
|
||
it('should not change scroll position when focusing details cell with click', async () => { | ||
// Make details cell partially visible for clicking | ||
grid.style.height = '240px'; | ||
await nextFrame(); | ||
|
||
verifyRowNotFullyVisible(grid, 1); | ||
|
||
const bounds = secondDetailsCell.getBoundingClientRect(); | ||
await sendMouse({ type: 'click', position: [bounds.x + 5, bounds.y + 5] }); | ||
|
||
expect(grid.$.table.scrollTop).to.equal(0); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removing the
__scrollIntoViewport
call in scroll mixin didn't cause any test failures, so I also added some general cases where scrolling a row into view would be expected.For clicking I also added a separate test for the details cell, since the linked issue was about clicking the details cell specifically. With the current implementation it doesn't make a difference which cell in a row you click, but can't hurt to have more test cases I guess.