Skip to content

Commit

Permalink
Merge pull request JedWatson#1248 from IvanLeonenko/creatable-input-keys
Browse files Browse the repository at this point in the history
Fix for Creatable doesn't allow input key down handling. Issue JedWatson#1247
  • Loading branch information
JedWatson authored Sep 25, 2016
2 parents 3b7dad8 + d2ff4a9 commit 962f138
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const Creatable = React.createClass({
},

onInputKeyDown (event) {
const { shouldKeyDownEventCreateNewOption } = this.props;
const { shouldKeyDownEventCreateNewOption, onInputKeyDown } = this.props;
const focusedOption = this.select.getFocusedOption();

if (
Expand All @@ -169,6 +169,8 @@ const Creatable = React.createClass({

// Prevent decorated Select from doing anything additional with this keyDown event
event.preventDefault();
} else if (onInputKeyDown) {
onInputKeyDown(event);
}
},

Expand Down
5 changes: 5 additions & 0 deletions test/Creatable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,9 @@ describe('Creatable', () => {
expect(test(188), 'to be', true);
expect(test(1), 'to be', false);
});

it('default :onInputKeyDown should run user provided handler.', (done) => {
createControl({ onInputKeyDown: event => done() });
return creatableInstance.onInputKeyDown({ keyCode: 97 });
});
});

0 comments on commit 962f138

Please sign in to comment.