Skip to content

Commit 3ff3e82

Browse files
authored
Merge pull request #43 from kevinkuszyk/input-child-components
Allow `Input` component to render child components passed to it
2 parents bfae9b3 + 36bbda0 commit 3ff3e82

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/components/input/Input.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { HTMLProps } from 'react';
2-
import classNames from 'classnames';
2+
3+
import { FormElementProps } from '../../util/types/FormTypes';
34
import FormGroup from '../../util/FormGroup';
45
import { InputWidth } from '../../util/types/NHSUKTypes';
5-
import { FormElementProps } from '../../util/types/FormTypes';
6+
import classNames from 'classnames';
67

78
interface InputProps extends HTMLProps<HTMLInputElement>, FormElementProps {
89
inputRef?: (inputRef: HTMLInputElement | null) => any;
@@ -13,16 +14,19 @@ interface InputProps extends HTMLProps<HTMLInputElement>, FormElementProps {
1314
const Input: React.FC<InputProps> = props => (
1415
<FormGroup<InputProps> {...props} inputType="input">
1516
{({ width, className, error, inputRef, ...rest }) => (
16-
<input
17-
className={classNames(
18-
'nhsuk-input',
19-
{ [`nhsuk-input--width-${width}`]: width },
20-
{ 'nhsuk-input--error': error },
21-
className,
22-
)}
23-
ref={inputRef}
24-
{...rest}
25-
/>
17+
<>
18+
<input
19+
className={classNames(
20+
'nhsuk-input',
21+
{ [`nhsuk-input--width-${width}`]: width },
22+
{ 'nhsuk-input--error': error },
23+
className,
24+
)}
25+
ref={inputRef}
26+
{...rest}
27+
/>
28+
{props.children}
29+
</>
2630
)}
2731
</FormGroup>
2832
);

0 commit comments

Comments
 (0)