From 7ba4ac8990db63cdfce3ad46f311651194615289 Mon Sep 17 00:00:00 2001 From: "Ji H. Park" Date: Tue, 14 Jun 2022 08:54:47 -0500 Subject: [PATCH] set radio group input value to option.value (#539) * pass in options.value to input's value prop * add a unit test for value prop * update version Co-authored-by: Conor --- package.json | 2 +- src/forms/inputs/radio-group.js | 2 +- test/forms/inputs/radio-group.test.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0e7c1afb..86d39237 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@launchpadlab/lp-components", - "version": "6.0.1", + "version": "6.0.2", "engines": { "node": "^14.19 || ^16.14" }, diff --git a/src/forms/inputs/radio-group.js b/src/forms/inputs/radio-group.js index b0a11efb..c3bec610 100644 --- a/src/forms/inputs/radio-group.js +++ b/src/forms/inputs/radio-group.js @@ -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 } diff --git a/test/forms/inputs/radio-group.test.js b/test/forms/inputs/radio-group.test.js index 52caa88a..3bc3ba90 100644 --- a/test/forms/inputs/radio-group.test.js +++ b/test/forms/inputs/radio-group.test.js @@ -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() + expect(wrapper.find('input').first().prop('value')).toEqual('Option 1') + expect(wrapper.find('input').last().prop('value')).toEqual('Option 2') +}) \ No newline at end of file