UNPKG

698 BJavaScriptView Raw
1import getOptionLabel from './getOptionLabel';
2import { isFunction } from './nodash';
3
4function addCustomOption(results, props) {
5 var allowNew = props.allowNew,
6 labelKey = props.labelKey,
7 text = props.text;
8
9 if (!allowNew || !text.trim()) {
10 return false;
11 } // If the consumer has provided a callback, use that to determine whether or
12 // not to add the custom option.
13
14
15 if (isFunction(allowNew)) {
16 return allowNew(results, props);
17 } // By default, don't add the custom option if there is an exact text match
18 // with an existing option.
19
20
21 return !results.some(function (o) {
22 return getOptionLabel(o, labelKey) === text;
23 });
24}
25
26export default addCustomOption;
\No newline at end of file