Skip to main content Sidebar
On this page

Radio Group

<pc-radio-group> Since  0.3.0 Experimental

Radio groups are used to group multiple radios so they function as a single form control.

<pc-radio-group label="Select an option" name="group-1" value="option-1">
    <pc-radio value="option-1">Option 1</pc-radio>
    <pc-radio value="option-2">Option 2</pc-radio>
    <pc-radio value="option-3">Option 3</pc-radio>
</pc-radio-group>
Code Edit

Demos

Hints

Add a descriptive hint to a radio group with the hint attribute. For hints that contain HTML, use the hint slot instead.

Edit

Disabling radios

Radios can be disabled by adding the disabled attribute to the respective options inside the radio group.

Edit

Size

The size of radios will be determined by the radio group’s size attribute.

Edit

Radios also have a size attribute. This can be useful in certain situations, but it will be ignored when used inside of a radio group.

Horizontal

Set the orientation attribute to horizontal to make a horizontal radio group.

Edit

Required

Set the required attribute to make selecting an option mandatory. If a value hasn’t been selected, it will prevent the form from submitting and display an error message.

Edit

Custom validity

Use the setCustomValidity() method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. If you want to restore the default validation message, pass an empty string to the setCustomValidity() method.

Edit

Properties

NameDescriptionReflectsDefault
labelThe radio group’s label. This is required for proper accessibility. If you need to display HTML, use the label slot instead.
Type: string
""
hintThe radio group’s hint. This is required for proper accessibility. If you need to display HTML, use the hint slot instead.
Type: string
""
nameThe name of the radio group, submitted as a name/value pair with form data.
Type: string | null
null
valueThe current value of the radio group, submitted as a name/value pair with form data.
defaultValue
value
The default value of the radio group. Primarily used for resetting the radio group.
Type: string | null
sizeThe radio group’s size. This size will be applied to all child radios.
Type: "small" | "medium" | "large"
"medium"
requiredIndicates if an option of the radio group must be chosen or not.
Type: boolean
false
validationTargetWe use the first available radio as the validationTarget similar to native HTML that shows the validation popup on the first radio element.
updateComplete A read‐only promise that resolves when the component has finished updating.

Learn more about customising animations.

Slots

NameDescription
(default)The default slot where <pc-radio> elements are placed.
labelThe radio group’s label. This is required for proper accessibility. Alternatively, you can use the label attribute.
hintText that describes how to use the radio group. Alternatively, you can use the hint attribute.

Learn more about using slots.

Methods

NameDescriptionArguments
focus()Sets focus on the radio group.options: FocusOptions

Learn more about methods.

Events

NameDescriptionEvent detail
inputEmitted when the radio group receives user input.InputEvent
changeEmitted when the radio group’s selected value changes.Event
pc-invalidEmitted when the form control has been checked for validity and its constraints aren’t satisfied.

Learn more about events.

Parts

NameDescription
form-controlThe form control that wraps the label, input and hint.
labelThe radio group’s label.
inputThe radio group.
hintThe radio group’s hint.

Learn more about customising CSS parts.

Importing

If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

CDN (script tag)CDN (import)npm (import)

To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.4/cdn/components/radio-group/radio-group.js"></script>

To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.4/cdn/components/radio-group/radio-group.js";

To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

import "placer-toolkit/dist/components/radio-group/radio-group.js";

We’d love to hear from you. Please reach out to us with any questions or enquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Dangerous lands

Whoa! You’ve wandered into the dangerous lands of Placer Toolkit. Version 0 is out of date and doesn’t meet EU privacy standards, including GDPR.

Want the latest powers, security and compliance? Stick with the current version of Placer Toolkit!

Yikes! Power up!

Our site is 100 % cookie‐free! We value your privacy, which is why we don’t store any cookies or personal information related to you.

Your browser history is safe from crumbs, and your data is protected, aligning with modern privacy standards like the GDPR. Enjoy your visit without a single digital cookie in sight! 🍪🚫

View our Privacy Policy for more information.

Got it!