Skip to content

Commit

Permalink
fix(Dropdown): fix multiple problems with minCharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Jun 24, 2017
1 parent 0163591 commit 642fe6a
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ export default class Dropdown extends Component {
if (move === undefined) return
e.preventDefault()
this.moveSelectionBy(move)
if (!multiple) this.makeSelectedItemActive(e)
if (!multiple) this.makeSelectedItemActive(e, false)
}

openOnSpace = (e) => {
Expand All @@ -550,7 +550,7 @@ export default class Dropdown extends Component {
this.open(e)
}

makeSelectedItemActive = (e) => {
makeSelectedItemActive = (e, resetQuery = true) => {
const { open } = this.state
const { multiple, onAddItem } = this.props
const item = this.getSelectedItem()
Expand All @@ -568,10 +568,10 @@ export default class Dropdown extends Component {
if (multiple) {
// state value may be undefined
const newValue = _.union(this.state.value, [value])
this.setValue(newValue)
this.setValue(newValue, resetQuery)
this.handleChange(e, newValue)
} else {
this.setValue(value)
this.setValue(value, resetQuery)
this.handleChange(e, value)
}
}
Expand Down Expand Up @@ -657,6 +657,15 @@ export default class Dropdown extends Component {
if (this.searchRef) this.searchRef.focus()
}

handleIconClick = e => {
debug('handleIconClick()', e)

_.invoke(this.props, 'onClick', e, this.props)
// prevent handleClick()
e.stopPropagation()
this.toggle(e)
}

handleItemClick = (e, item) => {
debug('handleItemClick()')
debug(item)
Expand Down Expand Up @@ -852,12 +861,12 @@ export default class Dropdown extends Component {
// Setters
// ----------------------------------------

setValue = (value) => {
setValue = (value, resetQuery = true) => {
debug('setValue()')
debug('value', value)
const newState = {
const newState = resetQuery ? {
searchQuery: '',
}
} : {}

const { multiple, search } = this.props
if (multiple && search && this.searchRef) this.searchRef.focus()
Expand Down Expand Up @@ -953,6 +962,17 @@ export default class Dropdown extends Component {
this.scrollSelectedItemIntoView()
}

// ----------------------------------------
// Overrides
// ----------------------------------------

handleIconOverrides = predefinedProps => ({
onClick: (e, props) => {
_.invoke(predefinedProps, 'onClick', e, props)
this.handleIconClick(e)
},
})

// ----------------------------------------
// Refs
// ----------------------------------------
Expand Down Expand Up @@ -1264,7 +1284,9 @@ export default class Dropdown extends Component {
{this.renderSearchInput()}
{this.renderSearchSizer()}
{trigger || this.renderText()}
{Icon.create(icon)}
{Icon.create(icon, {
overrideProps: this.handleIconOverrides,
})}
{this.renderMenu()}
</ElementType>
)
Expand Down

0 comments on commit 642fe6a

Please sign in to comment.