fix(Nav): ensure scroll buttons respond to window resize in horizontal nav#12132
Closed
evwilkin wants to merge 1 commit intopatternfly:mainfrom
Closed
fix(Nav): ensure scroll buttons respond to window resize in horizontal nav#12132evwilkin wants to merge 1 commit intopatternfly:mainfrom
evwilkin wants to merge 1 commit intopatternfly:mainfrom
Conversation
…l nav Fixes patternfly#12047 ## Problem Horizontal navigation scroll buttons (left/right arrows) were not appearing or disappearing when the browser window was resized. This occurred because the ResizeObserver only monitored the nav list container element itself, not the window. When the window resized but the container's dimensions didn't change (due to flex/grid layouts), the ResizeObserver wouldn't fire and scroll button visibility wasn't updated. ## Root Cause In NavList.tsx, the component relied solely on a ResizeObserver watching the nav list container. In scenarios where the window resizes but the container size remains stable (common with responsive layouts), the observer doesn't detect the change, so handleScrollButtons() is never called to update scroll button state. ## Solution Added a debounced window resize event listener alongside the existing ResizeObserver to ensure scroll buttons update in all resize scenarios: - ResizeObserver: Provides immediate response when container changes - Window resize listener: Catches cases where window resize doesn't trigger container resize events - Debouncing (250ms): Prevents performance issues from rapid resize events The fix maintains backward compatibility and doesn't affect any existing functionality (manual scrolling, keyboard navigation, etc.). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
|
Preview: https://pf-react-pr-12132.surge.sh A11y report: https://pf-react-pr-12132-a11y.surge.sh |
nicolethoen
approved these changes
Dec 11, 2025
kmcfaul
approved these changes
Dec 11, 2025
Contributor
Contributor
|
@thatblindgeye it looks like it was fixed already on staging by #12070 Here's the staging URL to verify - https://staging.patternfly.org/components/navigation/react-demos/horizontal-nav/ I'd say this PR could be closed, though looks like this PR and #12070 have different fixes - not sure if that's something to consider before closing. |
Member
Author
|
Nice catch @thatblindgeye and @mcoker , looks like this is no longer needed 👍 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Closes #12047 - This PR fixes horizontal navigation scroll buttons not appearing/disappearing when the browser window is resized.
Problem Description
When using horizontal navigation, the scroll buttons (left/right arrows) were not responding to window resize events. This caused two issues:
Shrinking the window: When the window becomes narrow enough that nav items overflow, the scroll buttons don't appear until the user manually scrolls or focuses a nav item.
Expanding the window: When the window becomes wide enough that all nav items fit, the scroll buttons don't disappear until the user clicks on them.
Root Cause
The
NavListcomponent relies on aResizeObserverthat only monitors the nav list container element itself. When the browser window resizes but the container's dimensions don't change (common in flex/grid layouts), theResizeObserverdoesn't fire, sohandleScrollButtons()is never called to update scroll button visibility.How
Added a (debounced) window resize event listener alongside the existing
ResizeObserver:Changes in
NavList.tsx:handleWindowResizeproperty - Stores the debounced handler for cleanupcomponentDidMount()- Creates debounced resize handler and adds window listenercomponentWillUnmount()- Properly removes the window listener to prevent memory leaksApproach
The fix implements dual monitoring:
Manual Testing Steps
To verify the fix on the horizontal nav demo:
Test scroll buttons appear on shrink:
Test scroll buttons disappear on expand:
🤖 Generated with Claude Code