@patternfly/react-core 4.176.0 → 4.179.1

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.
Files changed (121) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/esm/components/Card/Card.d.ts +5 -7
  3. package/dist/esm/components/Card/Card.d.ts.map +1 -1
  4. package/dist/esm/components/Card/Card.js +14 -2
  5. package/dist/esm/components/Card/Card.js.map +1 -1
  6. package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -1
  7. package/dist/esm/components/DragDrop/Droppable.js +5 -1
  8. package/dist/esm/components/DragDrop/Droppable.js.map +1 -1
  9. package/dist/esm/components/Dropdown/DropdownToggle.d.ts +3 -1
  10. package/dist/esm/components/Dropdown/DropdownToggle.d.ts.map +1 -1
  11. package/dist/esm/components/Dropdown/DropdownToggle.js +4 -4
  12. package/dist/esm/components/Dropdown/DropdownToggle.js.map +1 -1
  13. package/dist/esm/components/Dropdown/Toggle.d.ts +3 -1
  14. package/dist/esm/components/Dropdown/Toggle.d.ts.map +1 -1
  15. package/dist/esm/components/Dropdown/Toggle.js +8 -3
  16. package/dist/esm/components/Dropdown/Toggle.js.map +1 -1
  17. package/dist/esm/components/MenuToggle/MenuToggle.d.ts +1 -1
  18. package/dist/esm/components/MenuToggle/MenuToggle.d.ts.map +1 -1
  19. package/dist/esm/components/MenuToggle/MenuToggle.js +2 -1
  20. package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
  21. package/dist/esm/components/Popover/Popover.d.ts.map +1 -1
  22. package/dist/esm/components/Popover/Popover.js +2 -22
  23. package/dist/esm/components/Popover/Popover.js.map +1 -1
  24. package/dist/js/components/Card/Card.d.ts +5 -7
  25. package/dist/js/components/Card/Card.d.ts.map +1 -1
  26. package/dist/js/components/Card/Card.js +14 -2
  27. package/dist/js/components/Card/Card.js.map +1 -1
  28. package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -1
  29. package/dist/js/components/DragDrop/Droppable.js +5 -1
  30. package/dist/js/components/DragDrop/Droppable.js.map +1 -1
  31. package/dist/js/components/Dropdown/DropdownToggle.d.ts +3 -1
  32. package/dist/js/components/Dropdown/DropdownToggle.d.ts.map +1 -1
  33. package/dist/js/components/Dropdown/DropdownToggle.js +4 -4
  34. package/dist/js/components/Dropdown/DropdownToggle.js.map +1 -1
  35. package/dist/js/components/Dropdown/Toggle.d.ts +3 -1
  36. package/dist/js/components/Dropdown/Toggle.d.ts.map +1 -1
  37. package/dist/js/components/Dropdown/Toggle.js +8 -3
  38. package/dist/js/components/Dropdown/Toggle.js.map +1 -1
  39. package/dist/js/components/MenuToggle/MenuToggle.d.ts +1 -1
  40. package/dist/js/components/MenuToggle/MenuToggle.d.ts.map +1 -1
  41. package/dist/js/components/MenuToggle/MenuToggle.js +2 -1
  42. package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
  43. package/dist/js/components/Popover/Popover.d.ts.map +1 -1
  44. package/dist/js/components/Popover/Popover.js +2 -22
  45. package/dist/js/components/Popover/Popover.js.map +1 -1
  46. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Black.woff2 +0 -0
  47. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-BlackItalic.woff2 +0 -0
  48. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Bold.woff2 +0 -0
  49. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-BoldItalic.woff2 +0 -0
  50. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Italic.woff2 +0 -0
  51. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Light.woff2 +0 -0
  52. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-LightItalic.woff2 +0 -0
  53. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Medium.woff2 +0 -0
  54. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-MediumItalic.woff2 +0 -0
  55. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplay-updated-Regular.woff2 +0 -0
  56. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplayVF-updated-Italic.woff2 +0 -0
  57. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatDisplay/RedHatDisplayVF-updated.woff2 +0 -0
  58. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Bold.woff2 +0 -0
  59. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-BoldItalic.woff2 +0 -0
  60. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Italic.woff2 +0 -0
  61. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Light.woff2 +0 -0
  62. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-LightItalic.woff2 +0 -0
  63. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Medium.woff2 +0 -0
  64. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-MediumItalic.woff2 +0 -0
  65. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMono-updated-Regular.woff2 +0 -0
  66. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMonoVF-updated-Italic.woff2 +0 -0
  67. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatMono/RedHatMonoVF-updated.woff2 +0 -0
  68. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Bold.woff2 +0 -0
  69. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-BoldItalic.woff2 +0 -0
  70. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Italic.woff2 +0 -0
  71. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Light.woff2 +0 -0
  72. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-LightItalic.woff2 +0 -0
  73. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Medium.woff2 +0 -0
  74. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-MediumItalic.woff2 +0 -0
  75. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Regular.woff2 +0 -0
  76. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatTextVF-updated-Italic.woff2 +0 -0
  77. package/dist/styles/assets/fonts/RedHatFont-updated/RedHatText/RedHatTextVF-updated.woff2 +0 -0
  78. package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatDisplayVF-updated-ItalicModified.woff2 +0 -0
  79. package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatDisplayVFModified-updated.woff2 +0 -0
  80. package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatTextVF-updated-ItalicModified.woff2 +0 -0
  81. package/dist/styles/assets/fonts/RedHatFont-updated/modified/RedHatTextVFModified-updated.woff2 +0 -0
  82. package/dist/styles/base-no-reset.css +121 -0
  83. package/dist/styles/base.css +121 -15
  84. package/dist/umd/react-core.css +183 -12
  85. package/dist/umd/react-core.js +44 -35
  86. package/dist/umd/react-core.min.css +4004 -3833
  87. package/dist/umd/react-core.min.js +2 -2
  88. package/package.json +6 -6
  89. package/src/components/Alert/examples/Alert.md +201 -382
  90. package/src/components/Alert/examples/AlertAsyncLiveRegion.tsx +61 -0
  91. package/src/components/Alert/examples/AlertDynamicLiveRegion.tsx +61 -0
  92. package/src/components/ApplicationLauncher/__tests__/__snapshots__/ApplicationLauncher.test.tsx.snap +6 -0
  93. package/src/components/Card/Card.tsx +23 -17
  94. package/src/components/Card/__tests__/Card.test.tsx +8 -14
  95. package/src/components/Card/__tests__/__snapshots__/Card.test.tsx.snap +2 -12
  96. package/src/components/Card/examples/Card.md +230 -264
  97. package/src/components/DragDrop/Droppable.tsx +5 -1
  98. package/src/components/DragDrop/examples/DragDrop.md +2 -0
  99. package/src/components/Dropdown/DropdownToggle.tsx +6 -1
  100. package/src/components/Dropdown/Toggle.tsx +11 -1
  101. package/src/components/Dropdown/__tests__/DropdownToggle.test.tsx +51 -0
  102. package/src/components/Dropdown/__tests__/__snapshots__/Dropdown.test.tsx.snap +8 -0
  103. package/src/components/Dropdown/__tests__/__snapshots__/DropdownToggle.test.tsx.snap +346 -4
  104. package/src/components/Dropdown/__tests__/__snapshots__/Toggle.test.tsx.snap +1 -0
  105. package/src/components/Dropdown/examples/Dropdown.md +160 -91
  106. package/src/components/MenuToggle/MenuToggle.tsx +5 -2
  107. package/src/components/MenuToggle/__tests__/MenuToggle.test.tsx +5 -0
  108. package/src/components/MenuToggle/__tests__/__snapshots__/MenuToggle.test.tsx.snap +59 -0
  109. package/src/components/MenuToggle/examples/MenuToggle.md +60 -67
  110. package/src/components/OptionsMenu/__tests__/__snapshots__/OptionsMenu.test.tsx.snap +7 -0
  111. package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +15 -0
  112. package/src/components/Popover/Popover.tsx +1 -19
  113. package/src/components/Popover/__tests__/Generated/__snapshots__/Popover.test.tsx.snap +0 -1
  114. package/src/components/Popover/__tests__/__snapshots__/Popover.test.tsx.snap +0 -4
  115. package/src/demos/Card/Card.md +47 -23
  116. package/src/demos/CardDemos.md +65 -91
  117. package/src/demos/Tabs/NestedTabsDemo.js +151 -0
  118. package/src/demos/Tabs.md +4 -0
  119. package/src/demos/TextInputGroupDemo.md +8 -246
  120. package/src/demos/examples/TextInputGroup/AttributeValueFiltering.js +250 -0
  121. package/src/demos/examples/TextInputGroup/AutoCompleteSearch.js +230 -0
