A group of <Checkbox> buttons. The <Checkbox> buttons may either be direct children or descendants of the checkbox group.
Note: Setting value will override defaultValue as it puts the group of checkboxes into a controlled state. value will not override checkboxes that have checked set, as CheckboxGroup will take control of uncontrolled Checkbox components and can't override controlled ones. value will however override defaultChecked on Checkbox.
The onChange event handler for CheckboxGroup will fire after any onChange event handler set on individual Checkbox components. However, it is highly recommended to only set one event handler for the whole group in a controlled CheckboxGroup.
Checkbox components must have a value set on them in order to be controlled by CheckboxGroup.
Usage
import { CheckboxGroup } from 'nr1';Examples
Basic
<CheckboxGroup label="My checkbox group"> <Checkbox label="Checkbox 1" /> <Checkbox label="Checkbox 2" /> <Checkbox label="Checkbox 3" /></CheckboxGroup>;With label and info
<CheckboxGroup label="My checkbox group" info="Info value"> <Checkbox label="Checkbox 1" /> <Checkbox label="Checkbox 2" /> <Checkbox label="Checkbox 3" /></CheckboxGroup>;With inline label
<CheckboxGroup label="My checkbox group" labelInline> <Checkbox label="Checkbox 1" /> <Checkbox label="Checkbox 2" /> <Checkbox label="Checkbox 3" /></CheckboxGroup>;With description
<CheckboxGroup label="My checkbox group" description="Description value"> <Checkbox label="Checkbox 1" /> <Checkbox label="Checkbox 2" /> <Checkbox label="Checkbox 3" /></CheckboxGroup>;With invalid message
<CheckboxGroup label="My checkbox group" invalid="Invalid message value"> <Checkbox label="Checkbox 1" /> <Checkbox label="Checkbox 2" /> <Checkbox label="Checkbox 3" /></CheckboxGroup>;With default values
<CheckboxGroup label="My checkbox group" defaultValue={['1', '2']}> <Checkbox label="Checkbox 1" value="1" /> <Checkbox label="Checkbox 2" value="2" /> <Checkbox label="Checkbox 3" value="3" /></CheckboxGroup>;Controlled component
class MyNerdlet extends React.PureComponent { constructor(props) { super(props);
this.state = { values: ['2'], };
this.onChange = this.onChange.bind(this); }
onChange(event, values) { this.setState({ values }); }
render() { return ( <CheckboxGroup value={this.state.values} onChange={this.onChange}> <Checkbox label="Checkbox 1" value="1" /> <Checkbox label="Checkbox 2" value="2" /> <Checkbox label="Checkbox 3" value="3" /> </CheckboxGroup> ); }}Props
node | Content of the CheckboxGroup. |
string | Appends class names to the component. |
string[] | Default values of the checkbox 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 checkbox group value changes (a Event source of the callback. The values of the selected checkboxes. |
boolean | If |
object | Inline style for custom styling. |
string | Adds a |
string[] | Values of the checkbox group. The |