Skip to content

Commit 3b6bd40

Browse files
authored
[EuiForm] Added invalidCallout prop to allow conditional rendering of error callout (#3585)
Fixes #478
1 parent e0f79ff commit 3b6bd40

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
## [`25.0.0`](https://github.com/elastic/eui/tree/v25.0.0)
3030

3131
- Added conditional rendering of the title element in `EuiCallOut` to avoid usage of additional space caused by the rendered `<div>` element ([#3549](https://github.com/elastic/eui/pull/3549))
32+
- Added `invalidCallout` prop to `EuiForm` to allow conditional rendering of error callout([#3585](https://github.com/elastic/eui/pull/3585))
3233

3334
**Bug fixes**
3435

src-docs/src/views/form_validation/form_validation_example.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export const FormValidationExample = {
2626
Validation is achieved by applying <EuiCode>isInvalid</EuiCode> and
2727
optionally error props onto the <strong>EuiForm</strong> or{' '}
2828
<strong>EuiFormRow</strong> components. Errors are optional and are
29-
passed as an array in case you need to list many errors.
29+
passed as an array in case you need to list more than one. You can
30+
also hide the callout by passing
31+
<EuiCode>invalidCallout=&ldquo;none&ldquo;</EuiCode>
3032
</p>
3133
),
3234
source: [

src/components/form/__snapshots__/form.test.tsx.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ exports[`EuiForm renders a form element 1`] = `
1515
data-test-subj="test subject string"
1616
/>
1717
`;
18+
19+
exports[`EuiForm renders without error callout when invalidCallout is "none" 1`] = `
20+
<div
21+
aria-label="aria-label"
22+
class="euiForm testClass1 testClass2"
23+
data-test-subj="test subject string"
24+
/>
25+
`;

src/components/form/form.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ describe('EuiForm', () => {
3333
test('renders a form element', () => {
3434
const component = render(<EuiForm {...requiredProps} component="form" />);
3535

36+
expect(component).toMatchSnapshot();
37+
});
38+
test('renders without error callout when invalidCallout is "none"', () => {
39+
const component = render(
40+
<EuiForm {...requiredProps} isInvalid invalidCallout="none" />
41+
);
42+
3643
expect(component).toMatchSnapshot();
3744
});
3845
});

src/components/form/form.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export type EuiFormProps = CommonProps &
3939
*/
4040
component?: 'form' | 'div';
4141
error?: ReactNode | ReactNode[];
42+
/**
43+
* Where to display the callout with the list of errors
44+
*/
45+
invalidCallout?: 'above' | 'none';
4246
};
4347

4448
export const EuiForm: FunctionComponent<EuiFormProps> = ({
@@ -47,6 +51,7 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
4751
isInvalid,
4852
error,
4953
component = 'div',
54+
invalidCallout = 'above',
5055
...rest
5156
}) => {
5257
const classes = classNames('euiForm', className);
@@ -68,11 +73,11 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
6873

6974
let optionalErrorAlert;
7075

71-
if (isInvalid) {
76+
if (isInvalid && invalidCallout === 'above') {
7277
optionalErrorAlert = (
7378
<EuiI18n
7479
token="euiForm.addressFormErrors"
75-
default="Please address the errors in your form.">
80+
default="Please address the highlighted errors.">
7681
{(addressFormErrors: string) => (
7782
<EuiCallOut
7883
className="euiForm__errors"

0 commit comments

Comments
 (0)