@@ -0,0 +1,151 @@
1
+ import React from 'react';
2
+ import {
3
+ Card,
4
+ CardHeader,
5
+ CardBody,
6
+ Grid,
7
+ GridItem,
8
+ PageSection,
9
+ PageSectionVariants,
10
+ Tabs,
11
+ Tab,
12
+ TabContent,
13
+ TabContentBody,
14
+ TabTitleText,
15
+ Title,
16
+ Flex,
17
+ FlexItem
18
+ } from '@patternfly/react-core';
19
+ import DashboardWrapper from '../examples/DashboardWrapper';
20
+
21
+ export const NestedTabsDemo = () => {
22
+ const [activeTabKey, setActiveTabKey] = React.useState(0);
23
+ const [activeNestedTabKey, setActiveNestedTabKey] = React.useState(10);
24
+
25
+ // Toggle currently active tab
26
+ const handleTabClick = (_, tabIndex) => setActiveTabKey(tabIndex);
27
+
28
+ // Toggle currently active nested tab
29
+ const handleNestedTabClick = (_, tabIndex) => setActiveNestedTabKey(tabIndex);
30
+
31
+ const tabContent = (
32
+ <Grid hasGutter>
33
+ <GridItem xl={8} md={6}>
34
+ <Card>
35
+ <CardHeader>
36
+ <Title headingLevel="h2">Status</Title>
37
+ </CardHeader>
38
+ <CardBody>
39
+ <Flex direction={{ default: 'column' }}>
40
+ <FlexItem>
41
+ <Tabs
42
+ activeKey={activeNestedTabKey}
43
+ isSecondary
44
+ onSelect={handleNestedTabClick}
45
+ id="nested-tabs-example-tabs-list"
46
+ >
47
+ <Tab eventKey={10} title={<TabTitleText>Cluster</TabTitleText>} tabContentId={`tabContent${10}`} />
48
+ <Tab
49
+ eventKey={11}
50
+ title={<TabTitleText>Control plane</TabTitleText>}
51
+ tabContentId={`tabContent${11}`}
52
+ />
53
+ <Tab eventKey={12} title={<TabTitleText>Operators</TabTitleText>} tabContentId={`tabContent${12}`} />
54
+ <Tab
55
+ eventKey={13}
56
+ title={<TabTitleText>Virtualization</TabTitleText>}
57
+ tabContentId={`tabContent${13}`}
58
+ />
59
+ </Tabs>
60
+ </FlexItem>
61
+ <FlexItem>
62
+ <TabContent
63
+ key={10}
64
+ eventKey={10}
65
+ id={`tabContent${10}`}
66
+ activeKey={activeNestedTabKey}
67
+ hidden={10 !== activeNestedTabKey}
68
+ >
69
+ <TabContentBody>
70
+ {
71
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in odio porttitor, feugiat risus in, feugiat arcu. Nullam euismod enim eget fringilla condimentum. Maecenas tincidunt et metus id aliquet. Integer et fermentum purus. Nulla tempor velit arcu, vitae semper purus iaculis at. Sed malesuada auctor luctus. Pellentesque et leo urna. Aliquam vitae felis congue lacus mattis fringilla. Nullam et ultricies erat, sed dignissim elit. Cras mattis pulvinar aliquam. In ac est nulla. Pellentesque fermentum nibh ac sapien porta, ut congue orci aliquam. Sed nisl est, tempor eu pharetra eget, ullamcorper ut augue. Vestibulum eleifend libero eu nulla cursus lacinia.'
72
+ }
73
+ </TabContentBody>
74
+ </TabContent>
75
+ <TabContent
76
+ key={11}
77
+ eventKey={11}
78
+ id={`tabContent${11}`}
79
+ activeKey={activeNestedTabKey}
80
+ hidden={11 !== activeNestedTabKey}
81
+ >
82
+ <TabContentBody>Control plane panel</TabContentBody>
83
+ </TabContent>
84
+ <TabContent
85
+ key={12}
86
+ eventKey={12}
87
+ id={`tabContent${12}`}
88
+ activeKey={activeNestedTabKey}
89
+ hidden={12 !== activeNestedTabKey}
90
+ >
91
+ <TabContentBody>Operators panel</TabContentBody>
92
+ </TabContent>
93
+ <TabContent
94
+ key={13}
95
+ eventKey={13}
96
+ id={`tabContent${13}`}
97
+ activeKey={activeNestedTabKey}
98
+ hidden={13 !== activeNestedTabKey}
99
+ >
100
+ <TabContentBody>Virtualization panel</TabContentBody>
101
+ </TabContent>
102
+ </FlexItem>
103
+ </Flex>
104
+ </CardBody>
105
+ </Card>
106
+ </GridItem>
107
+ <GridItem xl={4} md={6}>
108
+ <Flex direction={{ default: 'column' }} className="pf-u-h-100">
109
+ <FlexItem flex={{ default: 'flex_1' }}>
110
+ <Card isFullHeight>
111
+ <CardHeader>
112
+ <Title headingLevel="h3">Title of Card</Title>
113
+ </CardHeader>
114
+ </Card>
115
+ </FlexItem>
116
+ <FlexItem flex={{ default: 'flex_1' }}>
117
+ <Card isFullHeight>
118
+ <CardHeader>
119
+ <Title headingLevel="h3">Title of Card</Title>
120
+ </CardHeader>
121
+ </Card>
122
+ </FlexItem>
123
+ </Flex>
124
+ </GridItem>
125
+ </Grid>
126
+ );
127
+
128
+ return (
129
+ <DashboardWrapper hasNoBreadcrumb>
130
+ <PageSection isWidthLimited variant={PageSectionVariants.light}>
131
+ <Title headingLevel="h1" size="2xl">
132
+ Overview
133
+ </Title>
134
+ </PageSection>
135
+ <PageSection type="tabs" variant={PageSectionVariants.light} isWidthLimited>
136
+ <Tabs activeKey={activeTabKey} onSelect={handleTabClick} usePageInsets id="nested-tabs-example-tabs-list">
137
+ <Tab eventKey={0} title={<TabTitleText>Cluster 1</TabTitleText>} tabContentId={`tabContent${0}`} />
138
+ <Tab eventKey={1} title={<TabTitleText>Cluster 2</TabTitleText>} tabContentId={`tabContent${1}`} />
139
+ </Tabs>
140
+ </PageSection>
141
+ <PageSection isWidthLimited>
142
+ <TabContent key={0} eventKey={0} id={`tabContent${0}`} activeKey={activeTabKey} hidden={0 !== activeTabKey}>
143
+ <TabContentBody>{tabContent}</TabContentBody>
144
+ </TabContent>
145
+ <TabContent key={1} eventKey={1} id={`tabContent${1}`} activeKey={activeTabKey} hidden={1 !== activeTabKey}>
146
+ <TabContentBody>Cluster 2 panel</TabContentBody>
147
+ </TabContent>
148
+ </PageSection>
149
+ </DashboardWrapper>
150
+ );
151
+ };
package/src/demos/Tabs.md CHANGED
@@ -437,3 +437,7 @@ TabsOpenWithSecondaryTabsDemo = () => {
437
437
  );
