fix: #10182 fixed the table keyboard navigation in the scrollIntoViewport #10211
Conversation
| let shouldCenter = true; | ||
| if (containingElement) { | ||
| const containerRect = containingElement.getBoundingClientRect(); | ||
| if (containerRect.height > window.innerHeight) { |
There was a problem hiding this comment.
Please see #10182 (comment). We shouldn't skip merely based on dimensions.
There was a problem hiding this comment.
Thanks @nwidynski, I have updated my code to handle scrolling based on dimensions.
|
Hi @nwidynski , can you please check my PR and let me know if any changes are needed. |
|
The problem I mentioned in the last comment is still unaddressed. The container may be obscured by another scrollParent, so directly comparing its bounding rect against the viewport doesn't work reliably. |
|
@nwidynski, I have made the changes. The parent scroll will not obscure the container. Can you please check and let me know if any changes are needed |
| const isExceedingViewport = containerRect.height > window.innerHeight; | ||
| if (isFullyVisible || isExceedingViewport) { | ||
| blockOption = 'nearest'; | ||
| inlineOption = 'nearest'; | ||
| } |
There was a problem hiding this comment.
This is essentially still the same thing as before. There are also problems with using nearest which have been described in the issues comment section. I believe it will need a different approach.
There was a problem hiding this comment.
I've reworked the implementation to address the feedback instead of continuing with the dimension-based approach.
The dimension check has been removed completely, and the implementation no longer uses scrollIntoView({ block: 'nearest' }). Instead, scrollIntoViewport now goes through every scroll parent between the target element and the document root. For each scroll parent, it calls a new scrollIntoViewIfNeeded helper that calculates the visible scroll area by considering borders, scroll-padding, and scrollbar size, and scrolls only the minimum distance needed to bring the target element into view.
This also addresses the concern raised in the issue about an outer scroll parent hiding the container. Since every scroll parent is handled separately, both the table's internal scroll and any outer scrollable container are handled correctly.
To verify this, I added a test for the nested scroll parent scenario. I also tested it manually in the browser using two Storybook scenarios:
A normal table.
A table inside a scrollable parent container.
Both scenarios are working as expected. I've attached a video showing these browser-level tests for reference.
scroll-into-viewport-browser-validation.mp4
f089e5f to
f506186
Compare
2a6b952 to
5e7060a
Compare
5e7060a to
5de4999
Compare
…crollIntoViewport-componen
…crollIntoViewport-componen
…crollIntoViewport-componen
Closes #10182
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: