-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[TextField] sync height with shadow when rowsMax
changed
#6297
Conversation
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 for taking the initiative to address the issue.
src/TextField/EnhancedTextarea.js
Outdated
@@ -75,6 +75,12 @@ class EnhancedTextarea extends Component { | |||
} | |||
} | |||
|
|||
componentDidUpdate(prevProps) { |
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.
We shouldn't need that hook. componentWillReceiveProps
should be enough.
I think that the issue is coming from syncHeightWithShadow
using the old maxHeight value and not the up coming one. Does that makes sens 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.
Yes, the actual problem is, that syncHeightWithShadow
is using this.props.rowsMax
, which will contain the value before the property was changed. Thus the function also calculates the height for the old value.
This is the "culprit":
if (this.props.rowsMax >= this.props.rows) {
newHeight = Math.min(this.props.rowsMax * rowsHeight, newHeight);
}
Another solution to this can be to call syncHeightWithShadow
with an additional argument props
and using them instead of this.props
-- syncHeightWithShadow(newValue, event, props)
.
I think its a slightly better solution, since syncHeightWithShadow
won't be called twice.
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.
That looks good to me 👍
This will adjust the height of the component when
rowsMax
property has changed.Currently I am using this to expand the
EnhancedTextarea
when the element gains focus (and reset it when it blurs).