callstack / react-native-paper

Material Design for React Native (Android & iOS)
https://reactnativepaper.com
MIT License
12.76k stars 2.08k forks source link

Segmented Buttons component should have 'disabled' prop #4371

Closed jairaja closed 4 months ago

jairaja commented 5 months ago

Is your feature request related to a problem? Please describe. Need to disable whole 'Segmented Buttons component, instead of individual buttons

Describe the solution you'd like 'disabled' prop in SegmentedButtons Props

Describe alternatives you've considered Currently using 'disabled' prop on all buttons within SegmentedButtons

Additional context Add any other context or screenshots about the feature request here.

gedu commented 4 months ago

Hey, as you said the only way for now is disabled individual buttons, if you wanna disable all of them at the same time I would suggest using just one flag:

const MyComponent = () => {
  const [value, setValue] = useState('');
  const [disableAll, setDisableAll] = React.useState(false);

  return (
    <SafeAreaView style={styles.container}>
      <SegmentedButtons
        value={value}
        onValueChange={setValue}
        buttons={[
          {
            value: 'walk',
            label: 'Walking',
            disabled: disableAll,
          },
          {
            value: 'train',
            label: 'Transit',
            disabled: disableAll,
          },
          { value: 'drive', label: 'Driving', disabled: disableAll, },
        ]}
      />
    </SafeAreaView>
  );
};

We don't see the need of one prop to disable all the buttons, that can complicate the logic and maintainability. Thanks