Skip to content

Commit

Permalink
Add variant for radios with a textarea (#3148)
Browse files Browse the repository at this point in the history
* add variant for radios

* update macro.md file

* fix formatting

* Update src/components/radios/_macro.njk

Co-authored-by: rmccar <42928680+rmccar@users.noreply.github.com>

---------

Co-authored-by: rmccar <42928680+rmccar@users.noreply.github.com>
Co-authored-by: Alessio Venturini <112873190+alessioventuriniAND@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 17, 2024
1 parent 955a74a commit 4f0ae95
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions src/components/radios/_macro-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

## Radio

| Name | Type | Required | Description |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id | string | true | The HTML `id` of the radio. Used for the label’s `for` attribute. |
| value | string | false | The HTML `value` attribute for the radio to set a preset value for the input |
| classes | string | false | Classes to add to the radio |
| checked | boolean | false | Set to “true” to select the radio when the page loads |
| label | `Label` [_(ref)_](/components/label) | true | Settings for the radio label |
| other | object`<OtherRadio>` with arrays if using `Select` [_(ref)_](/components/select), `Checkboxes` [_(ref)_](/components/checkboxes) or `Radios` [_(ref)_](/components/radios) | false | Settings for a nested [input](/components/input), [select](/components/select), [checkboxes](/components/checkboxes) or [radios](/components/radios) to provide [other information](#otherradio) in addition to the radio answer. Defaults to use input. |
| attributes | object | false | HTML attributes (for example, data attributes) to add to the radio input element |
| Name | Type | Required | Description |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| id | string | true | The HTML `id` of the radio. Used for the label’s `for` attribute. |
| value | string | false | The HTML `value` attribute for the radio to set a preset value for the input |
| classes | string | false | Classes to add to the radio |
| checked | boolean | false | Set to “true” to select the radio when the page loads |
| label | `Label` [_(ref)_](/components/label) | true | Settings for the radio label |
| other | object`<OtherRadio>` with arrays if using `Select` [_(ref)_](/components/select), `Checkboxes` [_(ref)_](/components/checkboxes) or `Radios` [_(ref)_](/components/radios) | false | Settings for a nested [input](/components/input), [select](/components/select), [checkboxes](/components/checkboxes), [radios](/components/radios) or [textarea](/components/textarea) to provide [other information](#otherradio) in addition to the radio answer. Defaults to use input. |
| attributes | object | false | HTML attributes (for example, data attributes) to add to the radio input element |

## OtherRadio

Expand All @@ -39,7 +39,7 @@
| width | string | false | Required width of the nested text input in number of letters or digits. Will also accept a breakpoint suffix, for example, “7@m”. Defaults to “auto”. |
| type | string | false | Sets the HTML `type` attribute for the nested `<input>`. Can be set to either: “number”, “email”, “tel”, “password”, or “search”. Defaults to “text”. |
| inputClasses | string | false | Classes to apply to the radio input element |
| otherType | string | false (unless alternative input used) | Set the type of nested input if not using default text input, using available types: “select”, “checkboxes” or “radios”. |
| otherType | string | false (unless alternative input used) | Set the type of nested input if not using default text input, using available types: “select”, “checkboxes”, “radios” or “textarea”. |
| open | boolean | false | Set to “true” to show the nested `other` input when page loads |
| selectAllChildren | boolean | false | Set to “true” when using `otherType` set to “checkboxes” to show all nested checkboxes pre-selected |
| attributes | object | false | HTML attributes (for example, data attributes) to add to the nested input |
Expand Down
19 changes: 19 additions & 0 deletions src/components/radios/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@
"radios": radio.other.radios
})
}}
{% elif otherType == "textarea" %}
{% from "components/textarea/_macro.njk" import onsTextarea %}
{{
onsTextarea({
"id": radio.other.id,
"name": radio.other.name,
"label": {
"id": radio.other.id + "-label",
"text": radio.other.label.text,
"classes": 'ons-u-fw-n',
"description": radio.other.label.description
},
"charCheckLimit": {
"limit": radio.other.charCheckLimit.limit,
"charCountSingular": radio.other.charCheckLimit.charCountSingular,
"charCountPlural": radio.other.charCheckLimit.charCountPlural
}
})
}}
{% endif %}
</span>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{% from "components/radios/_macro.njk" import onsRadios %}
{% from "components/question/_macro.njk" import onsQuestion %}

