Skip to content

Commit

Permalink
Use optional chaining and add inline comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Nov 1, 2024
1 parent 481431d commit 925b5f5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/components/src/tabs/tablist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ function useScrollRectIntoView(
const rightOverflow = childRightEdge + margin - parentRightEdge;
const leftOverflow = parentScroll - ( childLeft - margin );
if ( leftOverflow > 0 ) {
parent.scroll( { left: parentScroll - leftOverflow } );
/**
* 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: parentScroll - leftOverflow } );
} else if ( rightOverflow > 0 ) {
parent.scroll( { left: parentScroll + rightOverflow } );
parent.scroll?.( { left: parentScroll + rightOverflow } );
}
}, [ margin, parent, rect ] );
}
Expand Down

0 comments on commit 925b5f5

Please sign in to comment.