Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `21.0.0`.
- Added a renderForm prop to `EuiForm` to render a `<form>`([#3010](https://github.com/elastic/eui/pull/3010))
Comment thread
anishagg17 marked this conversation as resolved.
Outdated

## [`21.0.0`](https://github.com/elastic/eui/tree/v21.0.0)

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/form_layouts/form_rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class extends Component {

render() {
return (
<EuiForm>
<EuiForm component="form">
Comment thread
anishagg17 marked this conversation as resolved.
<EuiFormRow label="Text field" helpText="I am some friendly help text.">
<EuiFieldText name="first" />
</EuiFormRow>
Expand Down
8 changes: 8 additions & 0 deletions src/components/form/__snapshots__/form.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ exports[`EuiForm is rendered 1`] = `
data-test-subj="test subject string"
/>
`;

exports[`EuiForm renders <form > 1`] = `
<form
aria-label="aria-label"
class="euiForm testClass1 testClass2"
data-test-subj="test subject string"
/>
`;
6 changes: 6 additions & 0 deletions src/components/form/form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ describe('EuiForm', () => {

expect(component).toMatchSnapshot();
});

test('renders <form >', () => {
Comment thread
anishagg17 marked this conversation as resolved.
Outdated
const component = render(<EuiForm {...requiredProps} component="form" />);

expect(component).toMatchSnapshot();
});
});
30 changes: 27 additions & 3 deletions src/components/form/form.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import React, { FunctionComponent, ReactNode, HTMLAttributes } from 'react';
import React, {
FunctionComponent,
ReactNode,
HTMLAttributes,
FormEvent,
} from 'react';
import classNames from 'classnames';
import { EuiCallOut } from '../call_out';
import { EuiI18n } from '../i18n';
import { CommonProps } from '../common';

export type EuiFormProps = CommonProps &
HTMLAttributes<HTMLFormElement> &
HTMLAttributes<HTMLDivElement> & {
Comment thread
anishagg17 marked this conversation as resolved.
Outdated
isInvalid?: boolean;
/**
* Renders From element
Comment thread
anishagg17 marked this conversation as resolved.
Outdated
*/
component?: 'form' | 'div';
error?: ReactNode | ReactNode[];
};

Expand All @@ -15,6 +25,8 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
className,
isInvalid,
error,
component = 'div',
onSubmit,
Comment thread
anishagg17 marked this conversation as resolved.
Outdated
...rest
}) => {
const classes = classNames('euiForm', className);
Expand Down Expand Up @@ -53,10 +65,22 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
);
}

const relObj: {
onSubmit?:
| (((event: FormEvent<HTMLFormElement>) => void) &
((event: FormEvent<HTMLDivElement>) => void))
| undefined;
} = {};

if (component === 'form') {
relObj.onSubmit = onSubmit;
}
Comment thread
anishagg17 marked this conversation as resolved.
Outdated
const Element = component;

return (
<div className={classes} {...rest}>
<Element className={classes} {...relObj} {...rest}>
{optionalErrorAlert}
{children}
</div>
</Element>
);
};