Skip to content

Commit

Permalink
[Issue 157] move onConfirm to be after state
Browse files Browse the repository at this point in the history
Let the state be set with updated value then trigger
`onConfirm`
  • Loading branch information
Sam Tsai committed Aug 29, 2017
1 parent cb8a7c0 commit ad7fc95
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.preact.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.preact.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.react.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.react.min.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,21 @@ export default class Autocomplete extends Component {

handleComponentBlur (newState) {
const { options, query, selected } = this.state
let newQuery
let newQuery, setStateCallback

if (this.props.confirmOnBlur) {
newQuery = newState.query || query
this.props.onConfirm(options[selected])
setStateCallback = this.props.onConfirm(options[selected])
} else {
newQuery = query
setStateCallback = () => {}
}
this.setState({
focused: null,
menuOpen: newState.menuOpen || false,
query: newQuery,
selected: null
})
}, setStateCallback)
}

handleOptionBlur (event, index) {
Expand Down Expand Up @@ -266,13 +268,12 @@ export default class Autocomplete extends Component {
handleOptionClick (event, index) {
const selectedOption = this.state.options[index]
const newQuery = this.templateInputValue(selectedOption)
this.props.onConfirm(selectedOption)
this.setState({
focused: -1,
menuOpen: false,
query: newQuery,
selected: -1
})
}, this.props.onConfirm(selectedOption))
}

handleOptionMouseDown (event) {
Expand Down

0 comments on commit ad7fc95

Please sign in to comment.