-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Position tooltip on value change #1205
Conversation
@@ -25,6 +25,10 @@ let Tooltip = React.createClass({ | |||
this._setRippleSize(); | |||
this._setTooltipPosition(); | |||
}, | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing spaces
The tooltip was not centered anymore after a value change (for example, localisation change). Triggering it again fixes it.
@@ -26,6 +26,10 @@ let Tooltip = React.createClass({ | |||
this._setTooltipPosition(); | |||
}, | |||
|
|||
componentWillReceiveProps() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @CumpsD - I think I might have misspoken on gitter because this may have to be done in componentDidUpdate
. Is this working for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works. If I did it in componentDidUpdate, I got a stack overflow,
getting into a loop.
On 21 Jul 2015 12:30 am, "Hai Nguyen" [email protected] wrote:
In src/tooltip.jsx
#1205 (comment):@@ -26,6 +26,10 @@ let Tooltip = React.createClass({
this._setTooltipPosition();
},
- componentWillReceiveProps() {
Thanks @CumpsD https://github.com/CumpsD - I think I might have
misspoken on gitter because this may have to be done in componentDidUpdate.
Is this working for you?—
Reply to this email directly or view it on GitHub
https://github.com/callemall/material-ui/pull/1205/files#r35051913.
_setTooltipPosition() should be protected against calling setState if the value did not change. Then I guess it will works in componentDidUpdate. But because it does a setState, it means render will always cause another render when offsetWidth change. (which is bad) Maybe offsetWidth should not be a state, and the offset should always be calculated and set in componentDidUpdate. |
would the css 'calc' function works in that case? |
I'll leave that to @hai-cea and @oliviertassinari since I don't know enough about it :/ |
Yeah, the current implementation can be improved. The component renders two times when he is mounted. This is bad. |
Is that something you can do? |
@oliviertassinari @cgestes Is there any harm in merging this and address the implementation improvement in a separate PR? |
is this commit correct? I think it calculates the offsetWidth of the previous render, not of the current one. |
@cgestes I thought it was wrong to when I did it at first, but it actually works. |
Looks good to me. |
Position tooltip on value change
Thanks @CumpsD ! |
The tooltip was not centered anymore after a value change (for example, localisation change). Triggering it again fixes it.