1 | import getMatchBounds from './getMatchBounds';
|
2 | import getOptionLabel from './getOptionLabel';
|
3 | import hasOwnProperty from './hasOwnProperty';
|
4 | import { isString } from './nodash';
|
5 |
|
6 | function getHintText(_ref) {
|
7 | var activeIndex = _ref.activeIndex,
|
8 | initialItem = _ref.initialItem,
|
9 | isFocused = _ref.isFocused,
|
10 | isMenuShown = _ref.isMenuShown,
|
11 | labelKey = _ref.labelKey,
|
12 | multiple = _ref.multiple,
|
13 | selected = _ref.selected,
|
14 | text = _ref.text;
|
15 |
|
16 |
|
17 | if (
|
18 | !text ||
|
19 | !isFocused ||
|
20 | !isMenuShown ||
|
21 | !initialItem ||
|
22 | !isString(initialItem) && hasOwnProperty(initialItem, 'customOption') ||
|
23 | activeIndex > -1 ||
|
24 | !!selected.length && !multiple) {
|
25 | return '';
|
26 | }
|
27 |
|
28 | var initialItemStr = getOptionLabel(initialItem, labelKey);
|
29 | var bounds = getMatchBounds(initialItemStr.toLowerCase(), text.toLowerCase());
|
30 |
|
31 | if (!(bounds && bounds.start === 0)) {
|
32 | return '';
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 | return text + initialItemStr.slice(bounds.end, initialItemStr.length);
|
38 | }
|
39 |
|
40 | export default getHintText; |
\ | No newline at end of file |