diff --git a/packages/react/lib/TextField/index.js b/packages/react/lib/TextField/index.js index 996e1128d..6094950f1 100644 --- a/packages/react/lib/TextField/index.js +++ b/packages/react/lib/TextField/index.js @@ -127,7 +127,6 @@ const TextField = forwardRef(({ )} > inputRef.current?.blur()} + { ...rest } /> { children } diff --git a/packages/react/lib/TextField/index.stories.js b/packages/react/lib/TextField/index.stories.js index 94f5d69b1..d5840f0cb 100644 --- a/packages/react/lib/TextField/index.stories.js +++ b/packages/react/lib/TextField/index.stories.js @@ -50,3 +50,22 @@ export const withValidation = () => ( onValidate={val => /^[0-9]+$/g.test(val)} /> ); + +export const typeNumber = () => ( + +); + +export const withOnWheelOverrided = () => ( + +); diff --git a/packages/react/lib/TextField/index.test.js b/packages/react/lib/TextField/index.test.js index ca088f203..804910ce9 100644 --- a/packages/react/lib/TextField/index.test.js +++ b/packages/react/lib/TextField/index.test.js @@ -1,5 +1,5 @@ import { createRef } from 'react'; -import { render } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { blur, reset } from '~test-utils'; @@ -94,4 +94,36 @@ describe('', () => { expect(container).toMatchSnapshot(); unmount(); }); + + it('should blur on scroll', async () => { + const user = userEvent.setup(); + const { unmount, container } = render(); + + const input = container.querySelector('input'); + await user.click(input); + expect(container).toMatchSnapshot('focused'); + fireEvent.wheel(container.querySelector('.junipero.text-field input'), { + deltaY: 30, + }); + expect(container).toMatchSnapshot('unfocused'); + unmount(); + }); + + it('should do the given action on scroll if onWheel is set', async () => { + const user = userEvent.setup(); + const customWheel = jest.fn(); + const { unmount, container } = render( + + ); + + const input = container.querySelector('input'); + await user.click(input); + expect(container).toMatchSnapshot('focused'); + fireEvent.wheel(container.querySelector('.junipero.text-field input'), { + deltaY: 30, + }); + expect(customWheel).toHaveBeenCalled(); + expect(container).toMatchSnapshot('always focused'); + unmount(); + }); }); diff --git a/packages/react/lib/TextField/index.test.js.snap b/packages/react/lib/TextField/index.test.js.snap index c37e7923a..c159117a7 100644 --- a/packages/react/lib/TextField/index.test.js.snap +++ b/packages/react/lib/TextField/index.test.js.snap @@ -70,6 +70,62 @@ exports[` should be invalid if validation fails 1`] = ` `; +exports[` should blur on scroll: focused 1`] = ` +
+
+ +
+
+`; + +exports[` should blur on scroll: unfocused 1`] = ` +
+
+ +
+
+`; + +exports[` should do the given action on scroll if onWheel is set: always focused 1`] = ` +
+
+ +
+
+`; + +exports[` should do the given action on scroll if onWheel is set: focused 1`] = ` +
+
+ +
+
+`; + exports[` should not allow to change value when disabled 1`] = `