Skip to content

Expose FormGroup component to consumers #71

@kevinkuszyk

Description

@kevinkuszyk

Following on from the discussion in #35, this issue is to clarify our intent for this.

We would like to expose a FormGroup component so that it can be used by library consumers, so that all the boiler plate and logic for error styles, hint text etc can be encapsulated and easily reused. This will help us in Forms so that we can focus on our custom components and not repeat all the boiler plate.

There is some complexity here as the existing FormGroup component was not designed to be exposed and it accepts a function instead of child components in the usual way.

The goal is to have syntax like this:

import React from "react";
import { FormGroup, Input } from "nhsuk-react-components";

const ExampleUsage = () => (
    <FormGroup>
        <Input hint="Test Hint" label="Test Label" />
        <a href="/somewhere-else">Don't have a number?</a>
    </FormGroup>
);

Emit something like this:

<div class="nhsuk-form-group">
    <label class="nhsuk-label">Test Label</label>
    <span class="nhsuk-hint">Test Hint</span>
    <input />
    <a href="/somewhere-else">Don't have a number?</a>
</div>

The new / exposed FormGroup should support at least the following props (and associated functionality):

  1. hint
  2. label
  3. error

Questions

  1. Should we also support disableErrorLine?
  2. What else is included with labelProps, hintProps, errorProps and formGroupProps, and should we support them?

Fyi. Forms team, we're tracking this in Jira as WBFCD-399.


@Tomdango anything else to add?

@ramyas16 ping

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions