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 src/components/Input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const Input = forwardRef(
onBlur?.(e);
};

const handleOnWheel = e => {
if (type === "number") e.target.blur();
};

const dataCyLabel =
typeof label === "string" ? hyphenize(label) : hyphenize(dataCy);

Expand Down Expand Up @@ -148,6 +152,7 @@ const Input = forwardRef(
}}
onBlur={handleOnBlur}
onChange={handleChange}
onWheel={handleOnWheel}
/>
{suffix && <div className="neeto-ui-input__suffix">{suffix}</div>}
</div>
Expand Down
28 changes: 28 additions & 0 deletions tests/Input.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,32 @@ describe("Input", () => {
rerender(<Input label="label" value={45.677} />);
expect(input).toHaveValue("45.677");
});

it("should prevent wheel scrolling on number input fields", () => {
const { getByLabelText } = render(
<Input label="Number Input" type="number" />
);
const input = getByLabelText("Number Input");

const wheelEvent = new Event("wheel", { bubbles: true });
const blurSpy = jest.spyOn(input, "blur");

input.dispatchEvent(wheelEvent);

expect(blurSpy).toHaveBeenCalled();
blurSpy.mockRestore();
});

it("should not prevent wheel scrolling on non-number input fields", () => {
const { getByLabelText } = render(<Input label="Text Input" type="text" />);
const input = getByLabelText("Text Input");

const wheelEvent = new Event("wheel", { bubbles: true });
const blurSpy = jest.spyOn(input, "blur");

input.dispatchEvent(wheelEvent);

expect(blurSpy).not.toHaveBeenCalled();
blurSpy.mockRestore();
});
});
Loading