Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(checkboxes): add ability to click on label to select
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Oct 16, 2019
1 parent 7340739 commit b93a757
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 12 additions & 5 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import React, { Component } from 'react'
import FormCheck from 'react-bootstrap/FormCheck'

interface Props {
/** The id for the checkbox */
id?: string
/** The label to render next to the checkbox */
label: string
/* Determines the side of the checkbox to render the label on. By default right */
labelSide?: 'right' | 'left'
/* Gives the checkbox a name */
/** Gives the checkbox a name */
name?: string
/* Determines if the checkbox should be disabled or not. By default false */
/** Determines if the checkbox should be disabled or not. By default false */
disabled?: boolean
/* Determines if the checkbox should render inline or not. By default false. */
/** Determines if the checkbox should render inline or not. By default false. */
inline?: boolean
/** The onChange listener */
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void
Expand All @@ -26,13 +28,18 @@ class Checkbox extends Component<Props, {}> {

return (
<FormCheck name={this.props.name} inline={this.props.inline}>
{labelSide === 'left' && <FormCheck.Label>{this.props.label}</FormCheck.Label>}
{labelSide === 'left' && (
<FormCheck.Label htmlFor={this.props.id}>{this.props.label}</FormCheck.Label>
)}
<FormCheck.Input
id={this.props.id}
type="checkbox"
disabled={this.props.disabled}
onChange={this.props.onChange}
/>
{labelSide === 'right' && <FormCheck.Label>{this.props.label}</FormCheck.Label>}
{labelSide === 'right' && (
<FormCheck.Label htmlFor={this.props.id}>{this.props.label}</FormCheck.Label>
)}
</FormCheck>
)
}
Expand Down
12 changes: 6 additions & 6 deletions stories/checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ storiesOf('Checkbox', module)
.add('Checkbox', () => (
<div>
<h1>Vertical</h1>
<Checkbox label="Checkbox 1" />
<Checkbox label="Checkbox 2" />
<Checkbox label="Checkbox 3" disabled />
<Checkbox label="Checkbox 1" id="checkbox1" />
<Checkbox label="Checkbox 2" id="checkbox2" />
<Checkbox label="Checkbox 3" id="checkbox3" disabled />
<br />
<h1>Horizontal</h1>
<Checkbox label="Checkbox 1" inline />
<Checkbox label="Checkbox 2" inline />
<Checkbox label="Checkbox 3" inline />
<Checkbox label="Checkbox 1" id="checkbox11" inline />
<Checkbox label="Checkbox 2" id="checkbox22" inline />
<Checkbox label="Checkbox 3" id="checkbox33" inline />
</div>
))

0 comments on commit b93a757

Please sign in to comment.