UNPKG

1.8 kBJavaScriptView 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 _getMatchBounds = _interopRequireDefault(require("./getMatchBounds"));
11
12var _getOptionLabel = _interopRequireDefault(require("./getOptionLabel"));
13
14var _hasOwnProperty = _interopRequireDefault(require("./hasOwnProperty"));
15
16var _nodash = require("./nodash");
17
18function getHintText(_ref) {
19 var activeIndex = _ref.activeIndex,
20 initialItem = _ref.initialItem,
21 isFocused = _ref.isFocused,
22 isMenuShown = _ref.isMenuShown,
23 labelKey = _ref.labelKey,
24 multiple = _ref.multiple,
25 selected = _ref.selected,
26 text = _ref.text;
27
28 // Don't display a hint under the following conditions:
29 if ( // No text entered.
30 !text || // The input is not focused.
31 !isFocused || // The menu is hidden.
32 !isMenuShown || // No item in the menu.
33 !initialItem || // The initial item is a custom option.
34 !(0, _nodash.isString)(initialItem) && (0, _hasOwnProperty["default"])(initialItem, 'customOption') || // One of the menu items is active.
35 activeIndex > -1 || // There's already a selection in single-select mode.
36 !!selected.length && !multiple) {
37 return '';
38 }
39
40 var initialItemStr = (0, _getOptionLabel["default"])(initialItem, labelKey);
41 var bounds = (0, _getMatchBounds["default"])(initialItemStr.toLowerCase(), text.toLowerCase());
42
43 if (!(bounds && bounds.start === 0)) {
44 return '';
45 } // Text matching is case- and accent-insensitive, so to display the hint
46 // correctly, splice the input string with the hint string.
47
48
49 return text + initialItemStr.slice(bounds.end, initialItemStr.length);
50}
51
52var _default = getHintText;
53exports["default"] = _default;
\No newline at end of file