-
Notifications
You must be signed in to change notification settings - Fork 841
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
Expose scrollTo and scrollToItem on imperative ref #6042
Conversation
@weltenwort this looks great to me! Any objections if I push up Cypress tests to your branch for these 2 new APIs? |
I accidentally submitted this too early and have since reverted it to a draft because I wanted to add tests. 🙈 Any help with those would be appreciated. |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
Yes, for sure! You'll want describe('scrollToItem', () => {
it('scrolls to a specific cell position, rendering the cell', () => {
cy.get('[data-gridcell-row-index="90"]']).should('not.exist');
ref.current.scrollToItem({ rowIndex: 90, columnIndex: 5 });
cy.get('[data-gridcell-row-index="90"]']).should('exist');
});
});
describe('scrollTo', () => {
it('scrolls the grid to a specified position', () => {
cy.get('.euiDataGrid__virtualized']).its('scrollY').should('equal', 0);
ref.current.scrollTo({ scrollTop: 500, scrollLeft: 0 });
cy.get('.euiDataGrid__virtualized']).its('scrollY').should('equal', 500);
});
}); I didn't actually run the above so it's possible I have some syntax incorrect - feel free to bug me if so! Also, I can't remember if the Cypress docs mention it, but the CLI command you'll want to run/test this locally is |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
<li> | ||
<p> | ||
<EuiCode> | ||
scrollTo({'{ scrollLeft: number, scrollTop: number }'}) | ||
</EuiCode>{' '} | ||
- scrolls the grid to the specified horizontal and vertical | ||
pixel offsets. | ||
</p> | ||
</li> | ||
<li> | ||
<p> | ||
<EuiCode> | ||
scrollToItem( | ||
{ | ||
'{align: string = "auto", columnIndex?: number, rowIndex?: number }' | ||
} | ||
) | ||
</EuiCode>{' '} | ||
- scrolls the grid to the specified row and columns indices | ||
</p> | ||
</li> |
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.
Couple quick documentation notes:
-
I think we should link to react-window's docs (https://react-window.vercel.app/#/api/FixedSizeGrid#methods) rather than write our own - in general since we're just passing their methods as-is, their docs will always be more up to date than ours.
-
I'm also tempted to nest another
<ul>
titledreact-window methods
(or similar) for this section - this is important because of how EUI's ref APIs handlerowIndex
vs how react-window's APIs handlerowIndex
. See the below callout:
EUI expects the rowIndex
received from the original unsorted/unpaginated consumer data. react-window does not care at all about that and wants what EUI refers to as the visibleRowIndex
(i.e., the row index after sorting and pagination). This is a confusing but important difference that could potentially bite consumers if not clarified, and I think it's worth separating out react-window's ref APIs vs EUI's ref APIs for that reason.
@chandlerprall any thoughts here?
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.
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.
Separating the new methods into their own list makes sense to me. I think it draws a good distinction between the logic EUI provides vs. these pass-through functions. That would also provide a natural place to link to react-window's docs
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, I'll split the react-window API into its own section. Any opinion which section should own the example? Should it belong to the "Ref methods" or "react-window methods" section?
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 put it after the second section for now since it's pretty short. Let me know what you think.
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
Co-authored-by: Constance <[email protected]>
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
Looks fantastic, thanks so much @weltenwort! I have a couple super minor docs comments/tweaks that I'll go ahead and push up to your branch since I'm a half-day timezone away from you (and very slow in the mornings 😅) and don't want to delay your PR another full day. Excited to see the next PR with RowHeightUtils test improvements, that looked really cool from what I saw in the original PR! |
- combine sections and use EuiTitle tag for react-window methods - Fix link to react-window docs - minor grammar tweaks
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
@constancecchen thanks so much for helping me with the docs ❤️ and your cypress snippets got me started very quickly
sure thing, |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6042/ |
📝 Summary
This exposes the
scrollTo()
andscrollToItem()
methods on the imperative API of the grid component. It's a break-out PR from #6028 (#6024).Checklist