Skip to content

Commit

Permalink
refactor(pagination): minor nitpicks
Browse files Browse the repository at this point in the history
- check for null ref in usePagination
- restore original IntersectionObserver in test
  • Loading branch information
Peterl561 committed Dec 4, 2024
1 parent 7348ade commit 701b2ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/components/pagination/__tests__/pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ describe("Pagination", () => {
});

it("the pagination cursor should not have data-moving attribute before intersection", () => {
const originalIntersectionObserver = window.IntersectionObserver;

// save callback and options to later emulate intersection event
let intersectCallback: IntersectionObserverCallback | undefined;
let intersectOptions: IntersectionObserverInit | undefined;
Expand Down Expand Up @@ -148,5 +150,7 @@ describe("Pagination", () => {

// on rerender, the cursor should have the data-moving attribute
expect(cursor).toHaveAttribute("data-moving");

window.IntersectionObserver = originalIntersectionObserver;
});
});
4 changes: 3 additions & 1 deletion packages/components/pagination/src/use-pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ export function usePagination(originalProps: UsePaginationProps) {
const [setRef, isVisible] = useIntersectionObserver();

useEffect(() => {
setRef(domRef.current);
if (domRef.current) {
setRef(domRef.current);
}
}, [domRef.current]);

const activePageRef = useRef(activePage);
Expand Down

0 comments on commit 701b2ca

Please sign in to comment.