Radios
Default
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
name: "example-default",
hint: {
text: "This includes changing your last name or spelling your name differently."
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
]
}} />
Inline
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "example",
classes: "govuk-radios--inline",
name: "example",
fieldset: {
legend: {
text: "Have you changed your name?"
}
},
hint: {
text: "This includes changing your last name or spelling your name differently."
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No",
checked: true
}
]
}} />
With disabled
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "gov",
name: "gov",
fieldset: {
legend: {
text: "How do you want to sign in?",
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
},
items: [
{
value: "gateway",
text: "Sign in with Government Gateway",
id: "gateway",
hint: {
text: "You’ll have a user ID if you’ve registered for Self Assessment or filed a tax return online before."
}
},
{
value: "verify",
text: "Sign in with GOV.UK Verify",
id: "verify",
hint: {
text: "You’ll have an account if you’ve already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity."
},
disabled: true
}
]
}} />
With legend as page heading
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "housing-act",
name: "housing-act",
fieldset: {
legend: {
text: "Which part of the Housing Act was your licence issued under?",
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
},
hint: {
text: "Select one of the options below."
},
items: [
{
value: "part-2",
html: "<span class=\"govuk-heading-s govuk-!-margin-bottom-1\">Part 2 of the Housing Act 2004</span> For properties that are 3 or more stories high and occupied by 5 or more people"
},
{
value: "part-3",
html: "<span class=\"govuk-heading-s govuk-!-margin-bottom-1\">Part 3 of the Housing Act 2004</span> For properties that are within a geographical area defined by a local council"
}
]
}} />
With a medium legend
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "housing-act",
name: "housing-act",
fieldset: {
legend: {
text: "Which part of the Housing Act was your licence issued under?",
classes: "govuk-fieldset__legend--m"
}
},
hint: {
text: "Select one of the options below."
},
items: [
{
value: "part-2",
html: "<span class=\"govuk-heading-s govuk-!-margin-bottom-1\">Part 2 of the Housing Act 2004</span> For properties that are 3 or more stories high and occupied by 5 or more people"
},
{
value: "part-3",
html: "<span class=\"govuk-heading-s govuk-!-margin-bottom-1\">Part 3 of the Housing Act 2004</span> For properties that are within a geographical area defined by a local council"
}
]
}} />
With a divider
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "example-divider",
name: "example",
fieldset: {
legend: {
text: "How do you want to sign in?"
}
},
items: [
{
value: "governement-gateway",
text: "Use Government Gateway"
},
{
value: "govuk-verify",
text: "Use GOV.UK Verify"
},
{
divider: "or"
},
{
value: "create-account",
text: "Create an account"
}
]
}} />
With hints on items
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "gov",
name: "gov",
fieldset: {
legend: {
text: "How do you want to sign in?",
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
},
items: [
{
value: "gateway",
text: "Sign in with Government Gateway",
id: "gateway",
hint: {
text: "You’ll have a user ID if you’ve registered for Self Assessment or filed a tax return online before."
}
},
{
value: "verify",
text: "Sign in with GOV.UK Verify",
id: "verify",
hint: {
text: "You’ll have an account if you’ve already proved your identity with either Barclays, CitizenSafe, Digidentity, Experian, Post Office, Royal Mail or SecureIdentity."
}
}
]
}} />
Without fieldset
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
name: "colours",
items: [
{
value: "red",
text: "Red"
},
{
value: "green",
text: "Green"
},
{
value: "blue",
text: "Blue"
}
]
}} />
With fieldset and error message
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "example",
name: "example",
errorMessage: {
text: "Please select an option"
},
fieldset: {
legend: {
text: "Have you changed your name?"
}
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No",
checked: true
}
]
}} />
With very long option text
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
name: "waste",
hint: {
text: "Nullam id dolor id nibh ultricies vehicula ut id elit."
},
errorMessage: {
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
},
fieldset: {
legend: {
text: "Maecenas faucibus mollis interdum?"
}
},
items: [
{
value: "nullam",
text: "Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus."
},
{
value: "aenean",
text: "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras mattis consectetur purus sit amet fermentum."
},
{
value: "fusce",
text: "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. Sed posuere consectetur est at lobortis."
}
]
}} />
With conditional items
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted",
name: "how-contacted",
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: "<label class=\"govuk-label\" for=\"context-email\">Email address</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"context-email\" type=\"text\" id=\"context-email\">\n"
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-phone\">Phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-phone\" type=\"text\" id=\"contact-phone\">\n"
}
},
{
value: "text",
text: "Text message",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-text-message\">Mobile phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-text-message\" type=\"text\" id=\"contact-text-message\">\n"
}
}
]
}} />
With conditional items with special characters
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "user.profile[contact-prefs]",
name: "contact-prefs",
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: "<label class=\"govuk-label\" for=\"context-email\">Email address</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"context-email\" type=\"text\" id=\"context-email\">\n"
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-phone\">Phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-phone\" type=\"text\" id=\"contact-phone\">\n"
}
},
{
value: "text",
text: "Text message",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-text-message\">Mobile phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-text-message\" type=\"text\" id=\"contact-text-message\">\n"
}
}
]
}} />
With conditional item checked
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-checked",
name: "how-contacted-checked",
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
checked: true,
conditional: {
html: "<label class=\"govuk-label\" for=\"context-email\">Email</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"context-email\" type=\"text\" id=\"context-email\">\n"
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-phone\">Phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-phone\" type=\"text\" id=\"contact-phone\">\n"
}
},
{
value: "text",
text: "Text message",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-text-message\">Mobile phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-text-message\" type=\"text\" id=\"contact-text-message\">\n"
}
}
]
}} />
Prechecked
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
name: "example-default",
hint: {
text: "This includes changing your last name or spelling your name differently."
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No",
checked: true
}
]
}} />
Prechecked using value
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
name: "example-default",
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
],
value: "no"
}} />
With conditional items and preChecked value
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-checked",
name: "how-contacted-checked",
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: "<label class=\"govuk-label\" for=\"context-email\">Email</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"context-email\" type=\"text\" id=\"context-email\">\n"
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-phone\">Phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-phone\" type=\"text\" id=\"contact-phone\">\n"
}
},
{
value: "text",
text: "Text message",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-text-message\">Mobile phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-text-message\" type=\"text\" id=\"contact-text-message\">\n"
}
}
],
value: "text"
}} />
With optional formGroup classes showing group error
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-2",
name: "how-contacted-2",
formGroup: {
classes: "govuk-form-group--error"
},
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: "<label class=\"govuk-label\" for=\"context-email\">Email address</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"context-email\" type=\"text\" id=\"context-email\">\n"
}
},
{
value: "phone",
text: "Phone",
checked: true,
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-phone\">Phone number</label>\n<span id=\"contact-phone-error\" class=\"govuk-error-message\">Problem with input</span>\n<input class=\"govuk-input govuk-input--error govuk-!-width-one-third\" name=\"contact-phone\" type=\"text\" id=\"contact-phone\" aria-describedby=\"contact-phone-error\">\n"
}
},
{
value: "text",
text: "Text message",
conditional: {
html: "<label class=\"govuk-label\" for=\"contact-text-message\">Mobile phone number</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"contact-text-message\" type=\"text\" id=\"contact-text-message\">\n"
}
}
]
}} />
Small
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-2",
name: "how-contacted-2",
formGroup: {
classes: "govuk-radios--small"
},
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email"
},
{
value: "phone",
text: "Phone"
},
{
value: "text",
text: "Text message"
}
]
}} />
Small with long text
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "foo",
name: "foo",
classes: "govuk-radios--small",
fieldset: {
legend: {
text: "Venenatis Condimentum"
}
},
items: [
{
value: "nullam",
text: "Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus."
},
{
value: "aenean",
text: "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras mattis consectetur purus sit amet fermentum."
},
{
value: "fusce",
text: "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. Sed posuere consectetur est at lobortis."
}
]
}} />
Small with error
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-2",
name: "how-contacted-2",
formGroup: {
classes: "govuk-radios--small"
},
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
errorMessage: {
text: "Select a thing"
},
items: [
{
value: "email",
text: "Email"
},
{
value: "phone",
text: "Phone"
},
{
value: "text",
text: "Text message"
}
]
}} />
Small with hint
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-2",
name: "how-contacted-2",
formGroup: {
classes: "govuk-radios--small"
},
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
hint: {
text: "Hint for email address"
}
},
{
value: "phone",
text: "Phone"
},
{
value: "text",
text: "Text message"
}
]
}} />
Small with disabled
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-2",
name: "how-contacted-2",
formGroup: {
classes: "govuk-radios--small"
},
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email"
},
{
value: "phone",
text: "Phone"
},
{
value: "text",
text: "Text message",
disabled: true
}
]
}} />
Small with conditional reveal
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "how-contacted-2",
name: "how-contacted-2",
formGroup: {
classes: "govuk-radios--small"
},
fieldset: {
legend: {
text: "How do you want to be contacted?"
}
},
items: [
{
value: "email",
text: "Email",
conditional: {
html: "<label class=\"govuk-label\" for=\"context-email\">Foo</label>\n<input class=\"govuk-input govuk-!-width-one-third\" name=\"context-email\" type=\"text\" id=\"context-email\">\n"
}
},
{
value: "phone",
text: "Phone"
},
{
value: "text",
text: "Text message"
}
]
}} />
Small inline
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "sort",
classes: "govuk-radios--small govuk-radios--inline",
name: "example",
fieldset: {
legend: {
text: "Sort by"
}
},
items: [
{
value: "relevance",
text: "relevance"
},
{
value: "title",
text: "title"
},
{
value: "created",
text: "created"
}
]
}} />
Small inline extreme
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "sort",
classes: "govuk-radios--small govuk-radios--inline",
name: "example",
fieldset: {
legend: {
text: "Sort by"
}
},
items: [
{
value: "relevance",
text: "relevance"
},
{
value: "title",
text: "title"
},
{
value: "created",
text: "created"
},
{
value: "modified",
text: "modified"
},
{
value: "category",
text: "category"
},
{
value: "votes",
text: "votes"
},
{
value: "flavour",
text: "flavour"
},
{
value: "hue",
text: "hue"
},
{
value: "happiness",
text: "happiness"
},
{
value: "funkiness",
text: "funkiness"
}
]
}} />
Small with a divider
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
idPrefix: "example-small-divider",
name: "example",
fieldset: {
legend: {
text: "How do you want to sign in?"
}
},
classes: "govuk-radios--small",
items: [
{
value: "governement-gateway",
text: "Use Government Gateway"
},
{
value: "govuk-verify",
text: "Use GOV.UK Verify"
},
{
divider: "or"
},
{
value: "create-account",
text: "Create an account"
}
]
}} />
With idPrefix
Svelte code
<script>
import { Radios } from '@danboscaro/govuk-svelte'
</script>
<Radios {...{
name: "example-radio",
idPrefix: "example-id-prefix",
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
]
}} />