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

Position tooltip on value change #1205

Merged
merged 1 commit into from
Aug 24, 2015
Merged

Position tooltip on value change #1205

merged 1 commit into from
Aug 24, 2015

Conversation

CumpsD
Copy link
Contributor

@CumpsD CumpsD commented Jul 19, 2015

The tooltip was not centered anymore after a value change (for example, localisation change). Triggering it again fixes it.

@@ -25,6 +25,10 @@ let Tooltip = React.createClass({
this._setRippleSize();
this._setTooltipPosition();
},

Copy link
Member

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() {
Copy link
Member

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?

Copy link
Contributor Author

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" notifications@github.com 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.

@cgestes
Copy link
Contributor

cgestes commented Jul 20, 2015

_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.

@cgestes
Copy link
Contributor

cgestes commented Jul 20, 2015

would the css 'calc' function works in that case?

@CumpsD
Copy link
Contributor Author

CumpsD commented Jul 20, 2015

I'll leave that to @hai-cea and @oliviertassinari since I don't know enough about it :/

@oliviertassinari
Copy link
Member

Yeah, the current implementation can be improved. The component renders two times when he is mounted. This is bad.
The solution is to remove offsetWidth from the state. Then either use css tricks to make the tooltip centered or use vanilla js.

@CumpsD
Copy link
Contributor Author

CumpsD commented Jul 20, 2015

Is that something you can do?

@hai-cea
Copy link
Member

hai-cea commented Jul 22, 2015

@oliviertassinari @cgestes Is there any harm in merging this and address the implementation improvement in a separate PR?

@cgestes
Copy link
Contributor

cgestes commented Jul 22, 2015

is this commit correct? I think it calculates the offsetWidth of the previous render, not of the current one.

@CumpsD
Copy link
Contributor Author

CumpsD commented Jul 22, 2015

@cgestes I thought it was wrong to when I did it at first, but it actually works.

@CumpsD
Copy link
Contributor Author

CumpsD commented Aug 24, 2015

A visual explanation:

Start:
image

Tooltip updated:
image

Using the fix from this PR:

Start:
image

Tooltip updated:
image

@hai-cea
Copy link
Member

hai-cea commented Aug 24, 2015

Looks good to me.

hai-cea added a commit that referenced this pull request Aug 24, 2015
Position tooltip on value change
@hai-cea hai-cea merged commit d192c1b into mui:master Aug 24, 2015
@hai-cea
Copy link
Member

hai-cea commented Aug 24, 2015

Thanks @CumpsD !

@zannager zannager added the component: tooltip This is the name of the generic UI component, not the React module! label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tooltip This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants