diff --git a/src/components/Input/Input.mdx b/src/components/Input/Input.mdx index ed97fb5f..11019fb0 100644 --- a/src/components/Input/Input.mdx +++ b/src/components/Input/Input.mdx @@ -58,10 +58,10 @@ A Input can be used to let the user insert text using key strokes. A crucial for } ``` -### Error message +### Input with error - + ### Format a serial code diff --git a/src/components/Input/Input.test.tsx b/src/components/Input/Input.test.tsx index 4769a60c..a54a6ca4 100644 --- a/src/components/Input/Input.test.tsx +++ b/src/components/Input/Input.test.tsx @@ -53,14 +53,11 @@ describe('Input', () => { }); test('errorMessage prop', () => { - const errorMessage = 'This is an error message'; - const component = ; - const { getByTestId, queryByText } = render(component); + const component = ; + const { getByTestId } = render(component); const inputElement = getByTestId('input-firstname'); - const spanElement = queryByText(errorMessage); expect(inputElement.classList).toContain('containsError'); - expect(spanElement).not.toEqual(null); }); test('spellCheck prop', () => { diff --git a/src/components/Input/Input.tsx b/src/components/Input/Input.tsx index 735073bd..d99dc564 100644 --- a/src/components/Input/Input.tsx +++ b/src/components/Input/Input.tsx @@ -1,4 +1,4 @@ -import React, { ChangeEventHandler } from 'react'; +import React, { ChangeEventHandler, FocusEventHandler } from 'react'; import classNames from 'classnames'; import styles from './Input.module.css'; @@ -7,6 +7,7 @@ interface Props { name: string; value?: string; onChange?: ChangeEventHandler; + onBlur?: FocusEventHandler; placeholder?: string; type?: 'text' | 'email' | 'password'; errorMessage?: string; @@ -14,6 +15,7 @@ interface Props { autoComplete?: boolean; maxLength?: number; className?: string; + isInvalid?: boolean; } const Input = React.forwardRef( @@ -22,9 +24,10 @@ const Input = React.forwardRef( name, value, onChange, + onBlur, placeholder, type = 'text', - errorMessage, + isInvalid = false, spellCheck = false, autoComplete = false, maxLength, @@ -34,7 +37,7 @@ const Input = React.forwardRef( ) => { const mergedContainerClassName = classNames(styles.container, className); const mergedInputClassName = classNames(styles.input, { - [styles.containsError]: Boolean(errorMessage), + [styles.containsError]: Boolean(isInvalid), }); return (
@@ -50,8 +53,8 @@ const Input = React.forwardRef( ref={ref} className={mergedInputClassName} data-testid={`input-${name}`} + onBlur={onBlur} /> - {Boolean(errorMessage) && {errorMessage}}
); },