Skip to content
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

Components: Fix React Compiler error for 'useScrollRectIntoView' #66498

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/components/src/tabs/tablist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ function useScrollRectIntoView(
const childRightEdge = childLeft + childWidth;
const rightOverflow = childRightEdge + margin - parentRightEdge;
const leftOverflow = parentScroll - ( childLeft - margin );

let scrollLeft = null;
if ( leftOverflow > 0 ) {
parent.scrollLeft = parentScroll - leftOverflow;
scrollLeft = parentScroll - leftOverflow;
} else if ( rightOverflow > 0 ) {
parent.scrollLeft = parentScroll + rightOverflow;
scrollLeft = parentScroll + rightOverflow;
}

if ( scrollLeft !== null ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a precaution.

/**
* The optional chaining is used here to avoid unit test failures.
* It can be removed when JSDOM supports `Element` scroll methods.
* See: https://github.com/WordPress/gutenberg/pull/66498#issuecomment-2441146096
*/
parent.scroll?.( { left: scrollLeft } );
}
}, [ margin, parent, rect ] );
}
Expand Down
Loading