@patternfly/react-core 5.0.0-alpha.62 → 5.0.0-alpha.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/esm/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
- package/dist/esm/components/CalendarMonth/CalendarMonth.js +9 -11
- package/dist/esm/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/dist/esm/components/DualListSelector/DualListSelectorControl.d.ts +1 -1
- package/dist/esm/components/Menu/MenuItem.d.ts +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.d.ts.map +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.js +3 -1
- package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/esm/components/Select/Select.d.ts +26 -192
- package/dist/esm/components/Select/Select.d.ts.map +1 -1
- package/dist/esm/components/Select/Select.js +51 -935
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/SelectGroup.d.ts +7 -8
- package/dist/esm/components/Select/SelectGroup.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectGroup.js +4 -7
- package/dist/esm/components/Select/SelectGroup.js.map +1 -1
- package/dist/{js/next → esm}/components/Select/SelectList.d.ts +1 -1
- package/dist/esm/components/Select/SelectList.d.ts.map +1 -0
- package/dist/esm/{next/components → components}/Select/SelectList.js +1 -1
- package/dist/esm/components/Select/SelectList.js.map +1 -0
- package/dist/esm/components/Select/SelectOption.d.ts +13 -66
- package/dist/esm/components/Select/SelectOption.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectOption.js +6 -192
- package/dist/esm/components/Select/SelectOption.js.map +1 -1
- package/dist/esm/components/Select/index.d.ts +1 -1
- package/dist/esm/components/Select/index.d.ts.map +1 -1
- package/dist/esm/components/Select/index.js +1 -1
- package/dist/esm/components/Select/index.js.map +1 -1
- package/dist/esm/deprecated/components/Select/Select.d.ts +199 -0
- package/dist/esm/deprecated/components/Select/Select.d.ts.map +1 -0
- package/dist/esm/deprecated/components/Select/Select.js +940 -0
- package/dist/esm/deprecated/components/Select/Select.js.map +1 -0
- package/dist/esm/deprecated/components/Select/SelectGroup.d.ts +13 -0
- package/dist/esm/deprecated/components/Select/SelectGroup.d.ts.map +1 -0
- package/dist/esm/deprecated/components/Select/SelectGroup.js +13 -0
- package/dist/esm/deprecated/components/Select/SelectGroup.js.map +1 -0
- package/dist/esm/deprecated/components/Select/SelectMenu.d.ts.map +1 -0
- package/dist/esm/{components → deprecated/components}/Select/SelectMenu.js +1 -1
- package/dist/esm/deprecated/components/Select/SelectMenu.js.map +1 -0
- package/dist/esm/deprecated/components/Select/SelectOption.d.ts +73 -0
- package/dist/esm/deprecated/components/Select/SelectOption.d.ts.map +1 -0
- package/dist/esm/deprecated/components/Select/SelectOption.js +196 -0
- package/dist/esm/deprecated/components/Select/SelectOption.js.map +1 -0
- package/dist/esm/deprecated/components/Select/SelectToggle.d.ts.map +1 -0
- package/dist/esm/{components → deprecated/components}/Select/SelectToggle.js +2 -2
- package/dist/esm/deprecated/components/Select/SelectToggle.js.map +1 -0
- package/dist/esm/{next → deprecated}/components/Select/index.d.ts +1 -1
- package/dist/esm/deprecated/components/Select/index.d.ts.map +1 -0
- package/dist/esm/{next → deprecated}/components/Select/index.js +1 -1
- package/dist/esm/deprecated/components/Select/index.js.map +1 -0
- package/dist/esm/deprecated/components/Select/selectConstants.d.ts.map +1 -0
- package/dist/esm/deprecated/components/Select/selectConstants.js.map +1 -0
- package/dist/esm/deprecated/components/index.d.ts +1 -0
- package/dist/esm/deprecated/components/index.d.ts.map +1 -1
- package/dist/esm/deprecated/components/index.js +1 -0
- package/dist/esm/deprecated/components/index.js.map +1 -1
- package/dist/esm/next/components/index.d.ts +0 -1
- package/dist/esm/next/components/index.d.ts.map +1 -1
- package/dist/esm/next/components/index.js +0 -1
- package/dist/esm/next/components/index.js.map +1 -1
- package/dist/js/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
- package/dist/js/components/CalendarMonth/CalendarMonth.js +8 -10
- package/dist/js/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/dist/js/components/DualListSelector/DualListSelectorControl.d.ts +1 -1
- package/dist/js/components/Menu/MenuItem.d.ts +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.d.ts.map +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.js +3 -1
- package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/js/components/Select/Select.d.ts +26 -192
- package/dist/js/components/Select/Select.d.ts.map +1 -1
- package/dist/js/components/Select/Select.js +51 -936
- package/dist/js/components/Select/Select.js.map +1 -1
- package/dist/js/components/Select/SelectGroup.d.ts +7 -8
- package/dist/js/components/Select/SelectGroup.d.ts.map +1 -1
- package/dist/js/components/Select/SelectGroup.js +4 -7
- package/dist/js/components/Select/SelectGroup.js.map +1 -1
- package/dist/{esm/next → js}/components/Select/SelectList.d.ts +1 -1
- package/dist/js/components/Select/SelectList.d.ts.map +1 -0
- package/dist/js/{next/components → components}/Select/SelectList.js +1 -1
- package/dist/js/components/Select/SelectList.js.map +1 -0
- package/dist/js/components/Select/SelectOption.d.ts +13 -66
- package/dist/js/components/Select/SelectOption.d.ts.map +1 -1
- package/dist/js/components/Select/SelectOption.js +7 -193
- package/dist/js/components/Select/SelectOption.js.map +1 -1
- package/dist/js/components/Select/index.d.ts +1 -1
- package/dist/js/components/Select/index.d.ts.map +1 -1
- package/dist/js/components/Select/index.js +1 -1
- package/dist/js/components/Select/index.js.map +1 -1
- package/dist/js/deprecated/components/Select/Select.d.ts +199 -0
- package/dist/js/deprecated/components/Select/Select.d.ts.map +1 -0
- package/dist/js/deprecated/components/Select/Select.js +944 -0
- package/dist/js/deprecated/components/Select/Select.js.map +1 -0
- package/dist/js/deprecated/components/Select/SelectGroup.d.ts +13 -0
- package/dist/js/deprecated/components/Select/SelectGroup.d.ts.map +1 -0
- package/dist/js/deprecated/components/Select/SelectGroup.js +17 -0
- package/dist/js/deprecated/components/Select/SelectGroup.js.map +1 -0
- package/dist/js/deprecated/components/Select/SelectMenu.d.ts.map +1 -0
- package/dist/js/{components → deprecated/components}/Select/SelectMenu.js +1 -1
- package/dist/js/deprecated/components/Select/SelectMenu.js.map +1 -0
- package/dist/js/deprecated/components/Select/SelectOption.d.ts +73 -0
- package/dist/js/deprecated/components/Select/SelectOption.d.ts.map +1 -0
- package/dist/js/deprecated/components/Select/SelectOption.js +200 -0
- package/dist/js/deprecated/components/Select/SelectOption.js.map +1 -0
- package/dist/js/deprecated/components/Select/SelectToggle.d.ts.map +1 -0
- package/dist/js/{components → deprecated/components}/Select/SelectToggle.js +2 -2
- package/dist/js/deprecated/components/Select/SelectToggle.js.map +1 -0
- package/dist/js/{next → deprecated}/components/Select/index.d.ts +1 -1
- package/dist/js/deprecated/components/Select/index.d.ts.map +1 -0
- package/dist/js/{next → deprecated}/components/Select/index.js +1 -1
- package/dist/js/deprecated/components/Select/index.js.map +1 -0
- package/dist/js/deprecated/components/Select/selectConstants.d.ts.map +1 -0
- package/dist/js/deprecated/components/Select/selectConstants.js.map +1 -0
- package/dist/js/deprecated/components/index.d.ts +1 -0
- package/dist/js/deprecated/components/index.d.ts.map +1 -1
- package/dist/js/deprecated/components/index.js +1 -0
- package/dist/js/deprecated/components/index.js.map +1 -1
- package/dist/js/next/components/index.d.ts +0 -1
- package/dist/js/next/components/index.d.ts.map +1 -1
- package/dist/js/next/components/index.js +0 -1
- package/dist/js/next/components/index.js.map +1 -1
- package/dist/umd/react-core.min.js +3 -3
- package/package.json +2 -2
- package/src/components/CalendarMonth/CalendarMonth.tsx +25 -15
- package/src/components/DatePicker/__tests__/__snapshots__/DatePicker.test.tsx.snap +22 -31
- package/src/components/LoginPage/examples/LoginPageLanguageSelect.tsx +28 -19
- package/src/components/MenuToggle/MenuToggle.tsx +2 -1
- package/src/components/MenuToggle/__tests__/__snapshots__/MenuToggle.test.tsx.snap +18 -10
- package/src/components/MenuToggle/examples/MenuToggle.md +85 -78
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonAction.tsx +10 -11
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckbox.tsx +4 -17
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckboxWithText.tsx +10 -11
- package/src/components/MenuToggle/examples/MenuToggleTypeahead.tsx +35 -0
- package/src/components/Select/Select.tsx +113 -1475
- package/src/components/Select/SelectGroup.tsx +13 -25
- package/src/{next/components → components}/Select/SelectList.tsx +1 -1
- package/src/components/Select/SelectOption.tsx +22 -452
- package/src/components/Select/examples/Select.md +11 -2897
- package/src/{next/components → components}/Select/examples/SelectBasic.tsx +1 -2
- package/src/{next/components → components}/Select/examples/SelectCheckbox.tsx +1 -2
- package/src/{next/components → components}/Select/examples/SelectGrouped.tsx +1 -2
- package/src/{next/components → components}/Select/examples/SelectMultiTypeahead.tsx +4 -1
- package/src/{next/components → components}/Select/examples/SelectTypeahead.tsx +4 -1
- package/src/components/Select/index.ts +1 -1
- package/src/components/Toolbar/__tests__/Toolbar.test.tsx +3 -21
- package/src/components/Toolbar/__tests__/__snapshots__/Toolbar.test.tsx.snap +12 -124
- package/src/components/Toolbar/examples/Toolbar.md +0 -1
- package/src/components/Toolbar/examples/ToolbarComponentManagedToggleGroups.tsx +59 -63
- package/src/components/Toolbar/examples/ToolbarConsumerManagedToggleGroups.tsx +58 -62
- package/src/components/Toolbar/examples/ToolbarCustomChipGroupContent.tsx +107 -23
- package/src/components/Toolbar/examples/ToolbarGroups.tsx +96 -59
- package/src/components/Toolbar/examples/ToolbarStacked.tsx +56 -39
- package/src/components/Toolbar/examples/ToolbarWithFilters.tsx +115 -28
- package/src/components/Tooltip/examples/TooltipOptions.tsx +53 -23
- package/src/demos/Card/Card.md +39 -23
- package/src/demos/CardDemos.md +99 -46
- package/src/demos/Toolbar.md +51 -21
- package/src/demos/examples/Tabs/TabsAndTable.tsx +5 -22
- package/src/deprecated/components/Select/Select.tsx +1495 -0
- package/src/deprecated/components/Select/SelectGroup.tsx +36 -0
- package/src/{components → deprecated/components}/Select/SelectMenu.tsx +2 -2
- package/src/deprecated/components/Select/SelectOption.tsx +461 -0
- package/src/{components → deprecated/components}/Select/SelectToggle.tsx +3 -3
- package/src/{components → deprecated/components}/Select/__tests__/Select.test.tsx +1 -1
- package/src/deprecated/components/Select/examples/Select.md +2937 -0
- package/src/{next → deprecated}/components/Select/index.ts +1 -1
- package/src/deprecated/components/index.ts +1 -0
- package/src/next/components/index.ts +0 -1
- package/dist/esm/components/Select/SelectMenu.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectMenu.js.map +0 -1
- package/dist/esm/components/Select/SelectToggle.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectToggle.js.map +0 -1
- package/dist/esm/components/Select/selectConstants.d.ts.map +0 -1
- package/dist/esm/components/Select/selectConstants.js.map +0 -1
- package/dist/esm/next/components/Select/Select.d.ts +0 -33
- package/dist/esm/next/components/Select/Select.d.ts.map +0 -1
- package/dist/esm/next/components/Select/Select.js +0 -56
- package/dist/esm/next/components/Select/Select.js.map +0 -1
- package/dist/esm/next/components/Select/SelectGroup.d.ts +0 -12
- package/dist/esm/next/components/Select/SelectGroup.d.ts.map +0 -1
- package/dist/esm/next/components/Select/SelectGroup.js +0 -10
- package/dist/esm/next/components/Select/SelectGroup.js.map +0 -1
- package/dist/esm/next/components/Select/SelectList.d.ts.map +0 -1
- package/dist/esm/next/components/Select/SelectList.js.map +0 -1
- package/dist/esm/next/components/Select/SelectOption.d.ts +0 -20
- package/dist/esm/next/components/Select/SelectOption.d.ts.map +0 -1
- package/dist/esm/next/components/Select/SelectOption.js +0 -10
- package/dist/esm/next/components/Select/SelectOption.js.map +0 -1
- package/dist/esm/next/components/Select/index.d.ts.map +0 -1
- package/dist/esm/next/components/Select/index.js.map +0 -1
- package/dist/js/components/Select/SelectMenu.d.ts.map +0 -1
- package/dist/js/components/Select/SelectMenu.js.map +0 -1
- package/dist/js/components/Select/SelectToggle.d.ts.map +0 -1
- package/dist/js/components/Select/SelectToggle.js.map +0 -1
- package/dist/js/components/Select/selectConstants.d.ts.map +0 -1
- package/dist/js/components/Select/selectConstants.js.map +0 -1
- package/dist/js/next/components/Select/Select.d.ts +0 -33
- package/dist/js/next/components/Select/Select.d.ts.map +0 -1
- package/dist/js/next/components/Select/Select.js +0 -59
- package/dist/js/next/components/Select/Select.js.map +0 -1
- package/dist/js/next/components/Select/SelectGroup.d.ts +0 -12
- package/dist/js/next/components/Select/SelectGroup.d.ts.map +0 -1
- package/dist/js/next/components/Select/SelectGroup.js +0 -14
- package/dist/js/next/components/Select/SelectGroup.js.map +0 -1
- package/dist/js/next/components/Select/SelectList.d.ts.map +0 -1
- package/dist/js/next/components/Select/SelectList.js.map +0 -1
- package/dist/js/next/components/Select/SelectOption.d.ts +0 -20
- package/dist/js/next/components/Select/SelectOption.d.ts.map +0 -1
- package/dist/js/next/components/Select/SelectOption.js +0 -14
- package/dist/js/next/components/Select/SelectOption.js.map +0 -1
- package/dist/js/next/components/Select/index.d.ts.map +0 -1
- package/dist/js/next/components/Select/index.js.map +0 -1
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonActionPrimary.tsx +0 -58
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonActionSecondary.tsx +0 -58
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckboxPrimary.tsx +0 -55
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckboxSecondary.tsx +0 -55
- package/src/next/components/Select/Select.tsx +0 -133
- package/src/next/components/Select/SelectGroup.tsx +0 -24
- package/src/next/components/Select/SelectOption.tsx +0 -31
- package/src/next/components/Select/examples/Select.md +0 -38
- /package/dist/esm/{components → deprecated/components}/Select/SelectMenu.d.ts +0 -0
- /package/dist/esm/{components → deprecated/components}/Select/SelectToggle.d.ts +0 -0
- /package/dist/esm/{components → deprecated/components}/Select/selectConstants.d.ts +0 -0
- /package/dist/esm/{components → deprecated/components}/Select/selectConstants.js +0 -0
- /package/dist/js/{components → deprecated/components}/Select/SelectMenu.d.ts +0 -0
- /package/dist/js/{components → deprecated/components}/Select/SelectToggle.d.ts +0 -0
- /package/dist/js/{components → deprecated/components}/Select/selectConstants.d.ts +0 -0
- /package/dist/js/{components → deprecated/components}/Select/selectConstants.js +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/SelectGroup.test.tsx +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/SelectOption.test.tsx +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/SelectToggle.test.tsx +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/__snapshots__/Select.test.tsx.snap +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/__snapshots__/SelectGroup.test.tsx.snap +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/__snapshots__/SelectOption.test.tsx.snap +0 -0
- /package/src/{components → deprecated/components}/Select/__tests__/__snapshots__/SelectToggle.test.tsx.snap +0 -0
- /package/src/{components → deprecated/components}/Select/selectConstants.tsx +0 -0
|
@@ -1,940 +1,56 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import
|
|
3
|
-
import styles from '@patternfly/react-styles/css/components/Select/select';
|
|
4
|
-
import badgeStyles from '@patternfly/react-styles/css/components/Badge/badge';
|
|
5
|
-
import formStyles from '@patternfly/react-styles/css/components/FormControl/form-control';
|
|
6
|
-
import buttonStyles from '@patternfly/react-styles/css/components/Button/button';
|
|
2
|
+
import React from 'react';
|
|
7
3
|
import { css } from '@patternfly/react-styles';
|
|
8
|
-
import
|
|
9
|
-
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
|
|
10
|
-
import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
|
|
11
|
-
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
|
|
12
|
-
import { SelectMenu } from './SelectMenu';
|
|
13
|
-
import { SelectOption } from './SelectOption';
|
|
14
|
-
import { SelectGroup } from './SelectGroup';
|
|
15
|
-
import { SelectToggle } from './SelectToggle';
|
|
16
|
-
import { SelectContext, SelectVariant, SelectPosition, SelectDirection, SelectFooterTabbableItems } from './selectConstants';
|
|
17
|
-
import { ChipGroup } from '../ChipGroup';
|
|
18
|
-
import { Chip } from '../Chip';
|
|
19
|
-
import { Spinner } from '../Spinner';
|
|
20
|
-
import { keyHandler, getNextIndex, getOUIAProps, getDefaultOUIAId, GenerateId } from '../../helpers';
|
|
21
|
-
import { KeyTypes } from '../../helpers/constants';
|
|
22
|
-
import { Divider } from '../Divider';
|
|
4
|
+
import { Menu, MenuContent } from '../Menu';
|
|
23
5
|
import { Popper } from '../../helpers/Popper/Popper';
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.props.loadingVariant !== 'spinner' &&
|
|
72
|
-
this.refCollection[this.state.viewMoreNextIndex][0] &&
|
|
73
|
-
this.props.variant !== 'typeahead' && // do not hard focus newly added items for typeahead variants
|
|
74
|
-
this.props.variant !== 'typeaheadmulti') {
|
|
75
|
-
this.refCollection[this.state.viewMoreNextIndex][0].focus();
|
|
76
|
-
this.setState({ viewMoreNextIndex: -1 });
|
|
77
|
-
}
|
|
78
|
-
const checkUpdatedChildren = (prevChildren, currChildren) => Array.from(prevChildren).some((prevChild, index) => {
|
|
79
|
-
const prevChildProps = prevChild.props;
|
|
80
|
-
const currChild = currChildren[index];
|
|
81
|
-
const { props: currChildProps } = currChild;
|
|
82
|
-
if (prevChildProps && currChildProps) {
|
|
83
|
-
return (prevChildProps.value !== currChildProps.value ||
|
|
84
|
-
prevChildProps.label !== currChildProps.label ||
|
|
85
|
-
prevChildProps.isDisabled !== currChildProps.isDisabled ||
|
|
86
|
-
prevChildProps.isPlaceholder !== currChildProps.isPlaceholder);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return prevChild !== currChild;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
const hasUpdatedChildren = prevProps.children.length !== this.props.children.length ||
|
|
93
|
-
checkUpdatedChildren(prevProps.children, this.props.children) ||
|
|
94
|
-
(this.props.isGrouped &&
|
|
95
|
-
Array.from(prevProps.children).some((prevChild, index) => prevChild.type === SelectGroup &&
|
|
96
|
-
prevChild.props.children &&
|
|
97
|
-
this.props.children[index].props.children &&
|
|
98
|
-
(prevChild.props.children.length !== this.props.children[index].props.children.length ||
|
|
99
|
-
checkUpdatedChildren(prevChild.props.children, this.props.children[index].props.children))));
|
|
100
|
-
if (hasUpdatedChildren) {
|
|
101
|
-
this.updateTypeAheadFilteredChildren(prevState.typeaheadInputValue || '', null);
|
|
102
|
-
}
|
|
103
|
-
// for menus with favorites,
|
|
104
|
-
// if the number of favorites or typeahead filtered children has changed, the generated
|
|
105
|
-
// list of favorites needs to be updated
|
|
106
|
-
if (this.props.onFavorite &&
|
|
107
|
-
(this.props.favorites.length !== prevProps.favorites.length ||
|
|
108
|
-
this.state.typeaheadFilteredChildren !== prevState.typeaheadFilteredChildren)) {
|
|
109
|
-
const tempRenderableChildren = this.props.variant === 'typeahead' || this.props.variant === 'typeaheadmulti'
|
|
110
|
-
? this.state.typeaheadFilteredChildren
|
|
111
|
-
: this.props.children;
|
|
112
|
-
const renderableFavorites = createRenderableFavorites(tempRenderableChildren, this.props.isGrouped, this.props.favorites);
|
|
113
|
-
const favoritesGroup = renderableFavorites.length
|
|
114
|
-
? [
|
|
115
|
-
React.createElement(SelectGroup, { key: "favorites", label: this.props.favoritesLabel }, renderableFavorites),
|
|
116
|
-
React.createElement(Divider, { key: "favorites-group-divider" })
|
|
117
|
-
]
|
|
118
|
-
: [];
|
|
119
|
-
this.setState({ favoritesGroup });
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
this.onEnter = () => {
|
|
123
|
-
this.setState({ focusFirstOption: true });
|
|
124
|
-
};
|
|
125
|
-
this.onToggle = (e, isExpanded) => {
|
|
126
|
-
const { isInputValuePersisted, onSelect, onToggle, hasInlineFilter } = this.props;
|
|
127
|
-
if (!isExpanded && isInputValuePersisted && onSelect) {
|
|
128
|
-
onSelect(undefined, this.inputRef.current ? this.inputRef.current.value : '');
|
|
129
|
-
}
|
|
130
|
-
if (isExpanded && hasInlineFilter) {
|
|
131
|
-
this.setState({
|
|
132
|
-
focusFirstOption: true
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
onToggle(e, isExpanded);
|
|
136
|
-
};
|
|
137
|
-
this.onClose = () => {
|
|
138
|
-
const { isInputFilterPersisted } = this.props;
|
|
139
|
-
this.setState(Object.assign(Object.assign({ focusFirstOption: false, typeaheadInputValue: null }, (!isInputFilterPersisted && {
|
|
140
|
-
typeaheadFilteredChildren: React.Children.toArray(this.props.children)
|
|
141
|
-
})), { typeaheadCurrIndex: -1, tabbedIntoFavoritesMenu: false, viewMoreNextIndex: -1 }));
|
|
142
|
-
};
|
|
143
|
-
this.onChange = (e) => {
|
|
144
|
-
if (e.target.value.toString() !== '' && !this.props.isOpen) {
|
|
145
|
-
this.onToggle(e, true);
|
|
146
|
-
}
|
|
147
|
-
if (this.props.onTypeaheadInputChanged) {
|
|
148
|
-
this.props.onTypeaheadInputChanged(e.target.value.toString());
|
|
149
|
-
}
|
|
150
|
-
this.setState({
|
|
151
|
-
typeaheadCurrIndex: -1,
|
|
152
|
-
typeaheadInputValue: e.target.value,
|
|
153
|
-
creatableValue: e.target.value
|
|
154
|
-
});
|
|
155
|
-
this.updateTypeAheadFilteredChildren(e.target.value.toString(), e);
|
|
156
|
-
this.refCollection = [[]];
|
|
157
|
-
};
|
|
158
|
-
this.updateTypeAheadFilteredChildren = (typeaheadInputValue, e) => {
|
|
159
|
-
let typeaheadFilteredChildren;
|
|
160
|
-
const { onFilter, isCreatable, isCreateOptionOnTop, onCreateOption, createText, noResultsFoundText, children, isGrouped, isCreateSelectOptionObject, loadingVariant } = this.props;
|
|
161
|
-
if (onFilter) {
|
|
162
|
-
/* The updateTypeAheadFilteredChildren callback is not only called on input changes but also when the children change.
|
|
163
|
-
* In this case the e is null but we can get the typeaheadInputValue from the state.
|
|
164
|
-
*/
|
|
165
|
-
typeaheadFilteredChildren = onFilter(e, e ? e.target.value : typeaheadInputValue) || children;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
let input;
|
|
169
|
-
try {
|
|
170
|
-
input = new RegExp(typeaheadInputValue.toString(), 'i');
|
|
171
|
-
}
|
|
172
|
-
catch (err) {
|
|
173
|
-
input = new RegExp(typeaheadInputValue.toString().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
|
174
|
-
}
|
|
175
|
-
const childrenArray = React.Children.toArray(children);
|
|
176
|
-
if (isGrouped) {
|
|
177
|
-
const childFilter = (child) => child.props.value &&
|
|
178
|
-
child.props.value.toString &&
|
|
179
|
-
this.getDisplay(child.props.value.toString(), 'text').search(input) === 0;
|
|
180
|
-
typeaheadFilteredChildren =
|
|
181
|
-
typeaheadInputValue.toString() !== ''
|
|
182
|
-
? React.Children.map(children, group => {
|
|
183
|
-
if (React.isValidElement(group) &&
|
|
184
|
-
group.type === SelectGroup) {
|
|
185
|
-
const filteredGroupChildren = React.Children.toArray(group.props.children).filter(childFilter);
|
|
186
|
-
if (filteredGroupChildren.length > 0) {
|
|
187
|
-
return React.cloneElement(group, {
|
|
188
|
-
titleId: group.props.label && group.props.label.replace(/\W/g, '-'),
|
|
189
|
-
children: filteredGroupChildren
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
return React.Children.toArray(group).filter(childFilter);
|
|
195
|
-
}
|
|
196
|
-
})
|
|
197
|
-
: childrenArray;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
typeaheadFilteredChildren =
|
|
201
|
-
typeaheadInputValue.toString() !== ''
|
|
202
|
-
? childrenArray.filter(child => {
|
|
203
|
-
const valueToCheck = child.props.value;
|
|
204
|
-
// Dividers don't have value and should not be filtered
|
|
205
|
-
if (!valueToCheck) {
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
const isSelectOptionObject = typeof valueToCheck !== 'string' &&
|
|
209
|
-
valueToCheck.toString &&
|
|
210
|
-
valueToCheck.compareTo;
|
|
211
|
-
// View more option should be returned as not a match
|
|
212
|
-
if (loadingVariant !== 'spinner' && (loadingVariant === null || loadingVariant === void 0 ? void 0 : loadingVariant.text) === valueToCheck) {
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
// spinner should be returned as not a match
|
|
216
|
-
if (loadingVariant === 'spinner' && valueToCheck === 'loading') {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
if (isSelectOptionObject) {
|
|
220
|
-
return valueToCheck.compareTo(typeaheadInputValue);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
return this.getDisplay(child.props.value.toString(), 'text').search(input) === 0;
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
: childrenArray;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (!typeaheadFilteredChildren) {
|
|
230
|
-
typeaheadFilteredChildren = [];
|
|
231
|
-
}
|
|
232
|
-
if (typeaheadFilteredChildren.length === 0) {
|
|
233
|
-
!isCreatable &&
|
|
234
|
-
typeaheadFilteredChildren.push(React.createElement(SelectOption, { isDisabled: true, key: "no-results", value: noResultsFoundText, isNoResultsOption: true }));
|
|
235
|
-
}
|
|
236
|
-
if (isCreatable && typeaheadInputValue !== '') {
|
|
237
|
-
const newValue = typeaheadInputValue;
|
|
238
|
-
if (!typeaheadFilteredChildren.find((i) => i.props.value && i.props.value.toString().toLowerCase() === newValue.toString().toLowerCase())) {
|
|
239
|
-
const newOptionValue = isCreateSelectOptionObject
|
|
240
|
-
? {
|
|
241
|
-
toString: () => newValue,
|
|
242
|
-
compareTo: value => this.toString()
|
|
243
|
-
.toLowerCase()
|
|
244
|
-
.includes(value.toString().toLowerCase())
|
|
245
|
-
}
|
|
246
|
-
: newValue;
|
|
247
|
-
const createSelectOption = (React.createElement(SelectOption, { key: `create ${newValue}`, value: newOptionValue, onClick: () => onCreateOption && onCreateOption(newValue) },
|
|
248
|
-
createText,
|
|
249
|
-
" \"",
|
|
250
|
-
newValue,
|
|
251
|
-
"\""));
|
|
252
|
-
if (isCreateOptionOnTop) {
|
|
253
|
-
typeaheadFilteredChildren.unshift(createSelectOption);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
typeaheadFilteredChildren.push(createSelectOption);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
this.setState({
|
|
261
|
-
typeaheadFilteredChildren
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
this.onClick = (e) => {
|
|
265
|
-
if (!this.props.isOpen) {
|
|
266
|
-
this.onToggle(e, true);
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
this.clearSelection = (_e) => {
|
|
270
|
-
this.setState({
|
|
271
|
-
typeaheadInputValue: null,
|
|
272
|
-
typeaheadFilteredChildren: React.Children.toArray(this.props.children),
|
|
273
|
-
typeaheadCurrIndex: -1
|
|
274
|
-
});
|
|
275
|
-
};
|
|
276
|
-
this.sendRef = (optionRef, favoriteRef, optionContainerRef, index) => {
|
|
277
|
-
this.refCollection[index] = [optionRef, favoriteRef];
|
|
278
|
-
this.optionContainerRefCollection[index] = optionContainerRef;
|
|
279
|
-
};
|
|
280
|
-
this.handleMenuKeys = (index, innerIndex, position) => {
|
|
281
|
-
keyHandler(index, innerIndex, position, this.refCollection, this.refCollection);
|
|
282
|
-
if (this.props.variant === SelectVariant.typeahead || this.props.variant === SelectVariant.typeaheadMulti) {
|
|
283
|
-
if (position !== 'tab') {
|
|
284
|
-
this.handleTypeaheadKeys(position);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
this.moveFocus = (nextIndex, updateCurrentIndex = true) => {
|
|
289
|
-
const { isCreatable, createText } = this.props;
|
|
290
|
-
const hasDescriptionElm = Boolean(this.refCollection[nextIndex][0] && this.refCollection[nextIndex][0].classList.contains('pf-m-description'));
|
|
291
|
-
const isLoad = Boolean(this.refCollection[nextIndex][0] && this.refCollection[nextIndex][0].classList.contains('pf-m-load'));
|
|
292
|
-
const optionTextElm = hasDescriptionElm
|
|
293
|
-
? this.refCollection[nextIndex][0].firstElementChild
|
|
294
|
-
: this.refCollection[nextIndex][0];
|
|
295
|
-
let typeaheadInputValue = '';
|
|
296
|
-
if (isCreatable && optionTextElm.textContent.includes(createText)) {
|
|
297
|
-
typeaheadInputValue = this.state.creatableValue;
|
|
298
|
-
}
|
|
299
|
-
else if (optionTextElm && !isLoad) {
|
|
300
|
-
// !isLoad prevents the view more button text from appearing the typeahead input
|
|
301
|
-
typeaheadInputValue = optionTextElm.textContent;
|
|
302
|
-
}
|
|
303
|
-
this.setState(prevState => ({
|
|
304
|
-
typeaheadCurrIndex: updateCurrentIndex ? nextIndex : prevState.typeaheadCurrIndex,
|
|
305
|
-
typeaheadStoredIndex: nextIndex,
|
|
306
|
-
typeaheadInputValue
|
|
307
|
-
}));
|
|
308
|
-
};
|
|
309
|
-
this.switchFocusToFavoriteMenu = () => {
|
|
310
|
-
const { typeaheadCurrIndex, typeaheadStoredIndex } = this.state;
|
|
311
|
-
let indexForFocus = 0;
|
|
312
|
-
if (typeaheadCurrIndex !== -1) {
|
|
313
|
-
indexForFocus = typeaheadCurrIndex;
|
|
314
|
-
}
|
|
315
|
-
else if (typeaheadStoredIndex !== -1) {
|
|
316
|
-
indexForFocus = typeaheadStoredIndex;
|
|
317
|
-
}
|
|
318
|
-
if (this.refCollection[indexForFocus] !== null && this.refCollection[indexForFocus][0] !== null) {
|
|
319
|
-
this.refCollection[indexForFocus][0].focus();
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
this.clearRef.current.focus();
|
|
323
|
-
}
|
|
324
|
-
this.setState({
|
|
325
|
-
tabbedIntoFavoritesMenu: true,
|
|
326
|
-
typeaheadCurrIndex: -1
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
this.moveFocusToLastMenuItem = () => {
|
|
330
|
-
const refCollectionLen = this.refCollection.length;
|
|
331
|
-
if (refCollectionLen > 0 &&
|
|
332
|
-
this.refCollection[refCollectionLen - 1] !== null &&
|
|
333
|
-
this.refCollection[refCollectionLen - 1][0] !== null) {
|
|
334
|
-
this.refCollection[refCollectionLen - 1][0].focus();
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
this.handleTypeaheadKeys = (position, shiftKey = false) => {
|
|
338
|
-
const { isOpen, onFavorite, isCreatable } = this.props;
|
|
339
|
-
const { typeaheadCurrIndex, tabbedIntoFavoritesMenu } = this.state;
|
|
340
|
-
const typeaheadActiveChild = this.getTypeaheadActiveChild(typeaheadCurrIndex);
|
|
341
|
-
if (isOpen) {
|
|
342
|
-
if (position === 'enter') {
|
|
343
|
-
if ((typeaheadCurrIndex !== -1 || (isCreatable && this.refCollection.length === 1)) && // do not allow selection without moving to an initial option unless it is a single create option
|
|
344
|
-
(typeaheadActiveChild || (this.refCollection[0] && this.refCollection[0][0]))) {
|
|
345
|
-
if (typeaheadActiveChild) {
|
|
346
|
-
if (!typeaheadActiveChild.classList.contains('pf-m-load')) {
|
|
347
|
-
const hasDescriptionElm = typeaheadActiveChild.childElementCount > 1;
|
|
348
|
-
const typeaheadActiveChildText = hasDescriptionElm
|
|
349
|
-
? typeaheadActiveChild.firstChild.textContent
|
|
350
|
-
: typeaheadActiveChild.textContent;
|
|
351
|
-
this.setState({
|
|
352
|
-
typeaheadInputValue: typeaheadActiveChildText
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
else if (this.refCollection[0] && this.refCollection[0][0]) {
|
|
357
|
-
this.setState({
|
|
358
|
-
typeaheadInputValue: this.refCollection[0][0].textContent
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
if (typeaheadActiveChild) {
|
|
362
|
-
typeaheadActiveChild.click();
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
this.refCollection[0][0].click();
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
else if (position === 'tab') {
|
|
370
|
-
if (onFavorite) {
|
|
371
|
-
// if the input has focus, tab to the first item or the last item that was previously focused.
|
|
372
|
-
if (this.inputRef.current === document.activeElement) {
|
|
373
|
-
// If shift is also clicked and there is a footer, tab to the last item in tabbable footer
|
|
374
|
-
if (this.props.footer && shiftKey) {
|
|
375
|
-
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
376
|
-
if (tabbableItems.length > 0) {
|
|
377
|
-
if (tabbableItems[tabbableItems.length - 1]) {
|
|
378
|
-
tabbableItems[tabbableItems.length - 1].focus();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
this.switchFocusToFavoriteMenu();
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
// focus is on menu or footer
|
|
388
|
-
if (this.props.footer) {
|
|
389
|
-
let tabbedIntoMenu = false;
|
|
390
|
-
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
391
|
-
if (tabbableItems.length > 0) {
|
|
392
|
-
// if current element is not in footer, tab to first tabbable element in footer,
|
|
393
|
-
// if shift was clicked, tab to input since focus is on menu
|
|
394
|
-
const currentElementIndex = tabbableItems.findIndex((item) => item === document.activeElement);
|
|
395
|
-
if (currentElementIndex === -1) {
|
|
396
|
-
if (shiftKey) {
|
|
397
|
-
// currently in menu, shift back to input
|
|
398
|
-
this.inputRef.current.focus();
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
// currently in menu, tab to first tabbable item in footer
|
|
402
|
-
tabbableItems[0].focus();
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
// already in footer
|
|
407
|
-
if (shiftKey) {
|
|
408
|
-
// shift to previous item
|
|
409
|
-
if (currentElementIndex === 0) {
|
|
410
|
-
// on first footer item, shift back to menu
|
|
411
|
-
this.switchFocusToFavoriteMenu();
|
|
412
|
-
tabbedIntoMenu = true;
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
// shift to previous footer item
|
|
416
|
-
tabbableItems[currentElementIndex - 1].focus();
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
// tab to next tabbable item in footer or to input.
|
|
421
|
-
if (tabbableItems[currentElementIndex + 1]) {
|
|
422
|
-
tabbableItems[currentElementIndex + 1].focus();
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
this.inputRef.current.focus();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
// no tabbable items in footer, tab to input
|
|
432
|
-
this.inputRef.current.focus();
|
|
433
|
-
tabbedIntoMenu = false;
|
|
434
|
-
}
|
|
435
|
-
this.setState({ tabbedIntoFavoritesMenu: tabbedIntoMenu });
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
this.inputRef.current.focus();
|
|
439
|
-
this.setState({ tabbedIntoFavoritesMenu: false });
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
// Close if there is no footer
|
|
445
|
-
if (!this.props.footer) {
|
|
446
|
-
this.onToggle(null, false);
|
|
447
|
-
this.onClose();
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
// has footer
|
|
451
|
-
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
452
|
-
const currentElementIndex = tabbableItems.findIndex((item) => item === document.activeElement);
|
|
453
|
-
if (this.inputRef.current === document.activeElement) {
|
|
454
|
-
if (shiftKey) {
|
|
455
|
-
// close toggle if shift key and tab on input
|
|
456
|
-
this.onToggle(null, false);
|
|
457
|
-
this.onClose();
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
// tab to first tabbable item in footer
|
|
461
|
-
if (tabbableItems[0]) {
|
|
462
|
-
tabbableItems[0].focus();
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
this.onToggle(null, false);
|
|
466
|
-
this.onClose();
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
// focus is in footer
|
|
472
|
-
if (shiftKey) {
|
|
473
|
-
if (currentElementIndex === 0) {
|
|
474
|
-
// shift tab back to input
|
|
475
|
-
this.inputRef.current.focus();
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
// shift to previous footer item
|
|
479
|
-
tabbableItems[currentElementIndex - 1].focus();
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
// tab to next footer item or close tab if last item
|
|
484
|
-
if (tabbableItems[currentElementIndex + 1]) {
|
|
485
|
-
tabbableItems[currentElementIndex + 1].focus();
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
// no next item, close toggle
|
|
489
|
-
this.onToggle(null, false);
|
|
490
|
-
this.inputRef.current.focus();
|
|
491
|
-
this.onClose();
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
else if (!tabbedIntoFavoritesMenu) {
|
|
499
|
-
if (this.refCollection[0][0] === null) {
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
let nextIndex;
|
|
503
|
-
if (typeaheadCurrIndex === -1 && position === 'down') {
|
|
504
|
-
nextIndex = 0;
|
|
505
|
-
}
|
|
506
|
-
else if (typeaheadCurrIndex === -1 && position === 'up') {
|
|
507
|
-
nextIndex = this.refCollection.length - 1;
|
|
508
|
-
}
|
|
509
|
-
else if (position !== 'left' && position !== 'right') {
|
|
510
|
-
nextIndex = getNextIndex(typeaheadCurrIndex, position, this.refCollection);
|
|
511
|
-
}
|
|
512
|
-
else {
|
|
513
|
-
nextIndex = typeaheadCurrIndex;
|
|
514
|
-
}
|
|
515
|
-
if (this.refCollection[nextIndex] === null) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
this.moveFocus(nextIndex);
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
const nextIndex = this.refCollection.findIndex(ref => ref !== undefined && (ref[0] === document.activeElement || ref[1] === document.activeElement));
|
|
522
|
-
this.moveFocus(nextIndex);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
this.onClickTypeaheadToggleButton = () => {
|
|
527
|
-
if (this.inputRef && this.inputRef.current) {
|
|
528
|
-
this.inputRef.current.focus();
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
this.getDisplay = (value, type = 'node') => {
|
|
532
|
-
if (!value) {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
const item = this.props.isGrouped
|
|
536
|
-
? React.Children.toArray(this.props.children)
|
|
537
|
-
.reduce((acc, curr) => [...acc, ...React.Children.toArray(curr.props.children)], [])
|
|
538
|
-
.find(child => child.props.value.toString() === value.toString())
|
|
539
|
-
: React.Children.toArray(this.props.children).find(child => child.props.value &&
|
|
540
|
-
child.props.value.toString() === value.toString());
|
|
541
|
-
if (item) {
|
|
542
|
-
if (item && item.props.children) {
|
|
543
|
-
if (type === 'node') {
|
|
544
|
-
return item.props.children;
|
|
545
|
-
}
|
|
546
|
-
return this.findText(item);
|
|
547
|
-
}
|
|
548
|
-
return item.props.value.toString();
|
|
549
|
-
}
|
|
550
|
-
return value.toString();
|
|
551
|
-
};
|
|
552
|
-
this.findText = (item) => {
|
|
553
|
-
if (typeof item === 'string') {
|
|
554
|
-
return item;
|
|
555
|
-
}
|
|
556
|
-
else if (!React.isValidElement(item)) {
|
|
557
|
-
return '';
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
const multi = [];
|
|
561
|
-
React.Children.toArray(item.props.children).forEach(child => multi.push(this.findText(child)));
|
|
562
|
-
return multi.join('');
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
this.generateSelectedBadge = () => {
|
|
566
|
-
const { customBadgeText, selections } = this.props;
|
|
567
|
-
if (customBadgeText !== null) {
|
|
568
|
-
return customBadgeText;
|
|
569
|
-
}
|
|
570
|
-
if (Array.isArray(selections) && selections.length > 0) {
|
|
571
|
-
return selections.length;
|
|
572
|
-
}
|
|
573
|
-
return null;
|
|
574
|
-
};
|
|
575
|
-
this.setVieMoreNextIndex = () => {
|
|
576
|
-
this.setState({ viewMoreNextIndex: this.refCollection.length - 1 });
|
|
577
|
-
};
|
|
578
|
-
this.isLastOptionBeforeFooter = (index) => this.props.footer && index === this.refCollection.length - 1 ? true : false;
|
|
579
|
-
}
|
|
580
|
-
extendTypeaheadChildren(typeaheadCurrIndex, favoritesGroup) {
|
|
581
|
-
const { isGrouped, onFavorite, createText } = this.props;
|
|
582
|
-
const typeaheadChildren = favoritesGroup
|
|
583
|
-
? favoritesGroup.concat(this.state.typeaheadFilteredChildren)
|
|
584
|
-
: this.state.typeaheadFilteredChildren;
|
|
585
|
-
const activeElement = this.optionContainerRefCollection[typeaheadCurrIndex];
|
|
586
|
-
let typeaheadActiveChild = this.getTypeaheadActiveChild(typeaheadCurrIndex);
|
|
587
|
-
if (typeaheadActiveChild && typeaheadActiveChild.classList.contains('pf-m-description')) {
|
|
588
|
-
typeaheadActiveChild = typeaheadActiveChild.firstElementChild;
|
|
589
|
-
}
|
|
590
|
-
this.refCollection = [[]];
|
|
591
|
-
this.optionContainerRefCollection = [];
|
|
592
|
-
if (isGrouped) {
|
|
593
|
-
return React.Children.map(typeaheadChildren, (group) => {
|
|
594
|
-
if (group.type === Divider) {
|
|
595
|
-
return group;
|
|
596
|
-
}
|
|
597
|
-
else if (group.type === SelectGroup && onFavorite) {
|
|
598
|
-
return React.cloneElement(group, {
|
|
599
|
-
titleId: group.props.label && group.props.label.replace(/\W/g, '-'),
|
|
600
|
-
children: React.Children.map(group.props.children, (child) => child.type === Divider
|
|
601
|
-
? child
|
|
602
|
-
: React.cloneElement(child, {
|
|
603
|
-
isFocused: activeElement &&
|
|
604
|
-
(activeElement.id === child.props.id ||
|
|
605
|
-
(this.props.isCreatable &&
|
|
606
|
-
typeaheadActiveChild.textContent ===
|
|
607
|
-
`${createText} "${group.props.value}"`))
|
|
608
|
-
}))
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
else if (group.type === SelectGroup) {
|
|
612
|
-
return React.cloneElement(group, {
|
|
613
|
-
titleId: group.props.label && group.props.label.replace(/\W/g, '-'),
|
|
614
|
-
children: React.Children.map(group.props.children, (child) => child.type === Divider
|
|
615
|
-
? child
|
|
616
|
-
: React.cloneElement(child, {
|
|
617
|
-
isFocused: typeaheadActiveChild &&
|
|
618
|
-
(typeaheadActiveChild.textContent === child.props.value.toString() ||
|
|
619
|
-
(this.props.isCreatable &&
|
|
620
|
-
typeaheadActiveChild.textContent ===
|
|
621
|
-
`${createText} "${child.props.value}"`))
|
|
622
|
-
}))
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
// group has been filtered down to SelectOption
|
|
627
|
-
return React.cloneElement(group, {
|
|
628
|
-
isFocused: typeaheadActiveChild &&
|
|
629
|
-
(typeaheadActiveChild.textContent === group.props.value.toString() ||
|
|
630
|
-
(this.props.isCreatable && typeaheadActiveChild.textContent === `${createText} "${group.props.value}"`))
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
return typeaheadChildren.map((child, index) => {
|
|
636
|
-
const childElement = child;
|
|
637
|
-
return childElement.type.displayName === 'Divider'
|
|
638
|
-
? child
|
|
639
|
-
: React.cloneElement(child, {
|
|
640
|
-
isFocused: typeaheadActiveChild
|
|
641
|
-
? typeaheadActiveChild.textContent === child.props.value.toString() ||
|
|
642
|
-
(this.props.isCreatable &&
|
|
643
|
-
typeaheadActiveChild.textContent === `${createText} "${child.props.value}"`)
|
|
644
|
-
: index === typeaheadCurrIndex // fallback for view more + typeahead use cases, when the new expanded list is loaded and refCollection hasn't be updated yet
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
render() {
|
|
649
|
-
const _a = this.props, { children, chipGroupProps, chipGroupComponent, className, customContent, variant, direction, onSelect, onClear, onBlur, toggleId, toggleRef, isOpen, isGrouped, isPlain, isDisabled, hasPlaceholderStyle, validated, selections: selectionsProp, typeAheadAriaLabel, typeAheadAriaDescribedby, clearSelectionsAriaLabel, toggleAriaLabel, removeSelectionAriaLabel, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedby, 'aria-invalid': ariaInvalid, placeholderText, width, maxHeight, toggleIcon, toggleIndicator, ouiaId, ouiaSafe, hasInlineFilter, isCheckboxSelectionBadgeHidden, inlineFilterPlaceholderText,
|
|
650
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
651
|
-
onFilter,
|
|
652
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
653
|
-
onTypeaheadInputChanged, onCreateOption, isCreatable, onToggle, createText, noResultsFoundText, customBadgeText, inputIdPrefix, inputAutoComplete,
|
|
654
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
655
|
-
isInputValuePersisted, isInputFilterPersisted,
|
|
656
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
657
|
-
menuAppendTo, favorites, onFavorite,
|
|
658
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
659
|
-
favoritesLabel, footer, loadingVariant, isCreateSelectOptionObject, isCreateOptionOnTop, shouldResetOnSelect, isFlipEnabled, zIndex } = _a, props = __rest(_a, ["children", "chipGroupProps", "chipGroupComponent", "className", "customContent", "variant", "direction", "onSelect", "onClear", "onBlur", "toggleId", "toggleRef", "isOpen", "isGrouped", "isPlain", "isDisabled", "hasPlaceholderStyle", "validated", "selections", "typeAheadAriaLabel", "typeAheadAriaDescribedby", "clearSelectionsAriaLabel", "toggleAriaLabel", "removeSelectionAriaLabel", 'aria-label', 'aria-labelledby', 'aria-describedby', 'aria-invalid', "placeholderText", "width", "maxHeight", "toggleIcon", "toggleIndicator", "ouiaId", "ouiaSafe", "hasInlineFilter", "isCheckboxSelectionBadgeHidden", "inlineFilterPlaceholderText", "onFilter", "onTypeaheadInputChanged", "onCreateOption", "isCreatable", "onToggle", "createText", "noResultsFoundText", "customBadgeText", "inputIdPrefix", "inputAutoComplete", "isInputValuePersisted", "isInputFilterPersisted", "menuAppendTo", "favorites", "onFavorite", "favoritesLabel", "footer", "loadingVariant", "isCreateSelectOptionObject", "isCreateOptionOnTop", "shouldResetOnSelect", "isFlipEnabled", "zIndex"]);
|
|
660
|
-
const { focusFirstOption: openedOnEnter, typeaheadCurrIndex, typeaheadInputValue, typeaheadFilteredChildren, favoritesGroup } = this.state;
|
|
661
|
-
const selectToggleId = toggleId || `pf-select-toggle-id-${currentId++}`;
|
|
662
|
-
const selections = Array.isArray(selectionsProp) ? selectionsProp : [selectionsProp];
|
|
663
|
-
// Find out if the selected option is a placeholder
|
|
664
|
-
const selectedOption = React.Children.toArray(children).find((option) => option.props.value === selections[0]);
|
|
665
|
-
const isSelectedPlaceholder = selectedOption && selectedOption.props.isPlaceholder;
|
|
666
|
-
const hasAnySelections = Boolean(selections[0] && selections[0] !== '');
|
|
667
|
-
const typeaheadActiveChild = this.getTypeaheadActiveChild(typeaheadCurrIndex);
|
|
668
|
-
let childPlaceholderText = null;
|
|
669
|
-
// If onFavorites is set, add isFavorite prop to children and add a Favorites group to the SelectMenu
|
|
670
|
-
let renderableItems = [];
|
|
671
|
-
if (onFavorite) {
|
|
672
|
-
// if variant is type-ahead call the extendTypeaheadChildren before adding favorites
|
|
673
|
-
let tempExtendedChildren = children;
|
|
674
|
-
if (variant === 'typeahead' || variant === 'typeaheadmulti') {
|
|
675
|
-
tempExtendedChildren = this.extendTypeaheadChildren(typeaheadCurrIndex, favoritesGroup);
|
|
676
|
-
}
|
|
677
|
-
else if (onFavorite) {
|
|
678
|
-
tempExtendedChildren = favoritesGroup.concat(children);
|
|
679
|
-
}
|
|
680
|
-
// mark items that are favorited with isFavorite
|
|
681
|
-
renderableItems = extendItemsWithFavorite(tempExtendedChildren, isGrouped, favorites);
|
|
682
|
-
}
|
|
683
|
-
else {
|
|
684
|
-
renderableItems = children;
|
|
685
|
-
}
|
|
686
|
-
if (!customContent) {
|
|
687
|
-
if (!hasAnySelections && !placeholderText) {
|
|
688
|
-
const childPlaceholder = React.Children.toArray(children).filter((child) => child.props.isPlaceholder === true);
|
|
689
|
-
childPlaceholderText =
|
|
690
|
-
(childPlaceholder[0] && this.getDisplay(childPlaceholder[0].props.value, 'node')) ||
|
|
691
|
-
(children[0] && this.getDisplay(children[0].props.value, 'node'));
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
if (isOpen) {
|
|
695
|
-
if (renderableItems.find(item => (item === null || item === void 0 ? void 0 : item.key) === 'loading') === undefined) {
|
|
696
|
-
if (loadingVariant === 'spinner') {
|
|
697
|
-
renderableItems.push(React.createElement(SelectOption, { isLoading: true, key: "loading", value: "loading" },
|
|
698
|
-
React.createElement(Spinner, { size: "lg" })));
|
|
699
|
-
}
|
|
700
|
-
else if (loadingVariant === null || loadingVariant === void 0 ? void 0 : loadingVariant.text) {
|
|
701
|
-
renderableItems.push(React.createElement(SelectOption, { isLoad: true, key: "loading", value: loadingVariant.text, setViewMoreNextIndex: this.setVieMoreNextIndex, onClick: loadingVariant === null || loadingVariant === void 0 ? void 0 : loadingVariant.onClick }));
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
const hasOnClear = onClear !== Select.defaultProps.onClear;
|
|
706
|
-
const clearBtn = (React.createElement("button", { className: css(buttonStyles.button, buttonStyles.modifiers.plain, styles.selectToggleClear), onClick: e => {
|
|
707
|
-
this.clearSelection(e);
|
|
708
|
-
onClear(e);
|
|
709
|
-
e.stopPropagation();
|
|
710
|
-
}, "aria-label": clearSelectionsAriaLabel, type: "button", disabled: isDisabled, ref: this.clearRef, onKeyDown: event => {
|
|
711
|
-
if (event.key === KeyTypes.Enter) {
|
|
712
|
-
this.clearRef.current.click();
|
|
713
|
-
}
|
|
714
|
-
} },
|
|
715
|
-
React.createElement(TimesCircleIcon, { "aria-hidden": true })));
|
|
716
|
-
let selectedChips = null;
|
|
717
|
-
if (variant === SelectVariant.typeaheadMulti) {
|
|
718
|
-
selectedChips = chipGroupComponent ? (chipGroupComponent) : (React.createElement(ChipGroup, Object.assign({}, chipGroupProps), selections &&
|
|
719
|
-
selections.map(item => (React.createElement(Chip, { key: item, onClick: (e) => onSelect(e, item), closeBtnAriaLabel: removeSelectionAriaLabel }, this.getDisplay(item, 'node'))))));
|
|
720
|
-
}
|
|
721
|
-
if (hasInlineFilter) {
|
|
722
|
-
const filterBox = (React.createElement(React.Fragment, null,
|
|
723
|
-
React.createElement("div", { key: "inline-filter", className: css(styles.selectMenuSearch) },
|
|
724
|
-
React.createElement("input", { key: "inline-filter-input", type: "search", className: css(formStyles.formControl, formStyles.modifiers.search), onChange: this.onChange, placeholder: inlineFilterPlaceholderText, onKeyDown: event => {
|
|
725
|
-
if (event.key === KeyTypes.ArrowUp) {
|
|
726
|
-
this.handleMenuKeys(0, 0, 'up');
|
|
727
|
-
event.preventDefault();
|
|
728
|
-
}
|
|
729
|
-
else if (event.key === KeyTypes.ArrowDown) {
|
|
730
|
-
this.handleMenuKeys(0, 0, 'down');
|
|
731
|
-
event.preventDefault();
|
|
732
|
-
}
|
|
733
|
-
else if (event.key === KeyTypes.ArrowLeft) {
|
|
734
|
-
this.handleMenuKeys(0, 0, 'left');
|
|
735
|
-
event.preventDefault();
|
|
736
|
-
}
|
|
737
|
-
else if (event.key === KeyTypes.ArrowRight) {
|
|
738
|
-
this.handleMenuKeys(0, 0, 'right');
|
|
739
|
-
event.preventDefault();
|
|
740
|
-
}
|
|
741
|
-
else if (event.key === KeyTypes.Tab && variant !== SelectVariant.checkbox && this.props.footer) {
|
|
742
|
-
// tab to footer or close menu if shift key
|
|
743
|
-
if (event.shiftKey) {
|
|
744
|
-
this.onToggle(event, false);
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
747
|
-
const tabbableItems = findTabbableElements(this.footerRef, SelectFooterTabbableItems);
|
|
748
|
-
if (tabbableItems.length > 0) {
|
|
749
|
-
tabbableItems[0].focus();
|
|
750
|
-
event.stopPropagation();
|
|
751
|
-
event.preventDefault();
|
|
752
|
-
}
|
|
753
|
-
else {
|
|
754
|
-
this.onToggle(event, false);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
else if (event.key === KeyTypes.Tab && variant === SelectVariant.checkbox) {
|
|
759
|
-
// More modal-like experience for checkboxes
|
|
760
|
-
// Let SelectOption handle this
|
|
761
|
-
if (event.shiftKey) {
|
|
762
|
-
this.handleMenuKeys(0, 0, 'up');
|
|
763
|
-
}
|
|
764
|
-
else {
|
|
765
|
-
this.handleMenuKeys(0, 0, 'down');
|
|
766
|
-
}
|
|
767
|
-
event.stopPropagation();
|
|
768
|
-
event.preventDefault();
|
|
769
|
-
}
|
|
770
|
-
}, ref: this.filterRef, autoComplete: inputAutoComplete })),
|
|
771
|
-
React.createElement(Divider, { key: "inline-filter-divider" })));
|
|
772
|
-
renderableItems = [filterBox, ...typeaheadFilteredChildren].map((option, index) => React.cloneElement(option, { key: index }));
|
|
773
|
-
}
|
|
774
|
-
let variantProps;
|
|
775
|
-
let variantChildren;
|
|
776
|
-
if (customContent) {
|
|
777
|
-
variantProps = {
|
|
778
|
-
selected: selections,
|
|
779
|
-
openedOnEnter,
|
|
780
|
-
isCustomContent: true
|
|
781
|
-
};
|
|
782
|
-
variantChildren = customContent;
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
switch (variant) {
|
|
786
|
-
case 'single':
|
|
787
|
-
variantProps = {
|
|
788
|
-
selected: selections[0],
|
|
789
|
-
hasInlineFilter,
|
|
790
|
-
openedOnEnter
|
|
791
|
-
};
|
|
792
|
-
variantChildren = renderableItems;
|
|
793
|
-
break;
|
|
794
|
-
case 'checkbox':
|
|
795
|
-
variantProps = {
|
|
796
|
-
checked: selections,
|
|
797
|
-
isGrouped,
|
|
798
|
-
hasInlineFilter,
|
|
799
|
-
openedOnEnter
|
|
800
|
-
};
|
|
801
|
-
variantChildren = renderableItems;
|
|
802
|
-
break;
|
|
803
|
-
case 'typeahead':
|
|
804
|
-
variantProps = {
|
|
805
|
-
selected: selections[0],
|
|
806
|
-
openedOnEnter
|
|
807
|
-
};
|
|
808
|
-
variantChildren = onFavorite ? renderableItems : this.extendTypeaheadChildren(typeaheadCurrIndex);
|
|
809
|
-
if (variantChildren.length === 0) {
|
|
810
|
-
variantChildren.push(React.createElement(SelectOption, { isDisabled: true, key: 0, value: noResultsFoundText, isNoResultsOption: true }));
|
|
811
|
-
}
|
|
812
|
-
break;
|
|
813
|
-
case 'typeaheadmulti':
|
|
814
|
-
variantProps = {
|
|
815
|
-
selected: selections,
|
|
816
|
-
openedOnEnter
|
|
817
|
-
};
|
|
818
|
-
variantChildren = onFavorite ? renderableItems : this.extendTypeaheadChildren(typeaheadCurrIndex);
|
|
819
|
-
if (variantChildren.length === 0) {
|
|
820
|
-
variantChildren.push(React.createElement(SelectOption, { isDisabled: true, key: 0, value: noResultsFoundText, isNoResultsOption: true }));
|
|
821
|
-
}
|
|
822
|
-
break;
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
const isStatic = isFlipEnabled && menuAppendTo !== 'inline';
|
|
826
|
-
const innerMenu = (React.createElement(SelectMenu, Object.assign({ className: css(isStatic && styles.modifiers.static) }, props, { isGrouped: isGrouped, selected: selections }, variantProps, { openedOnEnter: openedOnEnter, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, sendRef: this.sendRef, keyHandler: this.handleMenuKeys, maxHeight: maxHeight, ref: this.menuComponentRef, footer: footer, footerRef: this.footerRef, isLastOptionBeforeFooter: this.isLastOptionBeforeFooter }), variantChildren));
|
|
827
|
-
const menuContainer = footer ? React.createElement("div", { className: css(styles.selectMenu) },
|
|
828
|
-
" ",
|
|
829
|
-
innerMenu,
|
|
830
|
-
" ") : innerMenu;
|
|
831
|
-
const popperRef = React.createRef();
|
|
832
|
-
const popperContainer = (React.createElement("div", Object.assign({ className: css(styles.select, isOpen && styles.modifiers.expanded, validated === ValidatedOptions.success && styles.modifiers.success, validated === ValidatedOptions.warning && styles.modifiers.warning, validated === ValidatedOptions.error && styles.modifiers.invalid, direction === SelectDirection.up && styles.modifiers.top, className), ref: popperRef }, (width && { style: { width } }), (validated !== ValidatedOptions.default && { 'aria-invalid': ariaInvalid })), isOpen && menuContainer));
|
|
833
|
-
const mainContainer = (React.createElement("div", Object.assign({ className: css(styles.select, isOpen && styles.modifiers.expanded, validated === ValidatedOptions.success && styles.modifiers.success, validated === ValidatedOptions.warning && styles.modifiers.warning, validated === ValidatedOptions.error && styles.modifiers.invalid, direction === SelectDirection.up && styles.modifiers.top, className), ref: this.parentRef }, getOUIAProps(Select.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId, ouiaSafe), (width && { style: { width } }), (validated !== ValidatedOptions.default && { 'aria-invalid': ariaInvalid })),
|
|
834
|
-
React.createElement(SelectToggle, Object.assign({ id: selectToggleId, parentRef: this.parentRef, menuRef: this.menuComponentRef, ref: toggleRef }, (footer && { footerRef: this.footerRef }), { isOpen: isOpen, isPlain: isPlain, hasPlaceholderStyle: hasPlaceholderStyle && (!selections.length || selections[0] === null || isSelectedPlaceholder), onToggle: this.onToggle, onEnter: this.onEnter, onClose: this.onClose, onBlur: onBlur, variant: variant, toggleIndicator: toggleIndicator, "aria-labelledby": `${ariaLabelledBy || ''} ${selectToggleId}`, "aria-label": toggleAriaLabel }, (ariaDescribedby && { 'aria-describedby': ariaDescribedby }), { handleTypeaheadKeys: this.handleTypeaheadKeys, moveFocusToLastMenuItem: this.moveFocusToLastMenuItem, isDisabled: isDisabled, hasClearButton: hasOnClear, hasFooter: footer !== undefined, onClickTypeaheadToggleButton: this.onClickTypeaheadToggleButton }),
|
|
835
|
-
customContent && (React.createElement("div", { className: css(styles.selectToggleWrapper) },
|
|
836
|
-
toggleIcon && React.createElement("span", { className: css(styles.selectToggleIcon) }, toggleIcon),
|
|
837
|
-
React.createElement("span", { className: css(styles.selectToggleText) }, placeholderText))),
|
|
838
|
-
variant === SelectVariant.single && !customContent && (React.createElement(React.Fragment, null,
|
|
839
|
-
React.createElement("div", { className: css(styles.selectToggleWrapper) },
|
|
840
|
-
toggleIcon && React.createElement("span", { className: css(styles.selectToggleIcon) }, toggleIcon),
|
|
841
|
-
React.createElement("span", { className: css(styles.selectToggleText) }, this.getDisplay(selections[0], 'node') || placeholderText || childPlaceholderText)),
|
|
842
|
-
hasOnClear && hasAnySelections && clearBtn)),
|
|
843
|
-
variant === SelectVariant.checkbox && !customContent && (React.createElement(React.Fragment, null,
|
|
844
|
-
React.createElement("div", { className: css(styles.selectToggleWrapper) },
|
|
845
|
-
toggleIcon && React.createElement("span", { className: css(styles.selectToggleIcon) }, toggleIcon),
|
|
846
|
-
React.createElement("span", { className: css(styles.selectToggleText) }, placeholderText),
|
|
847
|
-
!isCheckboxSelectionBadgeHidden && hasAnySelections && (React.createElement("div", { className: css(styles.selectToggleBadge) },
|
|
848
|
-
React.createElement("span", { className: css(badgeStyles.badge, badgeStyles.modifiers.read) }, this.generateSelectedBadge())))),
|
|
849
|
-
hasOnClear && hasAnySelections && clearBtn)),
|
|
850
|
-
variant === SelectVariant.typeahead && !customContent && (React.createElement(React.Fragment, null,
|
|
851
|
-
React.createElement("div", { className: css(styles.selectToggleWrapper) },
|
|
852
|
-
toggleIcon && React.createElement("span", { className: css(styles.selectToggleIcon) }, toggleIcon),
|
|
853
|
-
React.createElement("input", Object.assign({ className: css(formStyles.formControl, styles.selectToggleTypeahead), "aria-activedescendant": typeaheadActiveChild && typeaheadActiveChild.id, id: `${selectToggleId}-select-typeahead`, "aria-label": typeAheadAriaLabel }, (typeAheadAriaDescribedby && { 'aria-describedby': typeAheadAriaDescribedby }), { placeholder: placeholderText, value: typeaheadInputValue !== null
|
|
854
|
-
? typeaheadInputValue
|
|
855
|
-
: this.getDisplay(selections[0], 'text') || '', type: "text", onClick: this.onClick, onChange: this.onChange, autoComplete: inputAutoComplete, disabled: isDisabled, ref: this.inputRef }))),
|
|
856
|
-
hasOnClear && (selections[0] || typeaheadInputValue) && clearBtn)),
|
|
857
|
-
variant === SelectVariant.typeaheadMulti && !customContent && (React.createElement(React.Fragment, null,
|
|
858
|
-
React.createElement("div", { className: css(styles.selectToggleWrapper) },
|
|
859
|
-
toggleIcon && React.createElement("span", { className: css(styles.selectToggleIcon) }, toggleIcon),
|
|
860
|
-
selections && Array.isArray(selections) && selections.length > 0 && selectedChips,
|
|
861
|
-
React.createElement("input", Object.assign({ className: css(formStyles.formControl, styles.selectToggleTypeahead), "aria-activedescendant": typeaheadActiveChild && typeaheadActiveChild.id, id: `${selectToggleId}-select-multi-typeahead-typeahead`, "aria-label": typeAheadAriaLabel, "aria-invalid": validated === ValidatedOptions.error }, (typeAheadAriaDescribedby && { 'aria-describedby': typeAheadAriaDescribedby }), { placeholder: placeholderText, value: typeaheadInputValue !== null ? typeaheadInputValue : '', type: "text", onChange: this.onChange, onClick: this.onClick, autoComplete: inputAutoComplete, disabled: isDisabled, ref: this.inputRef }))),
|
|
862
|
-
hasOnClear && ((selections && selections.length > 0) || typeaheadInputValue) && clearBtn)),
|
|
863
|
-
validated === ValidatedOptions.success && (React.createElement("span", { className: css(styles.selectToggleStatusIcon) },
|
|
864
|
-
React.createElement(CheckCircleIcon, { "aria-hidden": "true" }))),
|
|
865
|
-
validated === ValidatedOptions.error && (React.createElement("span", { className: css(styles.selectToggleStatusIcon) },
|
|
866
|
-
React.createElement(ExclamationCircleIcon, { "aria-hidden": "true" }))),
|
|
867
|
-
validated === ValidatedOptions.warning && (React.createElement("span", { className: css(styles.selectToggleStatusIcon) },
|
|
868
|
-
React.createElement(ExclamationTriangleIcon, { "aria-hidden": "true" })))),
|
|
869
|
-
isOpen && menuAppendTo === 'inline' && menuContainer));
|
|
870
|
-
const getParentElement = () => {
|
|
871
|
-
if (this.parentRef && this.parentRef.current) {
|
|
872
|
-
return this.parentRef.current.parentElement;
|
|
873
|
-
}
|
|
874
|
-
return null;
|
|
875
|
-
};
|
|
876
|
-
return (React.createElement(GenerateId, null, randomId => (React.createElement(SelectContext.Provider, { value: {
|
|
877
|
-
onSelect,
|
|
878
|
-
onFavorite,
|
|
879
|
-
onClose: this.onClose,
|
|
880
|
-
variant,
|
|
881
|
-
inputIdPrefix: inputIdPrefix || randomId,
|
|
882
|
-
shouldResetOnSelect
|
|
883
|
-
} }, menuAppendTo === 'inline' ? (mainContainer) : (React.createElement(Popper, { trigger: mainContainer, triggerRef: this.parentRef, popper: popperContainer, popperRef: popperRef, direction: direction, appendTo: menuAppendTo === 'parent' ? getParentElement() : menuAppendTo, isVisible: isOpen, zIndex: zIndex }))))));
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
Select.displayName = 'Select';
|
|
887
|
-
Select.defaultProps = {
|
|
888
|
-
children: [],
|
|
889
|
-
className: '',
|
|
890
|
-
position: SelectPosition.left,
|
|
891
|
-
direction: SelectDirection.down,
|
|
892
|
-
toggleId: null,
|
|
893
|
-
isOpen: false,
|
|
894
|
-
isGrouped: false,
|
|
895
|
-
isPlain: false,
|
|
896
|
-
isDisabled: false,
|
|
897
|
-
hasPlaceholderStyle: false,
|
|
898
|
-
isCreatable: false,
|
|
899
|
-
isCreateOptionOnTop: false,
|
|
900
|
-
validated: 'default',
|
|
901
|
-
'aria-label': '',
|
|
902
|
-
'aria-labelledby': '',
|
|
903
|
-
'aria-describedby': '',
|
|
904
|
-
'aria-invalid': false,
|
|
905
|
-
typeAheadAriaLabel: '',
|
|
906
|
-
typeAheadAriaDescribedby: '',
|
|
907
|
-
clearSelectionsAriaLabel: 'Clear all',
|
|
908
|
-
toggleAriaLabel: 'Options menu',
|
|
909
|
-
removeSelectionAriaLabel: 'Remove',
|
|
910
|
-
selections: [],
|
|
911
|
-
createText: 'Create',
|
|
912
|
-
placeholderText: '',
|
|
913
|
-
noResultsFoundText: 'No results found',
|
|
914
|
-
variant: SelectVariant.single,
|
|
915
|
-
width: '',
|
|
916
|
-
onClear: () => undefined,
|
|
917
|
-
onCreateOption: () => undefined,
|
|
918
|
-
toggleIcon: null,
|
|
919
|
-
toggleIndicator: null,
|
|
920
|
-
onFilter: null,
|
|
921
|
-
onTypeaheadInputChanged: null,
|
|
922
|
-
customContent: null,
|
|
923
|
-
hasInlineFilter: false,
|
|
924
|
-
inlineFilterPlaceholderText: null,
|
|
925
|
-
customBadgeText: null,
|
|
926
|
-
inputIdPrefix: '',
|
|
927
|
-
inputAutoComplete: 'off',
|
|
928
|
-
menuAppendTo: 'inline',
|
|
929
|
-
favorites: [],
|
|
930
|
-
favoritesLabel: 'Favorites',
|
|
931
|
-
ouiaSafe: true,
|
|
932
|
-
chipGroupComponent: null,
|
|
933
|
-
isInputValuePersisted: false,
|
|
934
|
-
isInputFilterPersisted: false,
|
|
935
|
-
isCreateSelectOptionObject: false,
|
|
936
|
-
shouldResetOnSelect: true,
|
|
937
|
-
isFlipEnabled: true,
|
|
938
|
-
zIndex: 9999
|
|
6
|
+
import { getOUIAProps, getDefaultOUIAId } from '../../helpers';
|
|
7
|
+
const SelectBase = (_a) => {
|
|
8
|
+
var { children, className, onSelect, isOpen, selected, toggle, onOpenChange, isPlain, innerRef, zIndex = 9999, role = 'listbox', popperProps } = _a, props = __rest(_a, ["children", "className", "onSelect", "isOpen", "selected", "toggle", "onOpenChange", "isPlain", "innerRef", "zIndex", "role", "popperProps"]);
|
|
9
|
+
const localMenuRef = React.useRef();
|
|
10
|
+
const toggleRef = React.useRef();
|
|
11
|
+
const containerRef = React.useRef();
|
|
12
|
+
const menuRef = innerRef || localMenuRef;
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
const handleMenuKeys = (event) => {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
// Close the menu on tab or escape if onOpenChange is provided
|
|
17
|
+
if ((isOpen && onOpenChange && ((_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) ||
|
|
18
|
+
((_b = toggleRef.current) === null || _b === void 0 ? void 0 : _b.contains(event.target))) {
|
|
19
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
20
|
+
onOpenChange(false);
|
|
21
|
+
(_c = toggleRef.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const handleClick = (event) => {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
// toggle was clicked open via keyboard, focus on first menu item
|
|
28
|
+
if (isOpen && ((_a = toggleRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)) && event.detail === 0) {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
var _a;
|
|
31
|
+
const firstElement = (_a = menuRef === null || menuRef === void 0 ? void 0 : menuRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('li button:not(:disabled),li input:not(:disabled)');
|
|
32
|
+
firstElement && firstElement.focus();
|
|
33
|
+
}, 0);
|
|
34
|
+
}
|
|
35
|
+
// If the event is not on the toggle and onOpenChange callback is provided, close the menu
|
|
36
|
+
if (isOpen && onOpenChange && !((_b = toggleRef === null || toggleRef === void 0 ? void 0 : toggleRef.current) === null || _b === void 0 ? void 0 : _b.contains(event.target))) {
|
|
37
|
+
if (isOpen && !((_c = menuRef.current) === null || _c === void 0 ? void 0 : _c.contains(event.target))) {
|
|
38
|
+
onOpenChange(false);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
window.addEventListener('keydown', handleMenuKeys);
|
|
43
|
+
window.addEventListener('click', handleClick);
|
|
44
|
+
return () => {
|
|
45
|
+
window.removeEventListener('keydown', handleMenuKeys);
|
|
46
|
+
window.removeEventListener('click', handleClick);
|
|
47
|
+
};
|
|
48
|
+
}, [isOpen, menuRef, onOpenChange]);
|
|
49
|
+
const menu = (React.createElement(Menu, Object.assign({ role: role, className: css(className), ref: menuRef, onSelect: (event, itemId) => onSelect && onSelect(event, itemId), isPlain: isPlain, selected: selected }, getOUIAProps(Select.displayName, props.ouiaId !== undefined ? props.ouiaId : getDefaultOUIAId(Select.displayName), props.ouiaSafe !== undefined ? props.ouiaSafe : true), props),
|
|
50
|
+
React.createElement(MenuContent, null, children)));
|
|
51
|
+
return (React.createElement("div", { ref: containerRef },
|
|
52
|
+
React.createElement(Popper, Object.assign({ trigger: toggle(toggleRef), triggerRef: toggleRef, popper: menu, popperRef: menuRef, appendTo: containerRef.current || undefined, isVisible: isOpen, zIndex: zIndex }, popperProps))));
|
|
939
53
|
};
|
|
54
|
+
export const Select = React.forwardRef((props, ref) => (React.createElement(SelectBase, Object.assign({ innerRef: ref }, props))));
|
|
55
|
+
Select.displayName = 'Select';
|
|
940
56
|
//# sourceMappingURL=Select.js.map
|