Skip to content

Commit

Permalink
[SelectInput] Add "name" to event.target for onBlur callback (#12467)
Browse files Browse the repository at this point in the history
* As discussed in #12204 - added "name" to

- event.target for onBlur callback

* clone the onChange event logic
  • Loading branch information
hassan-zaheer authored and oliviertassinari committed Aug 11, 2018
1 parent f314576 commit 2094498
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class SelectInput extends React.Component {
}

if (this.props.onBlur) {
const { value, name } = this.props;
event.persist();
event.target = { value, name };
this.props.onBlur(event);
}
};
Expand Down
15 changes: 15 additions & 0 deletions packages/material-ui/src/Select/SelectInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ describe('<SelectInput />', () => {
assert.strictEqual(handleBlur.callCount, 1);
});

it('should pass "name" as part of the event.target for onBlur', () => {
const handleBlur = spy();
wrapper.setProps({ onBlur: handleBlur, name: 'blur-testing' });

wrapper.find(`.${defaultProps.classes.select}`).simulate('click');
assert.strictEqual(wrapper.state().open, true);
assert.strictEqual(instance.ignoreNextBlur, true);
wrapper.find(`.${defaultProps.classes.select}`).simulate('blur');
assert.strictEqual(handleBlur.callCount, 0);
assert.strictEqual(instance.ignoreNextBlur, false);
wrapper.find(`.${defaultProps.classes.select}`).simulate('blur');
assert.strictEqual(handleBlur.callCount, 1);
assert.strictEqual(handleBlur.args[0][0].target.name, 'blur-testing');
});

['space', 'up', 'down'].forEach(key => {
it(`'should open menu when pressed ${key} key on select`, () => {
wrapper
Expand Down

0 comments on commit 2094498

Please sign in to comment.