question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onValueChange in ToggleButton.Group is called with null

See original GitHub issue

Recreated 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

Snack

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:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
PunainenAurinkocommented, Jun 11, 2021

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.

1reaction
github-actions[bot]commented, Mar 3, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found