-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add beforeInput(s)
and afterInput(s)
options to form groups
#4567
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 819324f |
Other changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/components/character-count/macro-options.json b/packages/govuk-frontend/dist/govuk/components/character-count/macro-options.json
index a740bfcee..6a1fec053 100644
--- a/packages/govuk-frontend/dist/govuk/components/character-count/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/character-count/macro-options.json
@@ -79,6 +79,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before the textarea used by the character count component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before the textarea. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before the textarea. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after the textarea used by the character count component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after the textarea. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after the textarea. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
diff --git a/packages/govuk-frontend/dist/govuk/components/checkboxes/macro-options.json b/packages/govuk-frontend/dist/govuk/components/checkboxes/macro-options.json
index 8da436cb0..52020dc33 100644
--- a/packages/govuk-frontend/dist/govuk/components/checkboxes/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/checkboxes/macro-options.json
@@ -43,6 +43,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInputs",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before all checkbox items within the checkboxes component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before all checkbox items. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before all checkbox items. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInputs",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after all checkbox items within the checkboxes component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after all checkbox items. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after all checkbox items. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
diff --git a/packages/govuk-frontend/dist/govuk/components/date-input/macro-options.json b/packages/govuk-frontend/dist/govuk/components/date-input/macro-options.json
index 8b6545b9a..afa2fc013 100644
--- a/packages/govuk-frontend/dist/govuk/components/date-input/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/date-input/macro-options.json
@@ -98,6 +98,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInputs",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before the inputs used by the date input component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before the inputs. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before the inputs. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInputs",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after the inputs used by the date input component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after the inputs. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after the inputs. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
diff --git a/packages/govuk-frontend/dist/govuk/components/file-upload/macro-options.json b/packages/govuk-frontend/dist/govuk/components/file-upload/macro-options.json
index 6e51af747..5db62cb10 100644
--- a/packages/govuk-frontend/dist/govuk/components/file-upload/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/file-upload/macro-options.json
@@ -67,6 +67,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before the input used by the file upload component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before the input. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before the input. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after the input used by the file upload component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after the input. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after the input. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
diff --git a/packages/govuk-frontend/dist/govuk/components/input/macro-options.json b/packages/govuk-frontend/dist/govuk/components/input/macro-options.json
index 018f8d1dc..1d7e6b2f1 100644
--- a/packages/govuk-frontend/dist/govuk/components/input/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/input/macro-options.json
@@ -130,7 +130,7 @@
"name": "formGroup",
"type": "object",
"required": false,
- "description": "Additional options for the form group containing the text-input component.",
+ "description": "Additional options for the form group containing the text input component.",
"params": [
{
"name": "classes",
@@ -143,6 +143,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before the input used by the text input component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before the input. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before the input. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after the input used by the text input component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after the input. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after the input. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
diff --git a/packages/govuk-frontend/dist/govuk/components/radios/macro-options.json b/packages/govuk-frontend/dist/govuk/components/radios/macro-options.json
index 8af83b280..7c6cfe63e 100644
--- a/packages/govuk-frontend/dist/govuk/components/radios/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/radios/macro-options.json
@@ -37,6 +37,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInputs",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before all radio items within the checkboxes component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before all radio items. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before all radio items. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInputs",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after all radio items within the checkboxes component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after all radio items. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after all radio items. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
@@ -50,7 +90,7 @@
"name": "name",
"type": "string",
"required": true,
- "description": "Name attribute for all radio items."
+ "description": "Name attribute for the radio items."
},
{
"name": "items",
diff --git a/packages/govuk-frontend/dist/govuk/components/select/macro-options.json b/packages/govuk-frontend/dist/govuk/components/select/macro-options.json
index 838f05e26..0665b9479 100644
--- a/packages/govuk-frontend/dist/govuk/components/select/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/select/macro-options.json
@@ -105,6 +105,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before the select used by the select component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before the select. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before the select. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after the select used by the select component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after the select. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after the select. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
diff --git a/packages/govuk-frontend/dist/govuk/components/textarea/macro-options.json b/packages/govuk-frontend/dist/govuk/components/textarea/macro-options.json
index 16249f7bb..cfe637803 100644
--- a/packages/govuk-frontend/dist/govuk/components/textarea/macro-options.json
+++ b/packages/govuk-frontend/dist/govuk/components/textarea/macro-options.json
@@ -79,6 +79,46 @@
"type": "object",
"required": false,
"description": "HTML attributes (for example data attributes) to add to the form group."
+ },
+ {
+ "name": "beforeInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add before the textarea used by the textarea component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add before the textarea. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add before the textarea. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
+ },
+ {
+ "name": "afterInput",
+ "type": "object",
+ "required": false,
+ "description": "Content to add after the textarea used by the textarea component.",
+ "params": [
+ {
+ "name": "text",
+ "type": "string",
+ "required": true,
+ "description": "Text to add after the textarea. If `html` is provided, the `text` option will be ignored."
+ },
+ {
+ "name": "html",
+ "type": "string",
+ "required": true,
+ "description": "HTML to add after the textarea. If `html` is provided, the `text` option will be ignored."
+ }
+ ]
}
]
},
Action run for 819324f |
6fe8308
to
fb96852
Compare
Given recent discussions about the limitations of components that inherit other components (i.e. character count and EtP), I'm quite interested in this! I'm less sure how much benefit there is to doing it this universally, though. Being able to insert custom HTML after an input/before the form group closes seems like it will have some utility; but I can't really see much benefit in putting something at the start of the group before the label, hint and error message (or fieldset). I don't think doing that's a behaviour we'd expect, and having it as an option doesn't seem like it'd help users do anything they can't usually already do by putting their custom HTML prior to the form group and potentially futzing with margins. It feels like what we might actually want is the ability to inject HTML before and after the |
That's great @querkmachine To solve #1602 we only really need to add content after the So I'm open to narrowing it down and/or chuck me some ideas for renaming the options |
fb96852
to
413c8d4
Compare
413c8d4
to
77b9c13
Compare
I agree that this could solve #1602, but I don't think it's necessarily a fix for #924, and I'm also not sure there are many situations outside of #1602 where having these parameters available would facilitate solving a problem. For example, if I were wanting to add a icon before a text input, I wouldn't be able to do that here because This similarly wouldn't really help us solve other issues with nested components, like in the password input we're currently developing. Code-wise I don't really see anything harmful with having the options, I just also don't see much use in them when compared to something akin to a Would be interested in having this shopped around to other devs for their thoughts. |
77b9c13
to
71933c7
Compare
@querkmachine Using Perhaps as an object with Your suggestion would work identically for Character count's |
a6d8ceb
to
e56ea8f
Compare
e56ea8f
to
9bb05d1
Compare
beforeHtml
and afterHtml
options to form groupsbeforeInput
and afterInput
options to form groups
beforeInput
and afterInput
options to form groupsbeforeInput(s)
and afterInput(s)
options to form groups
6cf96c1
to
077eb3c
Compare
077eb3c
to
2f58f11
Compare
2f58f11
to
819324f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all looking sensible to me. Should be a very useful thing to have!
This PR adds support for Nunjucks before/after content within components
It supports various improvements (see below) to new and existing patterns, for example:
Nunjucks before/after content
Nunjucks before/after options have also been varied for components with single or multiple fields:
Components with single form field
Use options
beforeInput
andafterInput
for components with a single fieldComponents with single form field
Use options
beforeInputs
andafterInputs
for components with multiple fields☝️ Note that Password input will have an input + button combo, is the option name still suitable?
I picked "input" for all form controls (input, select, textarea) as we do with Error summary
$input
All options considered might be:
beforeInput
/afterInput
beforeControl
/afterControl
beforeField
/afterField
Supporting other improvements
This work is based on a fix suggested by @36degrees in #1602 (comment) to solve these issues:
It is a supporting change to enable "components within components" as used by:
formGroup
as module wrapper #4566