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

fix(pagination): active element incorrect position on first load #3346

Open
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

arindam1997007
Copy link

@arindam1997007 arindam1997007 commented Jun 27, 2024

Closes #3151

📝 Description

Fixed Active Element positionon on first load, when pagination is rendered initially with display:hidden

⛳️ Current behavior (updates)

On first load, instead of left arrow button, Page 1 active element is displayed

🚀 New behavior

Active Element position is fixed even on first load, using IntersectionObserver.

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

According to code submitted by users which can be reproduced, issue occurs if pagination component is rendered using display:hidden for the first time, and then switching to display:block.

Using IntersectionObserver, checking for display of pagination componenet in the viewport, and then running the required functions.

fix-pagination.mov

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the position of the active element in the Pagination component when rendered with display: hidden.
  • New Features
    • Improved scrolling behavior and visibility checks in the Pagination component using the new useIntersectionObserver hook.

- Using useIntersectionObserver to check for visibility of active element
- If active element is visible, calling scrollTo method
Copy link

changeset-bot bot commented Jun 27, 2024

🦋 Changeset detected

Latest commit: 8baf2a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@nextui-org/pagination Patch
@nextui-org/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2024 0:37am

Copy link

vercel bot commented Jun 27, 2024

@arindam1997007 is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The update introduces a patch for the Pagination component in the @nextui-org/pagination package to correct the position of the active element when rendered with display: hidden. Additionally, it resolves issues with the left pagination arrow showing page 1 on the initial load by integrating the useIntersectionObserver hook for better visibility management and scroll behavior.

Changes

Files Change Summary
packages/components/pagination/package.json Added @nextui-org/use-intersection-observer as a new dependency.
packages/components/pagination/src/use-pagination.ts Modified the usePagination function to utilize useIntersectionObserver for visibility checks based on intersection status.
.changeset/tricky-stingrays-relax.md Introduced a patch for the Pagination component to correct the active element's position when hidden.

Sequence Diagram(s)

Not applicable for these changes due to their simplicity and specific focus on fixing visibility issues.

Assessment against linked issues

Objective Addressed Explanation
[#3151]: Pagination left arrow shows page 1 on the first load
Other objectives from linked issues not applicable for this PR Only the specific bug fix for pagination is addressed in this PR.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arindam1997007
Copy link
Author

Hi @wingkwong
Please review when you get the chance.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 78d4216 and 08471fd.

Files selected for processing (3)
  • .changeset/tricky-stingrays-relax.md (1 hunks)
  • packages/components/pagination/package.json (1 hunks)
  • packages/components/pagination/src/use-pagination.ts (4 hunks)
Additional comments not posted (4)
.changeset/tricky-stingrays-relax.md (1)

5-5: Clear and concise changeset description.

The changeset description succinctly captures the essence of the fix and links it to the relevant issue.

packages/components/pagination/package.json (1)

47-47: New dependency added: @nextui-org/use-intersection-observer.

Ensure that the version specified aligns with project standards and conduct a security audit on the new package to prevent potential vulnerabilities.

packages/components/pagination/src/use-pagination.ts (2)

19-19: Import added: useIntersectionObserver.

The addition of the useIntersectionObserver hook is aligned with the PR's objectives to manage the visibility of pagination elements effectively.


Line range hint 196-228: Significant changes to pagination visibility and interaction logic.

The integration of the useIntersectionObserver hook and the changes in the scrollTo function enhance the component's responsiveness to visibility changes. Ensure comprehensive testing, especially for edge cases involving rapid visibility changes.

Also applies to: 284-298

Verification successful

Comprehensive testing verified for pagination component

The test files related to the pagination component cover various aspects of its functionality, including state changes, rendering, and edge cases. The integration of the useIntersectionObserver hook and changes in the scrollTo function are likely well-tested.

  • packages/components/pagination/tests/pagination.test.ts
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify comprehensive testing of pagination component.
# Test: Search for test files related to pagination component. Expect: Tests covering new changes.

fd "pagination.*test.*" "packages/components/pagination/tests" --exec cat {}

Length of output: 202



Script:

#!/bin/bash
# Description: Locate test files related to the pagination component.
# Test: Search for test files related to pagination component across the entire repository.

fd "pagination.*test.*" --exec cat {}

Length of output: 4822

.changeset/tricky-stingrays-relax.md Outdated Show resolved Hide resolved
packages/components/pagination/package.json Show resolved Hide resolved
@wingkwong wingkwong changed the title fix(pagination): active element incorrect position on first load (#3151) fix(pagination): active element incorrect position on first load Jun 28, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 08471fd and 8baf2a7.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (1)
  • .changeset/tricky-stingrays-relax.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .changeset/tricky-stingrays-relax.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Pagination left arrow shows page 1 on the first load
2 participants