Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Commit

Permalink
eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Aug 8, 2016
1 parent cb5a8c1 commit d801f45
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions src/Select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default class Select extends Component {
if (this.dragging) return

// Clear the value
this.clearValue(event)
this.handleClearValue(event)
}

handleMouseDown = (event) => {
Expand Down Expand Up @@ -409,7 +409,7 @@ export default class Select extends Component {
if (this.state.isOpen) {
this.closeMenu()
} else if (this.props.clearable && this.props.escapeClearsValue) {
this.clearValue(event)
this.handleClearValue(event)
}
break
case 38: // up
Expand Down Expand Up @@ -468,20 +468,6 @@ export default class Select extends Component {
return (multi ? value.length === 0 : Object.keys(value).length === 0)
}

getValueArray = value => {
if (this.props.multi) {
let valueArray = value
if (typeof valueArray === 'string') valueArray = valueArray.split(this.props.delimiter)
if (!Array.isArray(valueArray)) {
if (valueArray === null || valueArray === undefined) return []
valueArray = [valueArray]
}
return valueArray.map(this.expandValue).filter(i => i)
}
const expandedValue = this.expandValue(value)
return expandedValue ? [expandedValue] : []
}

expandValue = (value) => {
if (typeof value !== 'string' && typeof value !== 'number') return value
const { options, valueKey } = this.props
Expand All @@ -499,7 +485,8 @@ export default class Select extends Component {
return undefined
}

setValue = (value) => {
setValue = newValue => {
let value = newValue
if (this.props.autoBlur) {
this.blurInput()
}
Expand Down Expand Up @@ -562,7 +549,7 @@ export default class Select extends Component {
this.focus()
}

clearValue = (event) => {
handleClearValue = event => {
// if the event was triggered by a mousedown and not the primary
// button, ignore it.
if (event && event.type === 'mousedown' && event.button !== 0) {
Expand Down Expand Up @@ -636,7 +623,7 @@ export default class Select extends Component {
focusedIndex = (focusedIndex + 1) % options.length
} else if (dir === 'previous') {
if (focusedIndex > 0) {
focusedIndex = focusedIndex - 1
focusedIndex -= 1
} else {
focusedIndex = options.length - 1
}
Expand Down Expand Up @@ -670,14 +657,7 @@ export default class Select extends Component {
})
}

selectFocusedOption = () => {
// if (this.props.allowCreate && !this.state.focusedOption) {
// return this.handleSelect(this.state.inputValue);
// }
if (this._focusedOption) {
return this.handleSelect(this._focusedOption)
}
}
selectFocusedOption = () => this._focusedOption && this.handleSelect(this._focusedOption)

createNewOption = (value) => {
let newOption = {}
Expand All @@ -696,6 +676,20 @@ export default class Select extends Component {

getOptionLabel = op => op[this.props.labelKey]

getValueArray = value => {
if (this.props.multi) {
let valueArray = value
if (typeof valueArray === 'string') valueArray = valueArray.split(this.props.delimiter)
if (!Array.isArray(valueArray)) {
if (valueArray === null || valueArray === undefined) return []
valueArray = [valueArray]
}
return valueArray.map(this.expandValue).filter(i => i)
}
const expandedValue = this.expandValue(value)
return expandedValue ? [expandedValue] : []
}

filterOptions = (excludeOptions) => {
let filterValue = this.state.inputValue
const originalFilterValue = filterValue
Expand All @@ -707,9 +701,9 @@ export default class Select extends Component {
if (this.props.ignoreCase) {
filterValue = filterValue.toLowerCase()
}
if (excludeOptions) excludeOptions = excludeOptions.map(i => i[this.props.valueKey])
const skipOptions = excludeOptions ? excludeOptions.map(i => i[this.props.valueKey]) : false
filteredOptions = options.filter(option => {
if (excludeOptions && excludeOptions.indexOf(option[this.props.valueKey]) > -1) return false
if (skipOptions && skipOptions.indexOf(option[this.props.valueKey]) > -1) return false
if (this.props.filterOption) return this.props.filterOption.call(this, option, filterValue)
if (!filterValue) return true
let valueTest = String(option[this.props.valueKey])
Expand Down Expand Up @@ -738,8 +732,11 @@ export default class Select extends Component {
if (this.props.allowCreate && filterValue) {
let addNewOption = true
// @TODO: only add the "Add" option if none of the options are an exact match
filteredOptions.map(option => {
if (String(option.label).toLowerCase() === filterValue || String(option.value).toLowerCase() === filterValue) {
filteredOptions.forEach(option => {
if (
String(option.label).toLowerCase() === filterValue ||
String(option.value).toLowerCase() === filterValue
) {
addNewOption = false
}
})
Expand Down Expand Up @@ -788,6 +785,8 @@ export default class Select extends Component {
</ValueComponent>
)
}

return false
}

renderInput(valueArray, focusedOptionIndex) {
Expand Down Expand Up @@ -830,16 +829,20 @@ export default class Select extends Component {

if (this.props.disabled || !this.props.searchable) {
return (
<div
<div // eslint-disable-line jsx-a11y/role-supports-aria-props
{...this.props.inputProps}
aria-activedescendant={
isOpen ?
`${this._instancePrefix}-option-${focusedOptionIndex}` :
`${this._instancePrefix}-value`
}
aria-expanded={isOpen}
aria-owns={isOpen ? this._instancePrefix + '-list' : this._instancePrefix + '-value'}
aria-readonly={`${!!this.props.disabled}`}
aria-owns={
isOpen ?
`${this._instancePrefix}-list` :
`${this._instancePrefix}-value`
}
aria-readonly={this.props.disabled}
className={className}
ref="input" // eslint-disable-line react/no-string-refs
role="combobox"
Expand Down Expand Up @@ -872,14 +875,14 @@ export default class Select extends Component {
this.props.disabled ||
this.props.isLoading
) {
return
return false
}
return (
<span
aria-label={this.props.multi ? this.props.clearAllText : this.props.clearValueText}
className="uk-component-select__clear uk-close"
title={this.props.multi ? this.props.clearAllText : this.props.clearValueText}
onMouseDown={this.clearValue}
onMouseDown={this.handleClearValue}
onTouchEnd={this.handleTouchEndClearValue}
onTouchMove={this.handleTouchMove}
onTouchStart={this.handleTouchStart}
Expand Down

0 comments on commit d801f45

Please sign in to comment.