forked from jquense/react-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[added] disable individual dropdown/combobox options
Showing
9 changed files
with
146 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,68 @@ | ||
'use strict'; | ||
import React from 'react'; | ||
import filter from '../util/filter'; | ||
import { dataText } from '../util/dataHelpers'; | ||
import CustomPropTypes from '../util/propTypes'; | ||
import { isDisabledItem, isReadOnlyItem } from '../util/interaction'; | ||
|
||
module.exports = { | ||
const EMPTY_VALUE = {}; | ||
|
||
var isDisabledOrReadonly = (item, props) => isDisabledItem(item, props) || isReadOnlyItem(item, props) | ||
|
||
export default { | ||
|
||
propTypes: { | ||
textField: React.PropTypes.string | ||
textField: CustomPropTypes.accessor, | ||
valueField: CustomPropTypes.accessor, | ||
disabled: CustomPropTypes.disabled.acceptsArray, | ||
readOnly: CustomPropTypes.readOnly.acceptsArray | ||
}, | ||
|
||
first() { | ||
return this._data()[0] | ||
return this.next(EMPTY_VALUE) | ||
}, | ||
|
||
last() { | ||
var data = this._data() | ||
return data[data.length - 1] | ||
}, | ||
|
||
prev(item, word) { | ||
var textField = this.props.textField | ||
, data = this._data() | ||
, idx = data.indexOf(item) | ||
let data = this._data() | ||
, item = data[data.length - 1]; | ||
|
||
if (idx === -1) idx = data.length; | ||
|
||
return word | ||
? findPrevInstance(textField, data, word, idx) | ||
: --idx < 0 ? data[0] : data[idx] | ||
return isDisabledOrReadonly(item, this.props) | ||
? this.prev(item) : item | ||
}, | ||
|
||
next(item, word) { | ||
var textField = this.props.textField | ||
, data = this._data() | ||
, idx = data.indexOf(item) | ||
prev(item, word){ | ||
var data = this._data() | ||
, nextIdx = data.indexOf(item) | ||
, matches = matcher(word, item, this.props.textField); | ||
|
||
return word | ||
? findNextInstance(textField, data, word, idx) | ||
: ++idx === data.length ? data[data.length - 1] : data[idx] | ||
} | ||
if (nextIdx < 0 || nextIdx == null) | ||
nextIdx = 0 | ||
|
||
} | ||
nextIdx--; | ||
|
||
function findNextInstance(textField, data, word, startIndex){ | ||
var matches = filter.startsWith | ||
, idx = -1 | ||
, len = data.length | ||
, foundStart, itemText; | ||
while (nextIdx > -1 && (isDisabledOrReadonly(data[nextIdx], this.props) || !matches(data[nextIdx]))) | ||
nextIdx-- | ||
|
||
word = word.toLowerCase() | ||
return nextIdx >= 0 ? data[nextIdx] : item; | ||
}, | ||
|
||
while (++idx < len){ | ||
foundStart = foundStart || idx > startIndex | ||
itemText = foundStart && dataText(data[idx], textField).toLowerCase() | ||
next(item, word) { | ||
var data = this._data() | ||
, nextIdx = data.indexOf(item) + 1 | ||
, len = data.length | ||
, matches = matcher(word, item, this.props.textField); | ||
|
||
if( foundStart && matches(itemText, word) ) | ||
return data[idx] | ||
while (nextIdx < len && (isDisabledOrReadonly(data[nextIdx], this.props) || !matches(data[nextIdx]))) | ||
nextIdx++ | ||
|
||
return nextIdx < len ? data[nextIdx] : item | ||
} | ||
} | ||
|
||
function findPrevInstance(textField, data, word, startIndex){ | ||
var matches = filter.startsWith | ||
, idx = data.length | ||
, foundStart, itemText; | ||
function matcher(word, item, textField){ | ||
if (!word) return ()=> true | ||
|
||
word = word.toLowerCase() | ||
|
||
while (--idx >= 0 ){ | ||
foundStart = foundStart || idx < startIndex | ||
itemText = foundStart && dataText(data[idx], textField).toLowerCase() | ||
|
||
if( foundStart && matches(itemText, word) ) | ||
return data[idx] | ||
} | ||
return item => filter.startsWith( | ||
dataText(item, textField).toLowerCase() | ||
, word | ||
) | ||
} |