438
438
  };
439
439
  ```
440
+
441
+ ### Nested tabs
442
+ ```js isFullscreen file="./Tabs/NestedTabsDemo.js"
443
+ ```
@@ -24,255 +24,17 @@ Additionally, attributes can be selected by typing the full (case sensitive) nam
24
24
 
25
25
  Attributes can be deselected (returning you to attribute selection mode) by hitting `escape`, or by hitting `backspace` when the only text in the text input is the attribute.
26
26
 
27
- ```js
28
- import React from 'react';
29
- import {
30
- TextInputGroup,
31
- TextInputGroupMain,
32
- TextInputGroupUtilities,
33
- Button,
34
- Menu,
35
- MenuContent,
36
- MenuList,
37
- MenuItem,
38
- Popper,
39
- Chip,
40
- ChipGroup,
41
- Divider
42
- } from '@patternfly/react-core';
43
- import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
44
- import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
45
-
46
- export const KeyValueFiltering = () => {
47
- const [inputValue, setInputValue] = React.useState('');
48
- const [selectedKey, setSelectedKey] = React.useState('');
49
- const [menuIsOpen, setMenuIsOpen] = React.useState(false);
50
- const [currentChips, setCurrentChips] = React.useState([]);
51
-
52
- /** key and value data to be shown in the menu */
53
- const data = {
54
- Cluster: ['acmeqe-managed-1', 'local-cluster'],
55
- Kind: ['Template', 'ReplicationController', 'ReplicaSet', 'Deployment'],
56
- Label: ['release', 'environment', 'partition'],
57
- Name: ['backup-1', 'backup-2', 'production-1', 'production-2', 'testing'],
58
- Namespace: ['default', 'public'],
59
- Status: ['running', 'idle', 'stopped']
60
- };
61
- const keyNames = ['Cluster', 'Kind', 'Label', 'Name', 'Namespace', 'Status'];
62
- const [menuItemsText, setMenuItemsText] = React.useState(keyNames);
63
- const [menuItems, setMenuItems] = React.useState([]);
64
-
65
- /** refs used to detect when clicks occur inside vs outside of the textInputGroup and menu popper */
66
- const menuRef = React.useRef();
67
- const textInputGroupRef = React.useRef();
68
-
69
- /** callback for updating the inputValue state in this component so that the input can be controlled */
70
- const handleInputChange = (value, _event) => {
71
- setInputValue(value);
72
- };
73
-
74
- /** callback for removing a chip from the chip selections */
75
- const deleteChip = chipToDelete => {
76
- const newChips = currentChips.filter(chip => !Object.is(chip, chipToDelete));
77
- setCurrentChips(newChips);
78
- };
79
-
80
- /** reset state hooks associated with key selection */
81
- const clearSelectedKey = () => {
82
- setInputValue('');
83
- setSelectedKey('');
84
- setMenuItemsText(keyNames);
85
- };
86
-
87
- /** callback for clearing all selected chips, the text input, and any selected keys */
88
- const clearChipsAndInput = () => {
89
- setCurrentChips([]);
90
- clearSelectedKey();
91
- };
92
-
93
- React.useEffect(() => {
94
- /** in the menu only show items that include the text in the input */
95
- const filteredMenuItems = menuItemsText
96
- .filter(
97
- item =>
98
- !inputValue ||
99
- item.toLowerCase().includes(
100
- inputValue
101
- .toString()
102
- .slice(selectedKey.length && selectedKey.length + 2)
103
- .toLowerCase()
104
- )
105
- )
106
- .map((currentValue, index) => (
107
- <MenuItem key={currentValue} itemId={index}>
108
- {currentValue}
109
- </MenuItem>
110
- ));
111
-
112
- /** in the menu show a disabled "no result" when all menu items are filtered out */
113
- if (filteredMenuItems.length === 0) {
114
- const noResultItem = (
115
- <MenuItem isDisabled key="no result">
116
- No results found
117
- </MenuItem>
118
- );
119
- setMenuItems([noResultItem]);
120
- return;
121
- }
122
-
123
- /** determine the menu heading text based on key selection; or lack thereof */
124
- const headingItem = (
125
- <MenuItem isDisabled key="heading">
126
- {selectedKey.length ? `${selectedKey} values` : 'Attributes'}
127
- </MenuItem>
128
- );
129
-
130
- const divider = <Divider key="divider" />;
131
-
132
- setMenuItems([headingItem, divider, ...filteredMenuItems]);
133
- }, [inputValue]);
134
-
135
- /** add selected key/value pair as a chip in the chip group */
136
- const selectValue = selectedValue => {
137
- setCurrentChips([...currentChips, `${selectedKey}: ${selectedValue}`]);
138
- clearSelectedKey();
139
- };
140
-
141
- /** update the input to show the selected key and the menu to show the values associated with that specific key */
142
- const selectKey = selectedText => {
143
- setInputValue(`${selectedText}: `);
144
- setSelectedKey(selectedText);
145
- setMenuItemsText(data[selectedText]);
146
- };
147
-
148
- const handleEnter = () => {
149
- /** do nothing if the menu contains no real results */
150
- if (menuItems.length === 1) {
151
- return;
152
- }
153
-
154
- /** perform the appropriate action based on key selection state */
155
- if (selectedKey.length) {
156
- selectValue(menuItems[2].props.children);
157
- } else {
158
- selectKey(menuItems[2].props.children);
159
- }
160
- };
161
-
162
- /** allow the user to backspace at the selected key name to drop the currently selected key */
163
- const handleBackspace = () => {
164
- if (selectedKey.length && inputValue === `${selectedKey}: `) {
165
- clearSelectedKey();
166
- }
167
- };
168
-
169
- /** allow the user to select a key by simply typing it and entering a colon, exact (case sensitive) matches only */
170
- const handleColon = () => {
171
- if (!selectedKey.length && keyNames.includes(inputValue)) {
172
- selectKey(inputValue);
173
- event.preventDefault();
174
- }
175
- };
176
-
177
- /** allow the user to focus on the menu and navigate using the arrow keys */
178
- const handleArrowKey = () => {
179
- if (menuRef.current) {
180
- const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
181
- firstElement && firstElement.focus();
182
- }
183
- };
184
-
185
- /** enable keyboard only usage */
186
- const handleTextInputKeyDown = event => {
187
- switch (event.key) {
188
- case 'Enter':
189
- handleEnter();
190
- break;
191
- case 'Escape':
192
- clearSelectedKey();
193
- break;
194
- case 'Backspace':
195
- handleBackspace();
196
- break;
197
- case ':':
198
- handleColon();
199
- break;
200
- case 'ArrowUp':
201
- case 'ArrowDown':
202
- handleArrowKey();
203
- break;
204
- }
205
- };
206
-
207
- /** perform the proper key or value selection when a menu item is selected */
208
- const onSelect = (event, _itemId) => {
209
- const selectedText = event.target.innerText;
210
-
211
- if (selectedKey.length) {
212
- selectValue(selectedText);
213
- } else {
214
- selectKey(selectedText);
215
- }
216
- event.stopPropagation();
217
- textInputGroupRef.current.querySelector('input').focus();
218
- };
219
-
220
- /** close the menu when a click occurs outside of the menu or text input group */
221
- const handleClick = event => {
222
- if (
223
- menuRef.current &&
224
- !menuRef.current.contains(event.target) &&
225
- !textInputGroupRef.current.contains(event.target)
226
- ) {
227
- setMenuIsOpen(false);
228
- }
229
- };
27
+ ```js file="./examples/TextInputGroup/AttributeValueFiltering.js"
28
+ ```
29
+ ### Auto-complete search
230
30
 
231
- /** only show the search icon when no chips are selected */
232
- const showSearchIcon = !currentChips.length;
31
+ This demo showcases a search input with suggestions, which filters possible selections based on the text you've entered. Unlike the attribute-value filtering demo, it allows creation of new chip items when the text entered is not available in the list of suggestions.
233
32
 
234
- /** only show the clear button when there is something that can be cleared */
235
- const showClearButton = inputValue || !!currentChips.length;
33
+ The current text in the input can be converted to a chip at any time by hitting `enter`. Auto-complete suggestions can be chosen by clicking the corresponding entry in the menu, or by navigating to an entry using the up/down arrow keys and selecting it with `enter`.
236
34
 
237
- const inputGroup = (
238
- <div ref={textInputGroupRef}>
239
- <TextInputGroup>
240
- <TextInputGroupMain
241
- icon={showSearchIcon && <SearchIcon />}
242
- value={inputValue}
243
- onChange={handleInputChange}
244
- onFocus={() => setMenuIsOpen(true)}
245
- onKeyDown={handleTextInputKeyDown}
246
- >
247
- <ChipGroup>
248
- {currentChips.map(currentChip => (
249
- <Chip key={currentChip} onClick={() => deleteChip(currentChip)}>
250
- {currentChip}
251
- </Chip>
252
- ))}
253
- </ChipGroup>
254
- </TextInputGroupMain>
255
- <TextInputGroupUtilities>
256
- {showClearButton && (
257
- <Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button and input">
258
- <TimesIcon />
259
- </Button>
260
- )}
261
- </TextInputGroupUtilities>
262
- </TextInputGroup>
263
- </div>
264
- );
35
+ Hitting `escape` while focused on the input or menu will close the menu, and the menu will reopen when text is entered.
265
36
 
266
- const menu = (
267
- <div ref={menuRef}>
268
- <Menu onSelect={onSelect}>
269
- <MenuContent>
270
- <MenuList>{menuItems}</MenuList>
271
- </MenuContent>
272
- </Menu>
273
- </div>
274
- );
37
+ When only one item remains in the suggestion list, tab can be used to auto-complete the typing of that item.
275
38
 
276
- return <Popper trigger={inputGroup} popper={menu} isVisible={menuIsOpen} onDocumentClick={handleClick} />;
277
- };
39
+ ```js file="./examples/TextInputGroup/AutoCompleteSearch.js"
278
40
  ```
