File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ const Input = forwardRef(
9090 onBlur ?. ( e ) ;
9191 } ;
9292
93+ const handleOnWheel = e => {
94+ if ( type === "number" ) e . target . blur ( ) ;
95+ } ;
96+
9397 const dataCyLabel =
9498 typeof label === "string" ? hyphenize ( label ) : hyphenize ( dataCy ) ;
9599
@@ -148,6 +152,7 @@ const Input = forwardRef(
148152 } }
149153 onBlur = { handleOnBlur }
150154 onChange = { handleChange }
155+ onWheel = { handleOnWheel }
151156 />
152157 { suffix && < div className = "neeto-ui-input__suffix" > { suffix } </ div > }
153158 </ div >
Original file line number Diff line number Diff line change @@ -197,4 +197,32 @@ describe("Input", () => {
197197 rerender ( < Input label = "label" value = { 45.677 } /> ) ;
198198 expect ( input ) . toHaveValue ( "45.677" ) ;
199199 } ) ;
200+
201+ it ( "should prevent wheel scrolling on number input fields" , ( ) => {
202+ const { getByLabelText } = render (
203+ < Input label = "Number Input" type = "number" />
204+ ) ;
205+ const input = getByLabelText ( "Number Input" ) ;
206+
207+ const wheelEvent = new Event ( "wheel" , { bubbles : true } ) ;
208+ const blurSpy = jest . spyOn ( input , "blur" ) ;
209+
210+ input . dispatchEvent ( wheelEvent ) ;
211+
212+ expect ( blurSpy ) . toHaveBeenCalled ( ) ;
213+ blurSpy . mockRestore ( ) ;
214+ } ) ;
215+
216+ it ( "should not prevent wheel scrolling on non-number input fields" , ( ) => {
217+ const { getByLabelText } = render ( < Input label = "Text Input" type = "text" /> ) ;
218+ const input = getByLabelText ( "Text Input" ) ;
219+
220+ const wheelEvent = new WheelEvent ( "wheel" , { deltaY : 1 } ) ;
221+ const blurSpy = jest . spyOn ( input , "blur" ) ;
222+
223+ input . dispatchEvent ( wheelEvent ) ;
224+
225+ expect ( blurSpy ) . not . toHaveBeenCalled ( ) ;
226+ blurSpy . mockRestore ( ) ;
227+ } ) ;
200228} ) ;
You can’t perform that action at this time.
0 commit comments