Radio Ready
Radio Buttons are graphical interface elements that allow user to choose only one of a predefined set of mutually exclusive options.
Examples #
<duet-radio checked label="Checked" value="test"></duet-radio>
<script>
// Select the above radio component
var radio = document.querySelector("duet-radio")
// Listen for change events in the radio
radio.addEventListener("duetChange", function (e) {
console.log("Change detected in radio", e.detail)
})
</script>
<duet-radio label="Unchecked"></duet-radio>
<duet-radio checked disabled label="Disabled"></duet-radio>
<duet-radio value="test" name="foo">
<span slot="label">Label with <strong>HTML</strong></span>
</duet-radio>
Properties #
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
accessibleActiveDescendant | accessible-active-descendant | Indicates the id of a related component’s visually focused element. | string | undefined |
accessibleControls | accessible-controls | Use this prop to add an aria-controls attribute. Use the attribute to indicate the id of a component controlled by this component. | string | undefined |
accessibleDescribedBy | accessible-described-by | Indicates the id of a component that describes the radio. | string | undefined |
accessibleDescription | accessible-description | Aria description the button | string | undefined |
accessibleDetails | accessible-details | Aria Details of the component | string | undefined |
accessibleIndex | accessible-index | Control the tabindex of checkbox. In most cases this should never be used! It exists only for Duet’s internal needs. | string | undefined |
accessibleLabelledBy | accessible-labelled-by | String of id's that indicate alternative labels elements | string | undefined |
accessibleOwns | accessible-owns | Indicates the id of a component owned by the radio. | string | undefined |
blockEvents | block-events | Stops the components from emitting events | boolean | false |
checked | checked | Check state of the radio. | boolean | undefined |
disabled | disabled | Makes the radio component disabled. This prevents users from being able to interact with the radio, and conveys its inactive state to assistive technologies. | boolean | false |
identifier | identifier | Adds a unique identifier for the radio. | string | undefined |
label | label | Label for the radio. | string | "label" |
margin | margin | Controls the margin of the component. | "auto" | "none" | "auto" |
name | name | Name of the radio. | string | undefined |
required | required | Set whether the input is required or not. Please note that this is required for accessible inputs when the user is required to fill them. When using this property you need to also set “novalidate” attribute to your form element to prevent browser from displaying its own validation errors. | boolean | false |
role | role | Defines a specific role attribute for the input. | string | undefined |
theme | theme | Theme of the radio. | "" | "default" | "turva" | "" |
value | value | The value of the radio input does not mean if it's checked or not, use the checked property for that. | string | undefined |
Events #
Event | Description | Type |
---|---|---|
duetBlur | Emitted when the checkbox loses focus. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-radio"; }> |
duetChange | Emitted when the checked property has changed. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-radio"; }> |
duetFocus | Emitted when the checkbox has focus. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-radio"; }> |
Methods #
setFocus(options?: FocusOptions) => Promise<void>
#
Sets focus on the specified duet-radio
. Use this method instead of the global
input.focus()
.
Parameters #
Name | Type | Description |
---|---|---|
options | FocusOptions |
Returns #
Type: Promise<void>
Slots #
Slot | Description |
---|---|
"label" | Label content. |
Usage #
This section includes guidelines for designers and developers about the usage of this component in different contexts.
When to use #
- When the user should be able to choose just one option from a limited number of options.
- When you have under 11 options to choose from.
When not to use #
Accessibility #
This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. You can find additional information regarding accessibility of this component below.
label
property is always required for accessible radio control.labelHidden
property hides the above label visually, but still keeps it accessible for assistive technologies.- You can use
accessibleActiveDescendant
property to indicates the id of a related component’s visually focused element. - Use
accessibleControls
property to add an aria-controls attribute. Use the attribute to indicate the id of a component controlled by this component. - Use
accessibleOwns
property to indicate the id of a component owned by the radio input. - Use
accessibleDescribedBy
property to indicate the id of a component which contains descriptive/help text related to the radio input. disabled
property makes the radio component disabled. This prevents users from being able to interact with the radio input, and conveys its inactive state to assistive technologies.role
property can be used to define a specific role attribute for the radio input.
Integration
For integration, event and theming guidelines, please see Using Components. This documentation explains how to implement and use Duet’s components across different technologies like Angular, React or Vanilla JavaScript.
Tutorials
Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:
Building Layouts
TutorialsUsing CLI Tools
TutorialsCreating Custom Patterns
TutorialsServer Side Rendering
TutorialsSharing Prototypes
TutorialsUsage With Markdown
Troubleshooting
If you experience any issues while using a component, please head over to the Support page for more guidelines and help.