-
Notifications
You must be signed in to change notification settings - Fork 83
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
Resizing the window sets needle back to original position. #35
Comments
I was able to get around this by unmounting and remounting the component every time I change the value instead of relying on prop change to update, That way when it does resize there's no prevProps for it to look at. |
Receiving this as well. Had to put extra logic in to ensure that the gauge never received zero data before my state was changed with it's final set of data. |
I'm having the same issue here, but it is triggered by scrolling down to the bottom of the page on mobile. I also made a sandbox to confirm this with the resize reset. Click the button then resize the window. Can we turn this issue report into an official bug? |
Moved window resize listener into useEffect to prevent resetting values to default on window resize. Fixes issue Martin36#35
Thanks for merge - this issue can now be closed. |
I was able to keep using react-gauge-chart at version 0.3.0, and followed an above recommendation: (base) jeff1evesque@AlienWareMacBook supercode % git diff jsx
diff --git a/jsx/import/xyz/flashy-popsicles.jsx b/jsx/import/xyz/flashy-popsicles.jsx
index 12b62c2..e9bfa63 100644
--- a/jsx/import/xyz/flashy-popsicles.jsx
+++ b/jsx/import/xyz/flashy-popsicles.jsx
@@ -110,6 +110,21 @@ class Chart extends Component {
colors: colors,
arcs_length: arcs_length
}
+
+ this.resize = this.resize.bind(this);
+ }
+
+ resize() {
+ if (
+ 'percent' in this.props
+ && checkValidFloat(this.props.percent)
+ ) {
+ this.setState({ percent: this.props.percent });
+ }
+ }
+
+ componentDidMount() {
+ window.addEventListener('resize', this.resize);
}
componentDidUpdate(prevProps, prevState) {
(base) jeff1evesque@AlienWareMacBook supercode % |
My workaround is still a bit glitchy, since its not very smooth between transition of the needle being forced to a (re)render on window resize. |
If I have a Gauge where I frequently update the percent and then the window resizes it will set the needle back to whatever the first percent I passed was.
Here is an example. let the gauge update twice and then resize the window you will see it go back to the original
https://codesandbox.io/s/pedantic-heisenberg-03qd1?fontsize=14&hidenavigation=1&theme=dark
The text was updated successfully, but these errors were encountered: