onValueChange in ToggleButton.Group is called with null
See original GitHub issueRecreated from https://github.com/callstack/react-native-paper/issues/2452 as the last one was closed without any comment.
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
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 | 8.1.0 |
react-native-paper | 4.7.2 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
I am not getting the value onchange of togglebuttongroup ...
Using the example of the react website you can get the value through a parameter in the (your) handleChange function.
Read more >ToggleButtonGroup API - Material UI - MUI
... ToggleButton values to be selected. fullWidth, bool, false. If true , the button group will take up the full width of its...
Read more >How to read Lightning Checkbox toggle button value or ...
I read the value or checked status inside the input-->onchange() as below. var toggleButton = component.find('swtichAllItems'); if (toggleButton ...
Read more >react-native-toggle-buttons - npm
Available ToggleButton.Group Props ; selected, null, selected value ; space, 0, space between buttons ; buttonStyle, {}, button style ; color, 'gray', buttons...
Read more >Angular PrimeNG ToggleButton Component - GeeksforGeeks
ariaLabel: It is used to define a string that labels the input element, It is of string data type, the default value is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the problem here is the ‘correct behavior’ of being able to deselect the toggle value. I think we need to have an option of preventing the deselect (and the resulting null value) from happening. I want the tap on the already selected item to do nothing (to not deselect the value). I am switching between views on toggle button taps, and deselecting the value switches to a next view, which is very confusing.
The versions mentioned in the issue for the following packages differ from the latest versions on npm:
react-native-vector-icons
(found:7.1.0
, latest:8.1.0
)react-native-paper
(found:4.5.0
, latest:4.7.2
)Can you verify that the issue still exists after upgrading to the latest versions of these packages?