Skip to content

Conversation

DHANUSHRAJA22
Copy link

@DHANUSHRAJA22 DHANUSHRAJA22 commented Aug 27, 2025

Description

This PR fixes the pagination component not displaying page numbers when there's only one page (resolves #1048).

Changes Made

  • Updated packages/ui/src/components/Pagination/helpers.ts:
    • Changed condition from start >= end to start > end in the range function
    • Updated JSDoc to reflect the new behavior
    • Added example showing range(1, 1) returns [1]

Problem Solved

Previously, when the pagination component had only one page, the page number "1" would not be displayed, showing only disabled previous/next buttons. This was caused by the range function returning an empty array when start === end.

With this change:

  • range(1, 1) now returns [1] instead of []
  • Single page scenarios properly display the page number
  • All existing behavior for multi-page scenarios is preserved

Related Issues

Testing

The existing test suite in helpers.test.ts already includes test cases that validate this behavior, including range(8, 9).toEqual([8, 9]) which confirms single-page ranges work correctly.

Checklist

Changed condition from start >= end to start > end to allow range function to return [start] when start equals end. This fixes the pagination component not showing page 1 when there's only one page. Addresses issue #1048.

Summarize the changes made and the motivation behind them.

Reference related issues using # followed by the issue number.

If there are breaking API changes - like adding or removing props, or changing the structure of the theme - describe them, and provide steps to update existing code.

Summary by CodeRabbit

  • Bug Fixes

    • Pagination now correctly handles equal start/end boundaries, showing a single item/page instead of an empty result. This ensures consistent display for edge cases and avoids missing pagination elements.
  • Documentation

    • Clarified boundary behavior in the pagination docs to reflect inclusive end handling.
    • Added an example demonstrating the equal-boundary case.

…tion): allow range function to return single page (fixes themesberg#1048)Update helpers.ts

Changed condition from start >= end to start > end to allow range function to return [start] when start equals end. This fixes the pagination component not showing page 1 when there's only one page. Addresses issue themesberg#1048.
Copy link

changeset-bot bot commented Aug 27, 2025

⚠️ No Changeset found

Latest commit: 1a7c19c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/DHANUSHRAJA22/flowbite-react/new/fix/pagination-single-page?filename=.changeset/angry-keys-rule.md&value=---%0A%22flowbite-react%22%3A%20patch%0A---%0A%0Afix(pagination)%3A%20allow%20single%20page%20display%20by%20updating%20range%20condition%20(resolves%20%231048)fix(pagination)%3A%20allow%20single%20page%20display%20by%20updating%20range%20function%20condition%20(resolves%20%231048)fix(pagination)%3A%20allow%20range%20function%20to%20return%20single%20pagefix(pagina%E2%80%A6%0A)

Copy link

vercel bot commented Aug 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
flowbite-react Ready Ready Preview Comment Aug 27, 2025 11:02am
flowbite-react-storybook Ready Ready Preview Comment Aug 27, 2025 11:02am

Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

Walkthrough

Adjusts the Pagination helper’s range function to include the end value when start equals end (returning [start] for start == end). Updates inline documentation accordingly. No exported APIs changed.

Changes

Cohort / File(s) Summary
Pagination helper: inclusive end in range
packages/ui/src/components/Pagination/helpers.ts
Change empty-case check from start >= end to start > end; update comments/docs; add example for equal-boundary case.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor UI as Pagination UI
  participant Helper as helpers.ts (range)
  UI->>Helper: range(start=1, end=1)
  Note right of Helper: New behavior: inclusive end when start==end
  Helper-->>UI: [1]
  Note over UI: UI renders single page "1"
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix single-page Pagination so "1" is rendered by adjusting range condition (#1048)

Assessment against linked issues: Out-of-scope changes

Suggested reviewers

  • rluders

Poem

I nibbled the bounds of a range tonight,
Tweaked a carrot-shaped “>=” to “>” just right.
Now page one hops in, crisp and clean,
Between two arrows, proudly seen.
Thump-thump! A single hop to cheer—
One page, one number, loud and clear. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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.
  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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: 1

🧹 Nitpick comments (1)
packages/ui/src/components/Pagination/helpers.ts (1)

5-11: Minor doc nit: specify integer inputs to avoid ambiguity with non-integers.

Since Array(end - start + 1) requires an integer length, consider noting that start and end are integers (page indices).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d61afda and 1a7c19c.

📒 Files selected for processing (1)
  • packages/ui/src/components/Pagination/helpers.ts (1 hunks)
🔇 Additional comments (2)
packages/ui/src/components/Pagination/helpers.ts (2)

5-5: Doc fix aligns return semantics with implementation.

The updated @returns text correctly reflects the inclusive behavior and the new guard.


10-10: Good example for the equal-bounds case.

This clarifies the intended single-page behavior.

Comment on lines +14 to 17
if (start > end) {
return [];
}

return [...Array(end - start + 1).keys()].map((key: number): number => key + start);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Inclusive boundary fix is correct; add a focused test and scan for callers relying on old behavior.

The start > end guard is the right fix and keeps end - start + 1 non-negative. Please:

  • Add a unit test specifically for range(1, 1) -> [1] and re-assert range(5, 1) -> [].
  • Verify no call sites depended on start === end returning [].

Run the following from repo root to review imports and usages:

Suggested tests (append to helpers.test.ts):

it('returns a single element when start equals end', () => {
  expect(range(1, 1)).toEqual([1]);
});

it('returns empty array when start is greater than end', () => {
  expect(range(5, 1)).toEqual([]);
});

🏁 Script executed:

#!/bin/bash
# Find modules importing Pagination helpers.range
rg -n -C2 -g '!**/node_modules/**' -g '!**/dist/**' -P 'import\s+\{\s*range\s*\}.*Pagination/helpers' packages

# Inspect all local usages within Pagination for possible assumptions on [] when start===end
rg -n -C3 -g '!**/node_modules/**' -g '!**/dist/**' -P '\brange\s*\(' packages/ui/src/components/Pagination

Length of output: 3620


Update tests for new inclusive-boundary behavior

The change to always include start === end is correct, but the existing tests still expect range(10, 10) to be []. We need to:

• Adjust the first test in helpers.test.ts so it only covers the start > end case.
• Add a new test for the start === end case to assert a single-element array.
• Verify that no other modules import or rely on the old range(start, end) behavior outside of Pagination (scan confirmed only internal usage in Pagination.tsx).

Affected file: packages/ui/src/components/Pagination/helpers.test.ts
Suggested diff:

 describe("Helpers / Range", () => {
-  it("should return the empty list, given start >= end", () => {
-    expect(range(20, 10)).toEqual([]);
-    expect(range(10, 10)).toEqual([]);
-  });
+  it("should return the empty list, given start > end", () => {
+    expect(range(20, 10)).toEqual([]);
+  });

+  it("should return a single element, given start === end", () => {
+    expect(range(10, 10)).toEqual([10]);
+  });

   it("should return every number from start to end, inclusive, given start < end", () => {
     expect(range(10, 20)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
   });

No external imports of range were found beyond the Pagination component itself, so no other callers need changes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (start > end) {
return [];
}
return [...Array(end - start + 1).keys()].map((key: number): number => key + start);
// packages/ui/src/components/Pagination/helpers.test.ts
describe("Helpers / Range", () => {
it("should return the empty list, given start > end", () => {
expect(range(20, 10)).toEqual([]);
});
it("should return a single element, given start === end", () => {
expect(range(10, 10)).toEqual([10]);
});
it("should return every number from start to end, inclusive, given start < end", () => {
expect(range(10, 20)).toEqual([
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
]);
});
});
🤖 Prompt for AI Agents
In packages/ui/src/components/Pagination/helpers.test.ts around lines 14 to 17,
update the tests to reflect the inclusive-boundary change: modify the existing
first test so it only asserts the start > end case (e.g., range(11,10) yields
[]), and add a new test that asserts the start === end case returns a
single-element array (e.g., range(10,10) yields [10]); ensure test descriptions
reflect the cases and run the test suite to confirm no other failures — note
that a scan found no external imports beyond Pagination.tsx so no other modules
need changes.

@SutuSebastian SutuSebastian changed the title fix(pagination): allow single page display by updating range condition (resolves #1048)fix(pagination): allow single page display by updating range function condition (resolves #1048)fix(pagination): allow range function to return single pagefix(pagina… fix(pagination): allow single page display by updating range condition Sep 4, 2025
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.

Pagination is broken if there is only one page
1 participant