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

[AutoComplete] Fix overriding TextField value and onChange prop #6642

Merged
merged 4 commits into from
Apr 18, 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
7 changes: 5 additions & 2 deletions src/AutoComplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,6 @@ class AutoComplete extends Component {
<TextField
ref="searchTextField"
autoComplete="off"
value={searchText}
onChange={this.handleChange}
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onKeyDown={this.handleKeyDown}
Expand All @@ -521,7 +519,12 @@ class AutoComplete extends Component {
multiLine={false}
errorStyle={errorStyle}
style={textFieldStyle}

{...other}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment for the why? Thanks

Copy link
Contributor Author

@avocadowastaken avocadowastaken Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Is there anything else?

// Do not let to override these values to not break internal functionality.
value={searchText}
onChange={this.handleChange}
/>
<Popover
style={Object.assign({}, styles.popover, popoverStyle)}
Expand Down
43 changes: 43 additions & 0 deletions src/AutoComplete/AutoComplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {spy} from 'sinon';
import AutoComplete from './AutoComplete';
import Menu from '../Menu/Menu';
import Popover from '../Popover/Popover';
import TextField from '../TextField/TextField';
import getMuiTheme from '../styles/getMuiTheme';

describe('<AutoComplete />', () => {
Expand Down Expand Up @@ -61,6 +62,48 @@ describe('<AutoComplete />', () => {
});
});

describe('prop: value', () => {
it('should not override value prop of TextField', () => {
const wrapper = shallowWithContext(
<AutoComplete
value={{name: 'foo'}}
dataSource={['foo', 'bar']}
searchText="f"
menuCloseDelay={10}
/>
);

assert.strictEqual(wrapper.find(TextField).props().value, 'f');
});
});

describe('prop: onChange', () => {
it('should not override onChange prop of TextField', (done) => {
const onChange = spy();

const wrapper = shallowWithContext(
<AutoComplete
onChange={onChange}
dataSource={['foo', 'bar']}
searchText="f"
menuCloseDelay={10}
/>
);

wrapper.find(TextField).props().onChange({target: {value: 'fo'}});

setTimeout(() => {
try {
assert.strictEqual(onChange.callCount, 0);

done();
} catch (error) {
done(error);
}
}, 20);
});
});

describe('prop: onNewRequest', () => {
it('should call onNewRequest once the popover is closed', (done) => {
const handleNewRequest = spy();
Expand Down