mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(number-input): onChange event in number input (#4907)
* fix(number-input): onChange event in number input * chore(number-input): remove duplicate test case
This commit is contained in:
parent
2186f6da23
commit
f55cf8bc7f
5
.changeset/cold-geese-visit.md
Normal file
5
.changeset/cold-geese-visit.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@heroui/number-input": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
handle onChange event in number input (#4874)
|
||||||
@ -240,6 +240,34 @@ describe("NumberInput", () => {
|
|||||||
|
|
||||||
expect(stepperButton).toBeNull();
|
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", () => {
|
describe("NumberInput with React Hook Form", () => {
|
||||||
@ -503,7 +531,6 @@ describe("NumberInput with React Hook Form", () => {
|
|||||||
|
|
||||||
await user.tab();
|
await user.tab();
|
||||||
await user.keyboard("1234");
|
await user.keyboard("1234");
|
||||||
await user.tab();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -136,7 +136,7 @@ export function useNumberInput(originalProps: UseNumberInputProps) {
|
|||||||
...originalProps,
|
...originalProps,
|
||||||
validationBehavior,
|
validationBehavior,
|
||||||
locale,
|
locale,
|
||||||
onChange: onValueChange,
|
onChange: chain(onValueChange, onChange),
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user