Skip to content

Commit

Permalink
feat(core-radio): add description text functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
marcod1419 authored and jraff committed Dec 12, 2018
1 parent e465e0b commit dc418c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Binary file modified e2e/output/components/Radio/baseline/chrome_headless.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions packages/Radio/Radio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './Radio.modules.scss'
* @version ./package.json
*/
const Radio = props => (
<Choice {...props} type="radio" inputTypeStyles={styles}>
<Choice {...props} type="radio" inputTypeStyles={styles} description={props.description}>
{(checked, disabled) => {
return (
checked && (
Expand Down Expand Up @@ -37,9 +37,13 @@ Radio.propTypes = {
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]).isRequired,
/**
* The checked state
* The checked state.
*/
checked: PropTypes.bool,
/**
* Description text below the radio.
*/
description: PropTypes.string,
/**
* A feedback state.
*/
Expand All @@ -66,6 +70,7 @@ Radio.propTypes = {

Radio.defaultProps = {
checked: false,
description: undefined,
feedback: undefined,
onChange: undefined,
onFocus: undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/Radio/Radio.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ const setChoice = event => {
label="e.Bill"
name="monthly-bill"
value="e.bill"
description="View your bill offline."
checked={state.choice === 'e.bill'}
onChange={setChoice}
/>
<Radio
label="Paper bill"
name="monthly-bill"
value="paper bill"
description="Receive your bill in the mail on a monthly basis."
checked={state.choice === 'paper bill'}
onChange={setChoice}
/>
Expand Down
7 changes: 7 additions & 0 deletions packages/Radio/__tests__/Radio.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Radio', () => {
return {
radio,
label: radio.find('label'),
description: () => radio.find('[data-testid="description"]'),
findRadioElement,
findFakeRadio: () => radio.find('[data-testid="fake-input"]'),
findFakeInnerRadio: () => radio.find('[data-testid="fake-inner-radio"]'),
Expand Down Expand Up @@ -50,6 +51,12 @@ describe('Radio', () => {
expect(label).toContainReact(<Text size="medium">Some label</Text>)
})

it('will display a description if defined', () => {
const { description } = doMount({ description: 'This is a description.' })

expect(description()).toContainReact(<Text size="small">This is a description.</Text>)
})

it('must have a name and a value', () => {
const { findRadioElement } = doMount({ name: 'some-radio-group', value: 'some-value' })

Expand Down

0 comments on commit dc418c6

Please sign in to comment.