Skip to content

Commit

Permalink
docs(checkbox): Add example with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Dec 8, 2017
1 parent a798186 commit b13444d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/components/Checkbox/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,25 @@

### Getting feedback for an unchecked checkbox

Use the feedback attribute to give the user feedback regarding a missed checkbox by highlighting the label and checkbox element.

Use the feedback and error props to give the user feedback regarding a missed checkbox by highlighting the label, checkbox element and adding an error message stating how to proceed.

```
<Checkbox name="terms" value="agree" label="I agree to the terms and conditions" feedback="error" />
const message = "Please confirm you have read the terms and conditions";
initialState = {
checked: false,
feedback: 'error',
message: message,
};
const handleCheck = (event) => {
if (event.target.checked === true) {
setState({ checked: false, feedback: undefined, message: undefined});
} else {
setState({ checked: true, feedback: 'error', message: message});
}
};
<Checkbox name="terms" value="agree" label="I agree to the terms and conditions" feedback={state.feedback} error={state.message} onChange={handleCheck} checked={state.checked} />
```

0 comments on commit b13444d

Please sign in to comment.