Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputSwitch doesn't update programmatically #461

Closed
byoder7 opened this issue Jun 26, 2018 · 2 comments
Closed

InputSwitch doesn't update programmatically #461

byoder7 opened this issue Jun 26, 2018 · 2 comments
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@byoder7
Copy link

byoder7 commented Jun 26, 2018

Let me first start off by saying I LOVE, LOVE PrimeReact!! Great job on that!

I'm submitting a ... (check one with "x")

[X ] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

Plunkr Case (Bug Reports)
Please fork the plunkr below and create a case demonstrating your bug report. Issues without a plunkr have much less possibility to be reviewed.

https://plnkr.co/edit/C6qjkdLtbmy92Hogdnjb?p=preview

Current behavior
When you update state, that changes the "checked" value from true/false then the state of the UI doesn't change. It only seems to properly set the state initially (componentDidMount) and subsequently when using checkUI or UncheckUI. So the UI becomes out of sync with the state.

ALSO - I've looked at the latest source code for InputSwitch and i believe you need to add this... Because you are ONLY updating the DIV widths (on/off sizes) in the componentWillMount - which I think is only called once initially, that leaves subsequent updates (via prop changes, not using the UI control) will not sync the UI.

*** NEED TO ADD THIS TO THE InputSwitch component ***

componentWillReceiveProps(nextProps) {
if (this.props.checked !== nextProps.checked) {
if (nextProps.checked) {
this.checkUI();
} else {
this.uncheckUI();
}
}
}

Expected behavior
State and UI should always be in SYNC.

Minimal reproduction of the problem with instructions
Just create another way to update state value, that passes as checked value to the InputSwitch.

Please tell us about your environment:

  • React version:
    React 16.x

  • PrimeReact version:
    1.5.2

  • **Browser:**Chrome

  • Language: [all | TypeScript X.X | ES6/7 | ES5]

@robbevwinckel
Copy link

componentWillReceiveProps will be deprecated in the next version of React. Should probably use componentDidUpdate or getDerivedStateFromProps.

@cagataycivici cagataycivici self-assigned this Jul 18, 2018
@cagataycivici cagataycivici added the Type: Bug Issue contains a defect related to a specific component. label Jul 18, 2018
@cagataycivici cagataycivici added this to the 2.0.0-beta.1 milestone Jul 18, 2018
@cagataycivici cagataycivici changed the title InputSwitch doesn't update when value changes via props (outside of UI click) InputSwitch doesn't update programmatically Jul 18, 2018
@cagataycivici
Copy link
Member

cagataycivici commented Jul 18, 2018

I've reimplemeted the inputswitch as below and checked this case as well, it works with the new one. It does not use any lifecycle callback as there is no need for this component.

screen shot 2018-07-18 at 14 55 19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

3 participants