UNPKG

981 BJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = void 0;
9
10var _getOptionLabel = _interopRequireDefault(require("./getOptionLabel"));
11
12var _nodash = require("./nodash");
13
14function addCustomOption(results, props) {
15 var allowNew = props.allowNew,
16 labelKey = props.labelKey,
17 text = props.text;
18
19 if (!allowNew || !text.trim()) {
20 return false;
21 } // If the consumer has provided a callback, use that to determine whether or
22 // not to add the custom option.
23
24
25 if ((0, _nodash.isFunction)(allowNew)) {
26 return allowNew(results, props);
27 } // By default, don't add the custom option if there is an exact text match
28 // with an existing option.
29
30
31 return !results.some(function (o) {
32 return (0, _getOptionLabel["default"])(o, labelKey) === text;
33 });
34}
35
36var _default = addCustomOption;
37exports["default"] = _default;
\No newline at end of file