When a user can choose only one of the options provided
The radio button state can be controlled through the checked
property. If the checked
prop is not set then the radio button will manage its own state.
You can listen to the radio button events through the onClick
or the onChange
props.
Usage
import { Radio } from 'nr1'
Examples
Basic
<div className="nr1-Docs-prettify"> <Radio onChange={(event) => alert('Foo')} label="Foo" /> <Radio checked label="Bar" /> <Radio checked disabled label="Baz" /></div>
With info
<Radio onChange={(event) => alert('Foo')} info="Info value" label="Foo" />
With description
<Radio onChange={(event) => alert('Foo')} description="Description value" label="Foo"/>
With invalid message
<Radio onChange={(event) => alert('Foo')} invalid="Invalid message value" label="Foo"/>
Controlled component
class MyNerdlet extends React.PureComponent { constructor(props) { super(props);
this.state = { isChecked: false, };
this.onClick = this.onClick.bind(this); }
onClick(event) { this.setState((state) => { return { isChecked: !state.isChecked }; }); }
render() { return ( <Radio checked={this.state.isChecked} onClick={this.onClick} label="Radio button" /> ); }}
Props
boolean | If |
string | Appends class names to the component.Should be used only for positioning and spacing purposes. |
string | Message with instructions on how to fill the form field. |
boolean | If |
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. |
function | Callback fired any time the selected state of the radio button changes. function ( |
function | Callback fired any time the radio button is clicked. function ( |
enum[] | Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like <Array of |
object | Inline style for custom styling.Should be used only for positioning and spacing purposes. |
string | Adds a |
string | The value of the component. Used by the |