ThakurBallary / react-native-radio-buttons-group

Simple, best and easy to use radio buttons for react native apps.
MIT License
248 stars 70 forks source link

LabelStyle from RadioButton not being considered, only labelStyle from RadioGroup is. #71

Closed jdrodriguezh closed 4 months ago

jdrodriguezh commented 4 months ago

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>
  )
}
ThakurBallary commented 4 months ago

@jdrodriguezh thanks for the PR. Your changes are released in v3.0.8