@@ -0,0 +1,250 @@
1
+ import React from 'react';
2
+ import {
3
+ TextInputGroup,
4
+ TextInputGroupMain,
5
+ TextInputGroupUtilities,
6
+ Button,
7
+ Menu,
8
+ MenuContent,
9
+ MenuList,
10
+ MenuItem,
11
+ Popper,
12
+ Chip,
13
+ ChipGroup,
14
+ Divider
15
+ } from '@patternfly/react-core';
16
+ import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
17
+ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
18
+
19
+ export const AttributeValueFiltering = () => {
20
+ const [inputValue, setInputValue] = React.useState('');
21
+ const [selectedKey, setSelectedKey] = React.useState('');
22
+ const [menuIsOpen, setMenuIsOpen] = React.useState(false);
23
+ const [currentChips, setCurrentChips] = React.useState([]);
24
+
25
+ /** key and value data to be shown in the menu */
26
+ const data = {
27
+ Cluster: ['acmeqe-managed-1', 'local-cluster'],
28
+ Kind: ['Template', 'ReplicationController', 'ReplicaSet', 'Deployment'],
29
+ Label: ['release', 'environment', 'partition'],
30
+ Name: ['backup-1', 'backup-2', 'production-1', 'production-2', 'testing'],
31
+ Namespace: ['default', 'public'],
32
+ Status: ['running', 'idle', 'stopped']
33
+ };
34
+ const keyNames = ['Cluster', 'Kind', 'Label', 'Name', 'Namespace', 'Status'];
35
+ const [menuItemsText, setMenuItemsText] = React.useState(keyNames);
36
+ const [menuItems, setMenuItems] = React.useState([]);
37
+
38
+ /** refs used to detect when clicks occur inside vs outside of the textInputGroup and menu popper */
39
+ const menuRef = React.useRef();
40
+ const textInputGroupRef = React.useRef();
41
+
42
+ /** callback for updating the inputValue state in this component so that the input can be controlled */
43
+ const handleInputChange = (value, _event) => {
44
+ setInputValue(value);
45
+ };
46
+
47
+ /** callback for removing a chip from the chip selections */
48
+ const deleteChip = chipToDelete => {
49
+ const newChips = currentChips.filter(chip => !Object.is(chip, chipToDelete));
50
+ setCurrentChips(newChips);
51
+ };
52
+
53
+ /** reset state hooks associated with key selection */
54
+ const clearSelectedKey = () => {
55
+ setInputValue('');
56
+ setSelectedKey('');
57
+ setMenuItemsText(keyNames);
58
+ };
59
+
60
+ /** callback for clearing all selected chips, the text input, and any selected keys */
61
+ const clearChipsAndInput = () => {
62
+ setCurrentChips([]);
63
+ clearSelectedKey();
64
+ };
65
+
66
+ React.useEffect(() => {
67
+ /** in the menu only show items that include the text in the input */
68
+ const filteredMenuItems = menuItemsText
69
+ .filter(
70
+ item =>
71
+ !inputValue ||
72
+ item.toLowerCase().includes(
73
+ inputValue
74
+ .toString()
75
+ .slice(selectedKey.length && selectedKey.length + 2)
76
+ .toLowerCase()
77
+ )
78
+ )
79
+ .map((currentValue, index) => (
80
+ <MenuItem key={currentValue} itemId={index}>
81
+ {currentValue}
82
+ </MenuItem>
83
+ ));
84
+
85
+ /** in the menu show a disabled "no result" when all menu items are filtered out */
86
+ if (filteredMenuItems.length === 0) {
87
+ const noResultItem = (
88
+ <MenuItem isDisabled key="no result">
89
+ No results found
90
+ </MenuItem>
91
+ );
92
+ setMenuItems([noResultItem]);
93
+ return;
94
+ }
95
+
96
+ /** determine the menu heading text based on key selection; or lack thereof */
97
+ const headingItem = (
98
+ <MenuItem isDisabled key="heading">
99
+ {selectedKey.length ? `${selectedKey} values` : 'Attributes'}
100
+ </MenuItem>
101
+ );
102
+
103
+ const divider = <Divider key="divider" />;
104
+
105
+ setMenuItems([headingItem, divider, ...filteredMenuItems]);
106
+ }, [inputValue]);
107
+
108
+ /** add selected key/value pair as a chip in the chip group */
109
+ const selectValue = selectedValue => {
110
+ setCurrentChips([...currentChips, `${selectedKey}: ${selectedValue}`]);
111
+ clearSelectedKey();
112
+ };
113
+
114
+ /** update the input to show the selected key and the menu to show the values associated with that specific key */
115
+ const selectKey = selectedText => {
116
+ setInputValue(`${selectedText}: `);
117
+ setSelectedKey(selectedText);
118
+ setMenuItemsText(data[selectedText]);
119
+ };
120
+
121
+ const handleEnter = () => {
122
+ /** do nothing if the menu contains no real results */
123
+ if (menuItems.length === 1) {
124
+ return;
125
+ }
126
+
127
+ /** perform the appropriate action based on key selection state */
128
+ if (selectedKey.length) {
129
+ selectValue(menuItems[2].props.children);
130
+ } else {
131
+ selectKey(menuItems[2].props.children);
132
+ }
133
+ };
134
+
135
+ /** allow the user to backspace at the selected key name to drop the currently selected key */
136
+ const handleBackspace = () => {
137
+ if (selectedKey.length && inputValue === `${selectedKey}: `) {
138
+ clearSelectedKey();
139
+ }
140
+ };
141
+
142
+ /** allow the user to select a key by simply typing it and entering a colon, exact (case sensitive) matches only */
143
+ const handleColon = () => {
144
+ if (!selectedKey.length && keyNames.includes(inputValue)) {
145
+ selectKey(inputValue);
146
+ event.preventDefault();
147
+ }
148
+ };
149
+
150
+ /** allow the user to focus on the menu and navigate using the arrow keys */
151
+ const handleArrowKey = () => {
152
+ if (menuRef.current) {
153
+ const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
154
+ firstElement && firstElement.focus();
155
+ }
156
+ };
157
+
158
+ /** enable keyboard only usage */
159
+ const handleTextInputKeyDown = event => {
160
+ switch (event.key) {
161
+ case 'Enter':
162
+ handleEnter();
163
+ break;
164
+ case 'Escape':
165
+ clearSelectedKey();
166
+ break;
167
+ case 'Backspace':
168
+ handleBackspace();
169
+ break;
170
+ case ':':
171
+ handleColon();
172
+ break;
173
+ case 'ArrowUp':
174
+ case 'ArrowDown':
175
+ handleArrowKey();
176
+ break;
177
+ }
178
+ };
179
+
180
+ /** perform the proper key or value selection when a menu item is selected */
181
+ const onSelect = (event, _itemId) => {
182
+ const selectedText = event.target.innerText;
183
+
184
+ if (selectedKey.length) {
185
+ selectValue(selectedText);
186
+ } else {
187
+ selectKey(selectedText);
188
+ }
189
+ event.stopPropagation();
190
+ textInputGroupRef.current.querySelector('input').focus();
191
+ };
192
+
193
+ /** close the menu when a click occurs outside of the menu or text input group */
194
+ const handleClick = event => {
195
+ if (
196
+ menuRef.current &&
197
+ !menuRef.current.contains(event.target) &&
198
+ !textInputGroupRef.current.contains(event.target)
199
+ ) {
200
+ setMenuIsOpen(false);
201
+ }
202
+ };
203
+
204
+ /** only show the search icon when no chips are selected */
205
+ const showSearchIcon = !currentChips.length;
206
+
207
+ /** only show the clear button when there is something that can be cleared */
208
+ const showClearButton = inputValue || !!currentChips.length;
209
+
210
+ const inputGroup = (
211
+ <div ref={textInputGroupRef}>
212
+ <TextInputGroup>
213
+ <TextInputGroupMain
214
+ icon={showSearchIcon && <SearchIcon />}
215
+ value={inputValue}
216
+ onChange={handleInputChange}
217
+ onFocus={() => setMenuIsOpen(true)}
218
+ onKeyDown={handleTextInputKeyDown}
219
+ >
220
+ <ChipGroup>
221
+ {currentChips.map(currentChip => (
222
+ <Chip key={currentChip} onClick={() => deleteChip(currentChip)}>
223
+ {currentChip}
224
+ </Chip>
225
+ ))}
226
+ </ChipGroup>
227
+ </TextInputGroupMain>
228
+ <TextInputGroupUtilities>
229
+ {showClearButton && (
230
+ <Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button and input">
231
+ <TimesIcon />
232
+ </Button>
233
+ )}
234
+ </TextInputGroupUtilities>
235
+ </TextInputGroup>
236
+ </div>
237
+ );
238
+
239
+ const menu = (
240
+ <div ref={menuRef}>
241
+ <Menu onSelect={onSelect}>
242
+ <MenuContent>
243
+ <MenuList>{menuItems}</MenuList>
244
+ </MenuContent>
245
+ </Menu>
246
+ </div>
247
+ );
248
+
249
+ return <Popper trigger={inputGroup} popper={menu} isVisible={menuIsOpen} onDocumentClick={handleClick} />;
250
+ };