Dojo's Radio widget provides a styleable radio widget with an optional label.
- Correctly handles a11y attributes
- Wraps the input in a visible or invisible but accessible
<label>if thelabelproperty is added
Radio ensures that the proper attributes (ARIA or otherwise) are set along with classes when properties such as disabled, readOnly, invalid, etc. are used.
If the label property is not used, we recommend creating a separate label and pointing it at the input's widgetId property.
// Example usage
w(Radio, {
checked: this.state.radioValue === 'radio1-1',
describedBy: 'instructions',
label: 'Choice A',
name: 'radio1'
value: 'radio1-1',
onChange: (event: TypedTargetEvent<HTMLInputElement>) => {
this.setState({ radioValue: event.target.value });
},
}),
w(Radio, {
checked: this.state.radioValue === 'radio1-2',
describedBy: 'instructions',
label: 'Choice B',
name: 'radio1'
value: 'radio1-2',
onChange: (event: TypedTargetEvent<HTMLInputElement>) => {
this.setState({ radioValue: event.target.value });
},
}),
v('p', {
id: 'instructions'
}, [ 'Extra helper text for radios' ]);The following CSS classes are available on the Radio widget for use with custom themes:
root: Applied to either the wrapping<label>, or a<div>in the same position in the node hierarchychecked: Applied to the same level asrootifproperties.checkedis truedisabled: Applied to the same level asrootifproperties.disabledis truereadonly: Applied to the same level asrootifproperties.readOnlyis truerequired: Applied to the same level asrootifproperties.requiredis trueinvalid: Applied to the same level asrootifproperties.invalidis truevalid: Applied to the same level asrootifproperties.invalidis set false (i.e. not only undefined)inputWrapper: Applied to the immediate parent of the<input>input: Applied to the<input>element