callstack / react-native-paper

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

onValueChange in ToggleButton.Group is called with null #2452

Closed maxammann closed 3 years ago

maxammann commented 3 years ago

Current behaviour

onValueChange in ToggleButton.Group is called with null

Expected behaviour

I think it is fine to call it with null. In that case the TypeScript types need to be changed. We could also introduce a defaultValue prop which is used when no toggle button is selected.

Code sample

[Snack](https://snack.expo.io/i5_NrJH5x?name=ToggleButton.Group&description=https%3A%2F%2Fcallstack.github.io%2Freact-native-paper%2Ftoggle-button-group.html&code=import%20*%20as%20React%20from%20%27react%27%3B%0Aimport%20{%20ToggleButton%20}%20from%20%27react-native-paper%27%3B%0A%0Aconst%20MyComponent%20%3D%20()%20%3D%3E%20{%0A%20%20const%20[value%2C%20setValue]%20%3D%20React.useState(%27left%27)%3B%0A%0A%20%20return%20(%0A%20%20%20%20%3CToggleButton.Group%0A%20%20%20%20%20%20onValueChange%3D{value%20%3D%3E%20setValue(value)}%0A%20%20%20%20%20%20value%3D{value}%3E%0A%20%20%20%20%20%20%3CToggleButton%20icon%3D%22format-align-left%22%20value%3D%22left%22%20%2F%3E%0A%20%20%20%20%20%20%3CToggleButton%20icon%3D%22format-align-right%22%20value%3D%22right%22%20%2F%3E%0A%20%20%20%20%3C%2FToggleButton.Group%3E%0A%20%20)%3B%0A}%3B%0A%0Aexport%20default%20MyComponent%3B&dependencies=react-native-paper)

import * as React from 'react';
import { ToggleButton } from 'react-native-paper';

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

  return (
    <ToggleButton.Group
      onValueChange={value => {setValue(value); alert(value);}}
      value={value}>
      <ToggleButton icon="format-align-left" value="left" />
      <ToggleButton icon="format-align-right" value="right" />
    </ToggleButton.Group>
  );
};

export default MyComponent;

Your Environment

software version
ios or android android
react-native 0.63.4
react-native-vector-icons 7.1.0
react-native-paper 4.5.0
github-actions[bot] commented 3 years ago

Couldn't find version numbers for the following packages in the issue:

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

github-actions[bot] commented 3 years ago

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

github-actions[bot] commented 3 years ago

Hello 👋, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.

maxammann commented 3 years ago

Still happening: null is logged but type it not nullable:

maxammann commented 3 years ago

@Trancever should this be closed? Not sure who to contact :man_shrugging: