UNPKG

react-bootstrap-typeahead

Version:
49 lines (47 loc) 1.79 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _getMatchBounds = _interopRequireDefault(require("./getMatchBounds")); var _getOptionLabel = _interopRequireDefault(require("./getOptionLabel")); var _hasOwnProperty = _interopRequireDefault(require("./hasOwnProperty")); var _nodash = require("./nodash"); function getHintText(_ref) { var activeIndex = _ref.activeIndex, initialItem = _ref.initialItem, isFocused = _ref.isFocused, isMenuShown = _ref.isMenuShown, labelKey = _ref.labelKey, multiple = _ref.multiple, selected = _ref.selected, text = _ref.text; // Don't display a hint under the following conditions: if ( // No text entered. !text || // The input is not focused. !isFocused || // The menu is hidden. !isMenuShown || // No item in the menu. !initialItem || // The initial item is a custom option. !(0, _nodash.isString)(initialItem) && (0, _hasOwnProperty["default"])(initialItem, 'customOption') || // One of the menu items is active. activeIndex > -1 || // There's already a selection in single-select mode. !!selected.length && !multiple) { return ''; } var initialItemStr = (0, _getOptionLabel["default"])(initialItem, labelKey); var bounds = (0, _getMatchBounds["default"])(initialItemStr.toLowerCase(), text.toLowerCase()); if (!(bounds && bounds.start === 0)) { return ''; } // Text matching is case- and accent-insensitive, so to display the hint // correctly, splice the input string with the hint string. return text + initialItemStr.slice(bounds.end, initialItemStr.length); } var _default = exports["default"] = getHintText;