Skip to content

Commit bae4bac

Browse files
jensengclaydiffrient
authored andcommitted
Add onFocus property (#40)
* fix tests * make this required, because it is * add onFocus prop react doesn't yet support focusin (facebook/react#6410), so add a prop so we can know when something in this component has focus this is useful if you want to defer something until the user interacts with the component (e.g. trigger ajax to pre-fill a store)
1 parent c4311b1 commit bae4bac

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"babel-preset-stage-1": "^6.5.0",
3030
"chai": "^1.10.0",
3131
"eslint": "^1.10.1",
32+
"jsx-loader": "^0.13.2",
3233
"karma": "^0.13.0",
3334
"karma-chai": "^0.1.0",
3435
"karma-chrome-launcher": "^0.2.1",

src/combobox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var input = React.createFactory('input');
1111
module.exports = React.createClass({
1212

1313
propTypes: {
14+
onFocus: React.PropTypes.func,
15+
1416
/**
1517
* Called when the combobox receives user input, this is your chance to
1618
* filter the data and rerender the options.
@@ -44,6 +46,7 @@ module.exports = React.createClass({
4446
getDefaultProps: function() {
4547
return {
4648
autocomplete: 'both',
49+
onFocus: k,
4750
onInput: k,
4851
onSelect: k,
4952
value: null,
@@ -164,6 +167,7 @@ module.exports = React.createClass({
164167
},
165168

166169
handleInputFocus: function() {
170+
this.props.onFocus();
167171
this.maybeShowList();
168172
},
169173

src/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = React.createClass({
1010
propTypes: {
1111
isLoading: React.PropTypes.bool,
1212
loadingComponent: React.PropTypes.any,
13-
onInput: React.PropTypes.func,
13+
onFocus: React.PropTypes.func,
14+
onInput: React.PropTypes.func.isRequired,
1415
onSelect: React.PropTypes.func.isRequired,
1516
tokenAriaFunc: React.PropTypes.func,
1617
onRemove: React.PropTypes.func.isRequired,
@@ -31,6 +32,12 @@ module.exports = React.createClass({
3132
this.refs['combo-li'].querySelector('input').focus();
3233
},
3334

35+
handleFocus: function() {
36+
if (this.props.onFocus) {
37+
this.props.onFocus();
38+
}
39+
},
40+
3441
handleInput: function(inputValue) {
3542
this.props.onInput(inputValue);
3643
},
@@ -60,6 +67,7 @@ module.exports = React.createClass({
6067
return (
6168
Token({
6269
tokenAriaFunc: this.props.tokenAriaFunc,
70+
onFocus: this.handleFocus,
6371
onRemove: this.handleRemove,
6472
value: token,
6573
name: token.name,
@@ -78,6 +86,7 @@ module.exports = React.createClass({
7886
id: this.props.id,
7987
'aria-label': this.props['combobox-aria-label'],
8088
ariaDisabled: isDisabled,
89+
onFocus: this.handleFocus,
8190
onInput: this.handleInput,
8291
showListOnFocus: this.props.showListOnFocus,
8392
onSelect: this.handleSelect,

src/token.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = React.createClass({
2626
span({
2727
role: 'button',
2828
onClick: this.handleClick,
29+
onFocus: this.props.onFocus,
2930
onKeyDown: this.handleKeyDown,
3031
'aria-label': this.ariaLabelRemove(),
3132
className: "ic-token-delete-button",

0 commit comments

Comments
 (0)