Skip to content

Commit

Permalink
wip: move onInputValueChange to setState function
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-drexler committed Oct 17, 2017
1 parent 5c0540a commit c7d998f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 8 additions & 7 deletions src/downshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,6 @@ class Downshift extends Component {
let onChangeArg
const onStateChangeArg = {}

if (stateToSet.hasOwnProperty('inputValue')) {
this.props.onInputValueChange(
stateToSet.inputValue,
this.getStateAndHelpers(),
)
}

return this.setState(
state => {
state = this.getState(state)
Expand All @@ -297,6 +290,14 @@ class Downshift extends Component {
onChangeArg = stateToSet.selectedItem
}
stateToSet.type = stateToSet.type || Downshift.stateChangeTypes.unknown

if (stateToSet.hasOwnProperty('inputValue')) {
this.props.onInputValueChange(stateToSet.inputValue, {
...this.getStateAndHelpers(),
...stateToSet,
})
}

Object.keys(stateToSet).forEach(key => {
// onStateChangeArg should only have the state that is
// actually changing
Expand Down
13 changes: 8 additions & 5 deletions stories/examples/input-bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ export default class InputBug extends React.Component {
}}
inputValue={this.state.inputValue}
>
{({getInputProps}) => (
<div>
<input {...getInputProps()} />
</div>
)}
{({getInputProps}) => {
console.log(getInputProps().value)
return (
<div>
<input {...getInputProps()} />
</div>
)
}}
</Downshift>
</div>
)
Expand Down

0 comments on commit c7d998f

Please sign in to comment.