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] Fix enter behavior with multiline when controlled #6992
Conversation
src/TextField/EnhancedTextarea.js
Outdated
@@ -126,7 +126,9 @@ class EnhancedTextarea extends Component { | |||
} | |||
|
|||
handleChange = (event) => { | |||
this.syncHeightWithShadow(event.target.value); | |||
if ( !this.props.hasOwnProperty('value') ) { |
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.
Would if (!this.props.value)) {
be enough?
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.
But, if the value is set as a falsy value, for example "" (an empty string), then if (!this.props.value) {
wouldn't work.
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.
Should good then!
A small unit test would make this PR perfect, otherwise, the logic looks good to me 👍 . We might need to port it back to the |
I have just started learning the testing frameworks mentioned [here] (https://github.com/callemall/material-ui/blob/master/test/README.md). Hoping to add a unit test soon. I've also started going through the |
it('does not change the height of text area', (done) => {
const wrapper = mountWithContext(
<TextField
onChange={() => {
const newHTML = wrapper.find('textarea').at(1).html();
assert.strictEqual(newHTML, initialHTML, 'should not change the height of the text area');
done();
}}
value="some value"
id="unique"
multiLine={true}
/>
);
const initialHTML = wrapper.find('textarea').at(1).html();
wrapper.find('textarea').at(1).simulate('change', {target: {value: '\n'}});
}); @oliviertassinari How does this look for a unit test? Since, there is not a good API in enzyme to extract the current style instance, this unit test validates the HTML instance itself. |
@sajal50 I would use the |
Thank you for your help, @oliviertassinari. For some reason, |
@sajal50 Thanks, I have removed that test as wasn't properly testing the behavior (it's green on master without the fix). Testing that part is hard without the test infrastructure we have on the |
Can't wait release with this one! :) |
@neemah It's done. |
Fixes #6990