react-bootstrap-typeahead
Version:
React typeahead with Bootstrap styling
35 lines (25 loc) • 942 B
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _getOptionLabel = _interopRequireDefault(require("./getOptionLabel"));
function addCustomOption(results, props) {
var allowNew = props.allowNew,
labelKey = props.labelKey,
text = props.text;
if (!allowNew || !text.trim()) {
return false;
} // If the consumer has provided a callback, use that to determine whether or
// not to add the custom option.
if (typeof allowNew === 'function') {
return allowNew(results, props);
} // By default, don't add the custom option if there is an exact text match
// with an existing option.
return !results.some(function (o) {
return (0, _getOptionLabel["default"])(o, labelKey) === text;
});
}
var _default = addCustomOption;
exports["default"] = _default;