diff --git a/cypress/integration/create.js b/cypress/integration/create.js index 85c58d947f9..cc89b084ddd 100644 --- a/cypress/integration/create.js +++ b/cypress/integration/create.js @@ -249,7 +249,7 @@ describe('Create Page', () => { }); it('should not show rich text input error message when field is untouched', () => { - cy.get(CreatePage.elements.richTextInputError).should('not.exist'); + cy.get(CreatePage.elements.richTextInputError).should('not.have.value'); }); it('should show rich text input error message when form is submitted', () => { diff --git a/examples/demo/src/ra-input-rich-text.d.ts b/examples/demo/src/ra-input-rich-text.d.ts new file mode 100644 index 00000000000..e9040f114c8 --- /dev/null +++ b/examples/demo/src/ra-input-rich-text.d.ts @@ -0,0 +1 @@ +declare module 'ra-input-rich-text'; diff --git a/packages/ra-input-rich-text/src/index.js b/packages/ra-input-rich-text/src/index.js index 1b1fd2cdf6a..86a258ca1bd 100644 --- a/packages/ra-input-rich-text/src/index.js +++ b/packages/ra-input-rich-text/src/index.js @@ -107,18 +107,16 @@ const RichTextInput = ({ )}
- {helperText || (touched && error) ? ( - - - - ) : null} + + + ); }; diff --git a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx index 53bf59a65f2..009fa9aa166 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx @@ -418,13 +418,11 @@ const AutocompleteArrayInput: FunctionComponent< htmlFor: id, })} helperText={ - (touched && error) || helperText ? ( - - ) : null + } variant={variant} margin={margin} diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx index 4e3aa86e085..3dd44d88c29 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx @@ -362,13 +362,11 @@ const AutocompleteInput: FunctionComponent< htmlFor: id, })} helperText={ - (touched && error) || helperText ? ( - - ) : null + } variant={variant} margin={margin} diff --git a/packages/ra-ui-materialui/src/input/BooleanInput.tsx b/packages/ra-ui-materialui/src/input/BooleanInput.tsx index 4dddd6862df..7ab4832e50c 100644 --- a/packages/ra-ui-materialui/src/input/BooleanInput.tsx +++ b/packages/ra-ui-materialui/src/input/BooleanInput.tsx @@ -74,15 +74,13 @@ const BooleanInput: FunctionComponent< /> } /> - {(touched && error) || helperText ? ( - - - - ) : null} + + + ); }; diff --git a/packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx b/packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx index 84e3c237f2a..eb8fcc72c54 100644 --- a/packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx +++ b/packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx @@ -147,7 +147,7 @@ describe('', () => { render={() => ( } + optionText={} choices={[{ id: 'foo', foobar: 'Bar' }]} /> )} @@ -223,17 +223,17 @@ describe('', () => { render={() => } /> ); - expect(container.querySelector('p')).toBeNull(); + expect(container.querySelector('p').innerHTML).toBe(' '); }); - it('should not be displayed if field has been touched but is valid', () => { + it('should be empty if field has been touched but is valid', () => { const { container } = render(
} /> ); - expect(container.querySelector('p')).toBeNull(); + expect(container.querySelector('p').innerHTML).toBe(' '); }); it('should be displayed if field has been touched and is invalid', () => { diff --git a/packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx b/packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx index fab7faa9248..196d4f43f93 100644 --- a/packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx +++ b/packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx @@ -187,15 +187,13 @@ const CheckboxGroupInput: FunctionComponent< /> ))} - {(touched && error) || helperText ? ( - - - - ) : null} + + + ); }; diff --git a/packages/ra-ui-materialui/src/input/DateInput.tsx b/packages/ra-ui-materialui/src/input/DateInput.tsx index be1ba1d2091..e60d016d99b 100644 --- a/packages/ra-ui-materialui/src/input/DateInput.tsx +++ b/packages/ra-ui-materialui/src/input/DateInput.tsx @@ -86,13 +86,11 @@ export const DateInput: FunctionComponent< type="date" error={!!(touched && error)} helperText={ - (touched && error) || helperText ? ( - - ) : null + } label={ - ) : null + } label={ )} - {(touched && error) || helperText ? ( - - - - ) : null} + + + ); diff --git a/packages/ra-ui-materialui/src/input/InputHelperText.spec.tsx b/packages/ra-ui-materialui/src/input/InputHelperText.spec.tsx index b56587128d6..5b7377c3cf8 100644 --- a/packages/ra-ui-materialui/src/input/InputHelperText.spec.tsx +++ b/packages/ra-ui-materialui/src/input/InputHelperText.spec.tsx @@ -6,11 +6,11 @@ import InputHelperText from './InputHelperText'; describe('InputHelperText', () => { afterEach(cleanup); - it('does not render anything when the input has not been touched yet and has no helper text', () => { + it('does render empty string when the input has not been touched yet and has no helper text', () => { const { container } = render( ); - expect(container.innerHTML).toBe(''); + expect(container.innerHTML).toBe(' '); }); it('renders the helperText when there is no error', () => { diff --git a/packages/ra-ui-materialui/src/input/InputHelperText.tsx b/packages/ra-ui-materialui/src/input/InputHelperText.tsx index 97598e8f847..c098bc6ed16 100644 --- a/packages/ra-ui-materialui/src/input/InputHelperText.tsx +++ b/packages/ra-ui-materialui/src/input/InputHelperText.tsx @@ -18,7 +18,9 @@ const InputHelperText: FunctionComponent = ({ ) : helperText ? ( <>{translate(helperText, { _: helperText })} - ) : null; + ) : ( + <> + ); }; export default InputHelperText; diff --git a/packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx b/packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx index b9232fa0e46..0971418ebe7 100644 --- a/packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx +++ b/packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx @@ -82,13 +82,11 @@ const NullableBooleanInput: FunctionComponent< } error={!!(touched && error)} helperText={ - (touched && error) || helperText ? ( - - ) : null + } className={classnames(classes.input, className)} variant={variant} diff --git a/packages/ra-ui-materialui/src/input/NumberInput.tsx b/packages/ra-ui-materialui/src/input/NumberInput.tsx index ffc3f5cf260..578851feee0 100644 --- a/packages/ra-ui-materialui/src/input/NumberInput.tsx +++ b/packages/ra-ui-materialui/src/input/NumberInput.tsx @@ -77,13 +77,11 @@ const NumberInput: FunctionComponent< variant={variant} error={!!(touched && error)} helperText={ - (touched && error) || helperText ? ( - - ) : null + } label={ ))} - {(touched && error) || helperText ? ( - - - - ) : null} + + + ); }; diff --git a/packages/ra-ui-materialui/src/input/TextInput.tsx b/packages/ra-ui-materialui/src/input/TextInput.tsx index 00ff175e1c0..61dbe92e008 100644 --- a/packages/ra-ui-materialui/src/input/TextInput.tsx +++ b/packages/ra-ui-materialui/src/input/TextInput.tsx @@ -73,13 +73,11 @@ export const TextInput: FunctionComponent = ({ } error={!!(touched && error)} helperText={ - (touched && error) || helperText ? ( - - ) : null + } {...options} {...sanitizeRestProps(rest)}