Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(checkbox): add storybook docs for onClick #10130

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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