The current RadioGroup definition presents a problem because the labelStyle that is being applied on each RadioButton is the one that comes from Props, regardless of whether the RadioButton already has a labelStyle.
It should check if each button already has a labelStyle in the object, and if it doesn't it defaults to the one from the Props. Please take a look at the comments on the code below for better context.
export default function RadioGroup({
accessibilityLabel,
containerStyle,
labelStyle, /* <-- THIS IS THE ONLY LABELSTYLE THAT IS BEING CONSIDERED WHEN RENDERING */
layout = 'column',
onPress,
radioButtons,
selectedId,
testID
}: RadioGroupProps) {
function handlePress(id: string) {
if (id !== selectedId && onPress) {
onPress(id);
}
}
return (
<View
accessibilityLabel={accessibilityLabel}
accessibilityRole="radiogroup"
style={[styles.container, { flexDirection: layout }, containerStyle]}
testID={testID}
>
{radioButtons.map((button) => ( /* <-- IT NEVER CONSIDERS IF button HAS A LABEL STYLE */
<RadioButton
{...button}
key={button.id}
labelStyle={labelStyle} /* <-- APPLIES LABELSTYLE FROM PROPS, IGNORING LABELSTYLE FROM button */
selected={button.id === selectedId}
onPress={() => handlePress(button.id)}
/>
))}
</View>
)
}
The current RadioGroup definition presents a problem because the labelStyle that is being applied on each RadioButton is the one that comes from Props, regardless of whether the RadioButton already has a labelStyle.
It should check if each button already has a labelStyle in the object, and if it doesn't it defaults to the one from the Props. Please take a look at the comments on the code below for better context.