The Placer Toolkit alpha has
arrived! 🎉
Plenty of changes are coming your
way—some big, some breaking, some
even nuclear! Beware the changelog…
Radio Group
<pc-radio-group> 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> Demos#
Hints#
Add a descriptive hint to a radio group with the hint attribute. For hints that contain HTML, use the hint slot instead.
Disabling radios#
Radios can be disabled by adding the disabled attribute to the respective options inside the radio group.
Size#
The size of radios will be determined by the radio group’s size attribute.
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.
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.
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.
Properties#
| Name | Description | Reflects | Default |
|---|---|---|---|
label | The radio group’s label. This is required for proper accessibility. If you need to display HTML, use the label slot instead.Type: string |
| "" |
hint | The radio group’s hint. This is required for proper accessibility. If you need to display HTML, use the hint slot instead.Type: string |
| "" |
name | The name of the radio group, submitted as a name/value pair with form data. Type: string |
| "option" |
value | The current value of the radio group, submitted as a name/value pair with form data. Type: string |
| "" |
size | The radio group’s size. This size will be applied to all child radios. Type: "small" | "medium" | "large" |
| "medium" |
form | By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.Type: string |
| "" |
required | Indicates if an option of the radio group must be chosen or not. Type: boolean |
| false |
validity | Gets the validity state object. |
| ‐ |
validationMessage | Gets the validation message. |
| ‐ |
updateComplete | A read‐only promise that resolves when the component has finished updating. | ‐ |
Learn more about attributes and properties.
Slots#
| Name | Description |
|---|---|
| (default) | The default slot where <pc-radio> elements are placed. |
label | The radio group’s label. This is required for proper accessibility. Alternatively, you can use the label attribute. |
hint | Text that describes how to use the radio group. Alternatively, you can use the hint attribute. |
Learn more about using slots.
Methods#
| Name | Description | Arguments |
|---|---|---|
checkValidity() | Checks for validity but does not show a validation message. Returns true when valid and false when invalid. | ‐ |
getForm() | Gets the associated form, if one exists. | ‐ |
reportValidity() | Checks for validity and shows the browser’s validation message if the radio group is invalid. | ‐ |
setCustomValidity() | Sets a custom validation message. Pass an empty string to restore validity. | message: string |
focus() | Sets focus on the radio group. | options: FocusOptions |
Learn more about methods.
Events#
| Name | Description | Event detail |
|---|---|---|
pc-change | Emitted when the radio group’s selected value changes. | ‐ |
pc-input | Emitted when the radio group receives user input. | ‐ |
pc-invalid | Emitted when the form control has been checked for validity and its constraints aren’t satisfied. | ‐ |
Learn more about events.
Parts#
| Name | Description |
|---|---|
form-control | The form control that wraps the label, input and hint. |
label | The radio group’s label. |
input | The radio group. |
hint | The 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.
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.1/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.1/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";