Skip to content

Commit

Permalink
set radio group input value to option.value (#539)
Browse files Browse the repository at this point in the history
* pass in options.value to input's value prop

* add a unit test for value prop

* update version

Co-authored-by: Conor <[email protected]>
  • Loading branch information
jhp0621 and chawes13 authored Jun 14, 2022
1 parent eb83669 commit 7ba4ac8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchpadlab/lp-components",
"version": "6.0.1",
"version": "6.0.2",
"engines": {
"node": "^14.19 || ^16.14"
},
Expand Down
2 changes: 1 addition & 1 deletion src/forms/inputs/radio-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function RadioGroup (props) {
type: 'radio',
input: {
name, // all radio inputs must share the same name
value: '',
value: option.value,
onChange: () => onChange(option.value),
},
id: `${ name }.${ option.value }`, // override Input default behavior to assign id to input: { name }
Expand Down
14 changes: 14 additions & 0 deletions test/forms/inputs/radio-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ test('A RadioGroup\'s inputs all have the same name', () => {
expect(wrapper.find('input').first().prop('name')).toEqual(name)
expect(wrapper.find('input').last().prop('name')).toEqual(name)
})

test('A RadioGroup input has a value that matches the corresponding option\'s value', () => {
const props = {
input: {
name: 'test',
value: '',
},
meta: {},
options: ['Option 1', 'Option 2'],
}
const wrapper = mount(<RadioGroup {...props} />)
expect(wrapper.find('input').first().prop('value')).toEqual('Option 1')
expect(wrapper.find('input').last().prop('value')).toEqual('Option 2')
})

0 comments on commit 7ba4ac8

Please sign in to comment.