Skip to content

Commit 69f841e

Browse files
authored
feat(radiogroup): radio group option key (#287)
key can be number | string | boolean
1 parent 10c0222 commit 69f841e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/components/radio/radio-group.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import Radio, { RadioProps } from './index';
66
// Utils
77
import randomString from '../../utils/randomString';
88

9+
type Value = string | number | boolean;
910
export type RadioGroupOption = {
10-
key: string;
11+
key: Value;
1112
text: string;
1213
additionalText?: string;
1314
};
1415
export interface RadioGroupProps
1516
extends Omit<RadioProps, 'label' | 'onChange' | 'options' | 'value'> {
16-
value: string | null;
17+
value: Value | null;
1718
options: string[] | RadioGroupOption[];
18-
onChange: (value: string) => void;
19+
onChange: (value: Value) => void;
1920
tooltipMessages?: {
2021
[key: string]: string;
2122
};
@@ -31,7 +32,7 @@ const RadioGroup: FC<RadioGroupProps> = ({
3132
...props
3233
}: RadioGroupProps) => {
3334
const handleChange = useCallback(
34-
(newValue: string) => () => {
35+
(newValue: Value) => () => {
3536
onChange(newValue);
3637
},
3738
[onChange],
@@ -48,15 +49,15 @@ const RadioGroup: FC<RadioGroupProps> = ({
4849
{mappedOptions?.map(({ key, text, additionalText }) => (
4950
<Radio
5051
{...props}
51-
key={key}
52+
key={`${key}`}
5253
mt={flexDirection === 'column' ? 2 : 'initial'}
5354
mr={flexDirection === 'row' ? '20px' : 'initial'}
5455
checked={value === key}
5556
label={text}
5657
name={name}
5758
addtionalText={additionalText}
5859
onChange={handleChange(key)}
59-
tooltip={tooltipMessages[key]}
60+
tooltip={tooltipMessages[`${key}`]}
6061
/>
6162
))}
6263
</Flex>

0 commit comments

Comments
 (0)