A group of <Radio> buttons. The <Radio> buttons may either be direct children or descendants of the radio group. <Radio> buttons inside a radio group must have a unique value assigned.
Once a radio group is established, selecting any <Radio> in that group automatically deselects any currently-selected <Radio> in the group.
Note: Setting value will override defaultValue as it puts the RadioGroup into a controlled state. value will not override Radio components that have checked set, as RadioGroup will take control of uncontrolled Radio components and can't override controlled ones.
The onChange event handler for RadioGroup will fire after any onChange event handler set on individual Radio components. However, it is highly recommended to only set one event handler for the whole group in a controlled RadioGroup.
Usage
import { RadioGroup } from 'nr1';Examples
Basic
<RadioGroup defaultValue="2"> <Radio label="Radio 1" value="1" /> <Radio label="Radio 2" value="2" /> <Radio label="Radio 3" value="3" /></RadioGroup>;With label and info
<RadioGroup label="Radio Group" info="Info value" defaultValue="2"> <Radio label="Radio 1" value="1" /> <Radio label="Radio 2" value="2" /> <Radio label="Radio 3" value="3" /></RadioGroup>;With inline label
<RadioGroup label="Radio Group" labelInline defaultValue="2"> <Radio label="Radio 1" value="1" /> <Radio label="Radio 2" value="2" /> <Radio label="Radio 3" value="3" /></RadioGroup>;With description
<RadioGroup label="Radio Group" description="Description value" defaultValue="2"> <Radio label="Radio 1" value="1" /> <Radio label="Radio 2" value="2" /> <Radio label="Radio 3" value="3" /></RadioGroup>;With invalid message
<RadioGroup label="Radio Group" invalid="Invalid message value" defaultValue="2"> <Radio label="Radio 1" value="1" /> <Radio label="Radio 2" value="2" /> <Radio label="Radio 3" value="3" /></RadioGroup>;Controlled component
class MyNerdlet extends React.PureComponent { constructor(props) { super(props);
this.state = { selectedValue: '2', };
this.onChange = this.onChange.bind(this); }
onChange(event, value) { this.setState((state) => { return { selectedValue: value }; }); }
render() { return ( <RadioGroup value={this.state.selectedValue} onChange={this.onChange}> <Radio label="Radio 1" value="1" /> <Radio label="Radio 2" value="2" /> <Radio label="Radio 3" value="3" /> </RadioGroup> ); }}Props
node | Content of the RadioGroup. |
string | Appends class names to the component. |
any | Default value of the radio group. The |
string | Message with instructions on how to fill the form field. |
string | Additional information can be displayed in an info tooltip next to the Label. |
boolean|string | When true, sets the field in an invalid state, in order to notify the user attention is needed over this particular field. This property can be a |
string | Text to display as label. |
boolean | Display the label inline the form control.Use only when the component is not inside a |
function | Callback which is fired when the radio group value changes (a function ( |
boolean | If |
object | Inline style for custom styling. |
string | Adds a |
any | Value of the radio group. The radio button with the matching value will be selected.If defined, it turns the component into a controlled component. |