Skip to content

Commit

Permalink
docs(checkbox): add storybook docs for onClick (#10130)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Strubberg <[email protected]>
  • Loading branch information
tay1orjones and sstrubberg authored Nov 18, 2021
1 parent d6fabd6 commit 46eded4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/react/src/components/Checkbox/Checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ event.
<Checkbox onChange={()=>{}} labelText={`Checkbox label`} id="checkbox-label-2" />
```

### Checkbox onClick

You can use the `onClick` prop to pass in a custom function for event handling.
This event can be used to control click event bubbling without having to
implement your own wrapping element/component. It receives the dom event as its
only argument.

`onClick` is placed on the wrapping `div` containing both the `input` and
`label`. As such, this will be called twice for every click - once for the
input, a second time for the label. Due to this, `onClick` should not be used to
catch state updates when using Checkbox as a controlled component.

```jsx
<Checkbox onClick={()=>{}} labelText={`Checkbox label`} id="checkbox-label-1" />
<Checkbox onClick={()=>{}} labelText={`Checkbox label`} id="checkbox-label-2" />
```

## Feedback

Help us improve this component by providing feedback, asking questions on Slack,
Expand Down

0 comments on commit 46eded4

Please sign in to comment.