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

[TextField] Fix initial scroll #7260

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/TextField/EnhancedTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EnhancedTextarea extends Component {
}

componentDidMount() {
this.syncHeightWithShadow();
this.syncHeightWithShadow(this.props.value);
}

componentWillReceiveProps(nextProps) {
Expand All @@ -79,7 +79,7 @@ class EnhancedTextarea extends Component {
}

handleResize = (event) => {
this.syncHeightWithShadow(undefined, event);
this.syncHeightWithShadow(this.props.value, event);
};

getInputNode() {
Expand Down
43 changes: 43 additions & 0 deletions src/TextField/EnhancedTextarea.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-env mocha */
import React from 'react';
import PropTypes from 'prop-types';
import {mount} from 'enzyme';
import {assert} from 'chai';
import EnhancedTextarea from './EnhancedTextarea';
import getMuiTheme from '../styles/getMuiTheme';

describe('<EnhancedTextArea />', () => {
const muiTheme = getMuiTheme();
const rowHeight = 24;
const mountWithContext = (node) => mount(node, {
context: {muiTheme},
childContextTypes: {muiTheme: PropTypes.object},
});

it('renders with no arguments', () => {
const wrapper = mountWithContext(
<EnhancedTextarea />
);
assert.isAbove(wrapper.find('div').length, 0);
});

it('has one row initial height', () => {
const wrapper = mountWithContext(
<EnhancedTextarea />
);
assert.strictEqual(wrapper.state().height, rowHeight);
});

// This test will not succeed due to
// jsdom limitations
// https://github.com/tmpvar/jsdom/issues/1013
/* eslint mocha/no-skipped-tests: 0 */
it.skip('has zero initial height', () => {
const wrapper = mountWithContext(
<EnhancedTextarea
value="A really long string that should go over multiple lines and should trigger more rows than one"
/>
);
assert.isAbove(wrapper.state().height, rowHeight);
});
});