{% call onsQuestion({
"title": "How do you usually travel to work?",
"classes": "ons-u-mt-no",
"legendIsQuestionTitle": true
}) %}
{{
onsRadios({
"dontWrap": true,
"name": "travel",
"radios": [
{
"id": "home-example-radio-with-revealed-text-input",
"label": {
"text": "Work mainly from home"
},
"value": "home"
},
{
"id": "car-example-radio-with-revealed-text-input",
"label": {
"text": "Car or van"
},
"value": "car"
},
{
"id": "underground-example-radio-with-revealed-text-input",
"label": {
"text": "Underground, metro, light rail or tram"
},
"value": "underground"
},
{
"id": "train-example-radio-with-revealed-text-input",
"label": {
"text": "Train"
},
"value": "train"
},
{
"id": "bus-example-radio-with-revealed-text-input",
"label": {
"text": "Bus, minibus or coach"
},
"value": "bus"
},
{
"id": "bicycle-example-radio-with-revealed-text-input",
"label": {
"text": "Bicycle"
},
"value": "bicycle"
},
{
"id": "walk-example-radio-with-revealed-text-input",
"label": {
"text": "Walk"
},
"value": "walk"
},
{
"id": "other-radio-example-radio-with-revealed-text-input",
"label": {
"text": "Other"
},
"value": "other",
"checked": true,
"other": {
"otherType": "textarea",
"id": "other-textbox-example-radio-with-revealed-text-input",
"name": "other-answer",
"label": {
"text": "Enter how you travel"
},
"charCheckLimit": {
"limit": 200,
"charCountSingular": "You have {x} character remaining",
"charCountPlural": "You have {x} characters remaining"
}
}
}
]
})
}}
{% endcall %}
86 changes: 86 additions & 0 deletions src/components/radios/example-radios-with-revealed-text-area.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{% from "components/radios/_macro.njk" import onsRadios %}
{% from "components/question/_macro.njk" import onsQuestion %}

{% call onsQuestion({
"title": "How do you usually travel to work?",
"classes": "ons-u-mt-no",
"legendIsQuestionTitle": true
}) %}
{{
onsRadios({
"dontWrap": true,
"name": "travel",
"radios": [
{
"id": "home-example-radio-with-revealed-text-input",
"label": {
"text": "Work mainly from home"
},
"value": "home"
},
{
"id": "car-example-radio-with-revealed-text-input",
"label": {
"text": "Car or van"
},
"value": "car"
},
{
"id": "underground-example-radio-with-revealed-text-input",
"label": {
"text": "Underground, metro, light rail or tram"
},
"value": "underground"
},
{
"id": "train-example-radio-with-revealed-text-input",
"label": {
"text": "Train"
},
"value": "train"
},
{
"id": "bus-example-radio-with-revealed-text-input",
"label": {
"text": "Bus, minibus or coach"
},
"value": "bus"
},
{
"id": "bicycle-example-radio-with-revealed-text-input",
"label": {
"text": "Bicycle"
},
"value": "bicycle"
},
{
"id": "walk-example-radio-with-revealed-text-input",
"label": {
"text": "Walk"
},
"value": "walk"
},
{
"id": "other-radio-example-radio-with-revealed-text-input",
"label": {
"text": "Other"
},
"value": "other",
"other": {
"otherType": "textarea",
"id": "other-textbox-example-radio-with-revealed-text-input",
"name": "other-answer",
"label": {
"text": "Enter how you travel"
},
"charCheckLimit": {
"limit": 200,
"charCountSingular": "You have {x} character remaining",
"charCountPlural": "You have {x} characters remaining"
}
}
}
]
})
}}
{% endcall %}

0 comments on commit 4f0ae95

Please sign in to comment.