Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `12.1.0`.
**Bug fixes**
- Added requirement that `EuiFormRow` has exactly one child element [#2054](https://github.com/elastic/eui/pull/2054)

## [`12.1.0`](https://github.com/elastic/eui/tree/v12.1.0)

Expand Down
6 changes: 3 additions & 3 deletions src/components/form/form_row/form_row.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement, Component } from 'react';
import React, { cloneElement, Component, Children } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

Expand Down Expand Up @@ -155,7 +155,7 @@ export class EuiFormRow extends Component {
optionalProps['aria-describedby'] = describingIds.join(' ');
}

let field = cloneElement(children, {
let field = cloneElement(Children.only(children), {
id,
onFocus: this.onFocus,
onBlur: this.onBlur,
Expand Down Expand Up @@ -186,7 +186,7 @@ export class EuiFormRow extends Component {
}

EuiFormRow.propTypes = {
children: PropTypes.node.isRequired,
children: PropTypes.element.isRequired,
className: PropTypes.string,
label: PropTypes.node,
/**
Expand Down
13 changes: 13 additions & 0 deletions src/components/form/form_row/form_row.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ describe('EuiFormRow', () => {
expect(component).toMatchSnapshot();
});

test('no children is an error', () => {
expect(() => <EuiFormRow {...requiredProps} />).toThrow();
});

test('two children is an error', () => {
expect(() => (
<EuiFormRow {...requiredProps}>
<div />
<div />
</EuiFormRow>
)).toThrow();
});

test('ties together parts for accessibility', () => {
const props = {
label: 'Label',
Expand Down
11 changes: 9 additions & 2 deletions src/components/form/form_row/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { CommonProps, ExclusiveUnion } from '../../common';

import { FunctionComponent, ReactNode, HTMLAttributes } from 'react';
import {
FunctionComponent,
ReactNode,
ReactElement,
HTMLAttributes,
} from 'react';

declare module '@elastic/eui' {
/**
Expand Down Expand Up @@ -29,7 +34,9 @@ declare module '@elastic/eui' {
} & EuiFormRowCommonProps &
HTMLAttributes<HTMLFieldSetElement>;

export type EuiFormRowProps = ExclusiveUnion<LabelProps, LegendProps>;
export type EuiFormRowProps = ExclusiveUnion<LabelProps, LegendProps> & {
children: ReactElement;
};

export const EuiFormRow: FunctionComponent<EuiFormRowProps>;
}