Skip to content

Commit 0de5a39

Browse files
author
Luke Pearson
authored
Merge pull request #30 from NHSDigital/fix/remove-wrapper-from-form
Allow passing formGroupProps and remove wrapper classes
2 parents b078483 + bad4655 commit 0de5a39

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/components/form/Form.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React, { HTMLProps } from 'react';
2-
import classNames from 'classnames';
32
import FormContext from './FormContext';
43

54
type FormProps = HTMLProps<HTMLFormElement> & {
65
disableErrorFromComponents?: boolean;
76
};
87

9-
const Form: React.FC<FormProps> = ({ className, disableErrorFromComponents, ...rest }) => (
8+
const Form: React.FC<FormProps> = ({ disableErrorFromComponents, ...rest }) => (
109
<FormContext.Provider value={{ disableErrorFromComponents: Boolean(disableErrorFromComponents) }}>
11-
<form className={classNames('nhsuk-form-group--wrapper', className)} {...rest} />
10+
<form {...rest} />
1211
</FormContext.Provider>
1312
);
1413

src/util/FormGroup.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const FormGroup = <T extends BaseFormElementRenderProps>(props: FormGroupProps<T
4343
error,
4444
hintProps,
4545
errorProps,
46+
formGroupProps,
4647
inputType,
4748
disableErrorLine,
4849
name,
@@ -79,11 +80,18 @@ const FormGroup = <T extends BaseFormElementRenderProps>(props: FormGroupProps<T
7980
return () => registerComponent(elementID, true);
8081
}, []);
8182

83+
const { className: formGroupClassName, ...formGroupRestProps } = formGroupProps || {};
84+
8285
return (
8386
<div
84-
className={classNames('nhsuk-form-group', {
85-
'nhsuk-form-group--error': !disableErrorFromComponents && !disableErrorLine && error,
86-
})}
87+
className={classNames(
88+
'nhsuk-form-group',
89+
{
90+
'nhsuk-form-group--error': !disableErrorFromComponents && !disableErrorLine && error,
91+
},
92+
formGroupClassName,
93+
)}
94+
{...formGroupRestProps}
8795
>
8896
{label ? (
8997
<Label id={labelID} htmlFor={elementID} {...labelProps}>

src/util/types/FormTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HTMLProps } from 'react';
12
import { ErrorMessageProps } from '../../components/error-message/ErrorMessage';
23
import { HintProps } from '../../components/hint/Hint';
34
import { LabelProps } from '../../components/label/Label';
@@ -9,6 +10,7 @@ export interface FormElementProps {
910
errorProps?: ErrorMessageProps;
1011
hint?: string;
1112
hintProps?: HintProps;
13+
formGroupProps?: HTMLProps<HTMLDivElement>;
1214
disableErrorLine?: boolean;
1315
id?: string;
1416
name?: string;

0 commit comments

Comments
 (0)