From 374a073af57defc9918da639ecce2e194fc6a39d Mon Sep 17 00:00:00 2001 From: Robin Wijnant Date: Mon, 13 Jul 2020 13:46:29 +0200 Subject: [PATCH 1/2] fix(button): use value instead of defaultValue --- src/components/Radio/Radio.test.tsx | 10 +++++----- src/components/Radio/RadioGroup/RadioGroup.tsx | 13 ++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/Radio/Radio.test.tsx b/src/components/Radio/Radio.test.tsx index 98ca75d0..bc6aec34 100644 --- a/src/components/Radio/Radio.test.tsx +++ b/src/components/Radio/Radio.test.tsx @@ -6,7 +6,7 @@ import Radio from './Radio'; describe('Radio', () => { test('default snapshot', () => { const component = ( - + @@ -18,7 +18,7 @@ describe('Radio', () => { test('description snapshot', () => { const component = ( - + @@ -32,7 +32,7 @@ describe('Radio', () => { const onChangeFn = jest.fn(); const component = ( - + @@ -57,7 +57,7 @@ describe('Radio', () => { const onChangeFn = jest.fn(); const component = ( - + @@ -78,7 +78,7 @@ describe('Radio', () => { test('className prop', () => { const className = 'center'; const component = ( - + diff --git a/src/components/Radio/RadioGroup/RadioGroup.tsx b/src/components/Radio/RadioGroup/RadioGroup.tsx index f27aec07..3a8ca326 100644 --- a/src/components/Radio/RadioGroup/RadioGroup.tsx +++ b/src/components/Radio/RadioGroup/RadioGroup.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import classNames from 'classnames'; import cssReset from '../../../css-reset.module.css'; @@ -13,7 +13,7 @@ export interface RadioContext { export interface Props { children: React.ReactNode; - defaultValue?: RadioContext['selectedValue']; + value?: RadioContext['selectedValue']; name: string; onChange?: (e: React.ChangeEvent) => void; groupRef?: React.Ref; @@ -24,16 +24,13 @@ export const radioContext = React.createContext(null); const RadioGroup: React.FC = ({ children, - defaultValue, + value, onChange, name, groupRef, className, }: Props) => { - const [selectedValue, setSelectedValue] = useState(defaultValue); - const onRadioItemChange = (e: React.ChangeEvent) => { - setSelectedValue(e.target.value); if (onChange) { onChange(e); } @@ -41,8 +38,10 @@ const RadioGroup: React.FC = ({ const mergedClassNames = classNames(cssReset.ventura, styles.group, className); + const radioContextValues = { selectedValue: value, onChange: onRadioItemChange, name, groupRef }; + return ( - +
{children}
); From b1a1724728644e9bae7b4ef666f88726ceb835bd Mon Sep 17 00:00:00 2001 From: Robin Wijnant Date: Mon, 13 Jul 2020 21:50:27 +0200 Subject: [PATCH 2/2] update radio docs with value --- src/components/Radio/Radio.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Radio/Radio.mdx b/src/components/Radio/Radio.mdx index b90bd16f..79ea0288 100644 --- a/src/components/Radio/Radio.mdx +++ b/src/components/Radio/Radio.mdx @@ -19,12 +19,12 @@ import pythonImage from './docAssets/python.png' Radio buttons are made up of two components working together. The `Radio.Group` and `Radio.Item` component. -The `Radio.Group` component controls the name of the radio buttons and the onChange event. Each `Radio.Group` name property should be unique. The `Radio.Item` componet contains the value and label of the radio buttons. You add one `Radio.Item` per option. +The `Radio.Group` component controls the name of the radio buttons and the onChange event. Each `Radio.Group` name property should be unique. The `Radio.Item` component contains the value and label of the radio buttons. You add one `Radio.Item` per option. The `Radio.Item` component must be wrapped in a `Radio.Group` component to function properly. - + @@ -36,7 +36,7 @@ The `Radio.Item` component must be wrapped in a `Radio.Group` component to funct The label property on the button component also accepts JSX. This allows you to display custom components in the radio button label, like icons. - + Introduction To React} /> Introduction To Docker}/> Introduction To Python} /> @@ -46,7 +46,7 @@ The label property on the button component also accepts JSX. This allows you to ### Radio item with description - + @@ -56,7 +56,7 @@ The label property on the button component also accepts JSX. This allows you to ### Disabled radio items - +