fix(JumpLinks): updated demo code for active item#12590
Conversation
WalkthroughJumpLinks scrollspy now activates the last link when its scroll container reaches the bottom. The scrollspy demo also targets ChangesJumpLinks scrollspy
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/react-core/src/components/JumpLinks/JumpLinks.tsx`:
- Around line 147-148: Update the bottom-detection logic in the JumpLinks scroll
handling so it requires the container to be scrollable before setting
isAtBottom, excluding cases where scrollHeight equals clientHeight. Apply the
same guard to the corresponding logic around the alternate referenced lines,
preserving the existing bottom threshold for genuinely scrollable containers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 988c5eab-531a-4730-822f-7eb8cbabb833
📒 Files selected for processing (2)
packages/react-core/src/components/JumpLinks/JumpLinks.tsxpackages/react-core/src/demos/examples/JumpLinks/JumpLinksScrollspy.tsx
| const isAtBottom = | ||
| Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Only treat the container as “at bottom” when it actually scrolls.
When scrollHeight === clientHeight, this condition is true at scrollTop === 0, so a short/non-scrollable page immediately marks the last JumpLink active instead of the first/default item.
Proposed fix
const isAtBottom =
- Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight;
+ scrollableElement.scrollHeight > scrollableElement.clientHeight &&
+ Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight;Also applies to: 160-162
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/react-core/src/components/JumpLinks/JumpLinks.tsx` around lines 147
- 148, Update the bottom-detection logic in the JumpLinks scroll handling so it
requires the container to be scrollable before setting isAtBottom, excluding
cases where scrollHeight equals clientHeight. Apply the same guard to the
corresponding logic around the alternate referenced lines, preserving the
existing bottom threshold for genuinely scrollable containers.
|
Thanks for the fix, this looks like a solid improvement for #12223 (especially the bottom-of-scroll active-item case and selector update). For Keycloak, we still can’t revert our temporary |
What: Closes #12223
Also added additional line of logic for an issue I was noticing for scrollspy demos (last jump link item not becoming "current" if that section didn't have enough content).
@edewit I noticed the Keycloak issue referenced in the above PF issue that y'all may have implemented a fix for the issue? FWIW i believe the original issue may have been because the scrollable page container was no longer accurate; we now have the
.pf-v6-c-page__mainselector as the scrollable container, not.pf-v6-c-page__main-container(which both one of our demos that were broken as well as Keycloak were originally using, at least based on Keycloak PR 47651).Additional issues:
Summary by CodeRabbit