WIP: Allow Input component to render child components passed to it#35
WIP: Allow Input component to render child components passed to it#35kevinkuszyk wants to merge 1 commit intoNHSDigital:masterfrom
Input component to render child components passed to it#35Conversation
|
I think the issue here is more around allowing components to be passed inside of the |
|
@Tomdango that was actually my starting point, but I hit two snags:
Are you thinking something like this might work better: |
|
The annoying bit is the way that the FormGroup works - it's not just a wrapper for |
Yes, I spotted that. Do you think it's ripe for a refactor to make the usage more like the example I posted earlier?
Yes, this is the good stuff I didn't want to lose.
I'm not sure about this, as it feels like a workaround on how the component is built, rather than doing it the react way? Do you know the background as to why it takes a function, rather than child components in the usual react way? As you know, I'm new to react, but I think we should aim for something that is as simple a possible for consumers and follows the usual react patterns for composition etc. Thoughts? |
When any Form component is used, all of the props are passed to the I think we could go in the middle here: We could implement a new 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>
);Which would output something along the lines of: <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>This seems like how this should work - we don't lose any functionality when not using a FormGroup directly (IDs should still pass through etc) - and the Input will still be wrapped in the |
|
@Tomdango that sounds perfect - to consumers it's a standard react, but inside we get all the accessibility benefits etc. @SatnamSinghUK how do you feel about implementing this? I'm guessing we're going to need to apply this refactor to all the form components in one go? |
|
@Tomdango That looks like the way to go with this @kevinkuszyk Yep, let's start to pull it into our elaboration/sprints sessions |
|
@Tomdango we have some feature work which is ahead of this on our priority list, so it might be a sprint or two before we get to this. |
@Tomdango as you know from discussions with @SatnamSinghUK we have a requirement to render input boxes with a hyperlink underneath, all inside a form group. Something like this:
I had a stab this afternoon at enabling the
Inputcomponent to take child components. The usage is something like this:It's quick and dirty, but it enables us to hit a deadline this week. Unfortunately, it also has a number of issues, not least, I'm not sure how accessible it will be.
So, would you accept this contribution as is?
If no, are you ok with this approach, but would like some changes (like tests?)?, or would you prefer if we went down the route you and @SatnamSinghUK have discussed? Something more like this: