Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/eleven-buses-bet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudoperators/juno-ui-components": patch
---

Fix NaN input in Pagination
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const Pagination = ({
// Enforce minimum and maximum limits
if (inputValue < 1) {
inputValue = 1
} else if (controlTotalPage !== undefined && inputValue > controlTotalPage) {
} else if (isNaN(inputValue) || (controlTotalPage !== undefined && inputValue > controlTotalPage)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, this won't work if controlTotalPage is undefined. Imo a better way to deal with NaN values is to add it to the inputValue < 1 case instead, because there is always going to be a first page.

inputValue = controlTotalPage
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,18 @@ describe("Pagination", () => {
expect(screen.getByTestId("my-pagination")).toBeInTheDocument()
expect(screen.getByTestId("my-pagination")).toHaveAttribute("data-lolol", "123-456")
})

test("sets inputValue to controlTotalPage on symbol or non-numeric input", async () => {
const onInputChangeMock = vi.fn()
render(<Pagination variant="input" totalPages={5} onInputChange={onInputChangeMock} />)

const textInput = screen.getByRole("textbox")
fireEvent.change(textInput, { target: { value: "$" } }) // Non-numeric input
fireEvent.blur(textInput)

await waitFor(() => {
// Check that controlTotalPage was set after invalid input
expect(onInputChangeMock).toHaveBeenCalledWith(5)
})
})
Comment thread
guoda-puidokaite marked this conversation as resolved.
Outdated
})
Loading