Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/cold-geese-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@heroui/number-input": patch
---

handle onChange event in number input (#4874)
29 changes: 28 additions & 1 deletion packages/components/number-input/__tests__/number-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,34 @@ describe("NumberInput", () => {

expect(stepperButton).toBeNull();
});

it("should emit onChange", async () => {
const onChange = jest.fn();

const {container} = render(<NumberInput label="test number input" onChange={onChange} />);

const input = container.querySelector("input") as HTMLInputElement;

await user.click(input);
await user.keyboard("1024");

expect(onChange).toHaveBeenCalledTimes(4);
});

it("should emit onChange with keyboard up & down key", async () => {
const onChange = jest.fn();

const {container} = render(<NumberInput label="test number input" onChange={onChange} />);

const input = container.querySelector("input") as HTMLInputElement;

await user.click(input);
await user.keyboard("[ArrowUp]");
await user.keyboard("[ArrowUp]");
expect(onChange).toHaveBeenCalledTimes(2);
await user.keyboard("[ArrowDown]");
expect(onChange).toHaveBeenCalledTimes(3);
});
});

describe("NumberInput with React Hook Form", () => {
Expand Down Expand Up @@ -503,7 +531,6 @@ describe("NumberInput with React Hook Form", () => {

await user.tab();
await user.keyboard("1234");
await user.tab();
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/components/number-input/src/use-number-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function useNumberInput(originalProps: UseNumberInputProps) {
...originalProps,
validationBehavior,
locale,
onChange: onValueChange,
onChange: chain(onValueChange, onChange),
});

const {
Expand Down