@patternfly/react-core 4.199.5 → 4.200.2

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 (97) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/esm/components/Avatar/Avatar.d.ts +2 -0
  3. package/dist/esm/components/Avatar/Avatar.d.ts.map +1 -1
  4. package/dist/esm/components/Avatar/Avatar.js +2 -2
  5. package/dist/esm/components/Avatar/Avatar.js.map +1 -1
  6. package/dist/esm/components/FormSelect/FormSelect.d.ts +2 -0
  7. package/dist/esm/components/FormSelect/FormSelect.d.ts.map +1 -1
  8. package/dist/esm/components/FormSelect/FormSelect.js +3 -2
  9. package/dist/esm/components/FormSelect/FormSelect.js.map +1 -1
  10. package/dist/esm/components/TextArea/TextArea.d.ts +2 -0
  11. package/dist/esm/components/TextArea/TextArea.d.ts.map +1 -1
  12. package/dist/esm/components/TextArea/TextArea.js +4 -3
  13. package/dist/esm/components/TextArea/TextArea.js.map +1 -1
  14. package/dist/esm/components/TextInput/TextInput.d.ts +2 -0
  15. package/dist/esm/components/TextInput/TextInput.d.ts.map +1 -1
  16. package/dist/esm/components/TextInput/TextInput.js +3 -2
  17. package/dist/esm/components/TextInput/TextInput.js.map +1 -1
  18. package/dist/js/components/Avatar/Avatar.d.ts +2 -0
  19. package/dist/js/components/Avatar/Avatar.d.ts.map +1 -1
  20. package/dist/js/components/Avatar/Avatar.js +2 -2
  21. package/dist/js/components/Avatar/Avatar.js.map +1 -1
  22. package/dist/js/components/FormSelect/FormSelect.d.ts +2 -0
  23. package/dist/js/components/FormSelect/FormSelect.d.ts.map +1 -1
  24. package/dist/js/components/FormSelect/FormSelect.js +3 -2
  25. package/dist/js/components/FormSelect/FormSelect.js.map +1 -1
  26. package/dist/js/components/TextArea/TextArea.d.ts +2 -0
  27. package/dist/js/components/TextArea/TextArea.d.ts.map +1 -1
  28. package/dist/js/components/TextArea/TextArea.js +4 -3
  29. package/dist/js/components/TextArea/TextArea.js.map +1 -1
  30. package/dist/js/components/TextInput/TextInput.d.ts +2 -0
  31. package/dist/js/components/TextInput/TextInput.d.ts.map +1 -1
  32. package/dist/js/components/TextInput/TextInput.js +3 -2
  33. package/dist/js/components/TextInput/TextInput.js.map +1 -1
  34. package/dist/umd/react-core.js +12 -9
  35. package/dist/umd/react-core.min.js +2 -2
  36. package/package.json +5 -5
  37. package/src/components/Avatar/Avatar.tsx +4 -0
  38. package/src/components/Avatar/examples/Avatar.md +33 -4
  39. package/src/components/ChipGroup/__tests__/ChipGroup.test.tsx +14 -9
  40. package/src/components/ClipboardCopy/__tests__/ClipboardCopyToggle.test.tsx +28 -19
  41. package/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyToggle.test.tsx.snap +1 -1
  42. package/src/components/ContextSelector/__tests__/ContextSelector.test.tsx +21 -14
  43. package/src/components/ContextSelector/__tests__/ContextSelectorToggle.test.tsx +49 -34
  44. package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelector.test.tsx.snap +2 -169
  45. package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelectorToggle.test.tsx.snap +5 -247
  46. package/src/components/DataList/__tests__/DataList.test.tsx +49 -40
  47. package/src/components/DataList/__tests__/__snapshots__/DataList.test.tsx.snap +1 -9
  48. package/src/components/Dropdown/__tests__/Dropdown.test.tsx +54 -42
  49. package/src/components/Dropdown/__tests__/DropdownToggle.test.tsx +179 -177
  50. package/src/components/Dropdown/__tests__/DropdownToggleCheckbox.test.tsx +51 -55
  51. package/src/components/Dropdown/__tests__/Generated/DropdownItem.test.tsx +28 -26
  52. package/src/components/Dropdown/__tests__/Generated/DropdownSeparator.test.tsx +14 -15
  53. package/src/components/Dropdown/__tests__/Generated/InternalDropdownItem.test.tsx +39 -36
  54. package/src/components/Dropdown/__tests__/Generated/__snapshots__/DropdownItem.test.tsx.snap +6 -4
  55. package/src/components/Dropdown/__tests__/Generated/__snapshots__/DropdownSeparator.test.tsx.snap +11 -4
  56. package/src/components/Dropdown/__tests__/Generated/__snapshots__/InternalDropdownItem.test.tsx.snap +7 -4
  57. package/src/components/Dropdown/__tests__/InternalDropdownItem.test.tsx +66 -69
  58. package/src/components/Dropdown/__tests__/__snapshots__/Dropdown.test.tsx.snap +15 -816
  59. package/src/components/Dropdown/__tests__/__snapshots__/DropdownToggle.test.tsx.snap +9 -454
  60. package/src/components/Dropdown/__tests__/__snapshots__/DropdownToggleCheckbox.test.tsx.snap +7 -141
  61. package/src/components/Dropdown/__tests__/__snapshots__/InternalDropdownItem.test.tsx.snap +10 -163
  62. package/src/components/FormSelect/FormSelect.tsx +16 -1
  63. package/src/components/FormSelect/examples/FormSelect.md +58 -0
  64. package/src/components/Nav/__tests__/Generated/NavList.test.tsx +28 -18
  65. package/src/components/Nav/__tests__/Generated/__snapshots__/NavList.test.tsx.snap +8 -4
  66. package/src/components/OptionsMenu/__tests__/Generated/OptionsMenuItem.test.tsx +21 -19
  67. package/src/components/OptionsMenu/__tests__/Generated/__snapshots__/OptionsMenuItem.test.tsx.snap +20 -11
  68. package/src/components/OverflowMenu/__tests__/Generated/OverflowMenuDropdownItem.test.tsx +14 -10
  69. package/src/components/OverflowMenu/__tests__/Generated/__snapshots__/OverflowMenuDropdownItem.test.tsx.snap +18 -4
  70. package/src/components/Select/__tests__/Generated/SelectGroup.test.tsx +22 -10
  71. package/src/components/Select/__tests__/Generated/SelectMenu.test.tsx +22 -26
  72. package/src/components/Select/__tests__/Generated/__snapshots__/SelectGroup.test.tsx.snap +15 -4
  73. package/src/components/Select/__tests__/Generated/__snapshots__/SelectMenu.test.tsx.snap +7 -19
  74. package/src/components/Select/__tests__/SelectGroup.test.tsx +14 -7
  75. package/src/components/Select/__tests__/SelectOption.test.tsx +51 -30
  76. package/src/components/Select/__tests__/__snapshots__/SelectGroup.test.tsx.snap +1 -5
  77. package/src/components/Select/__tests__/__snapshots__/SelectOption.test.tsx.snap +10 -272
  78. package/src/components/TextArea/TextArea.tsx +5 -0
  79. package/src/components/TextArea/__tests__/__snapshots__/TextArea.test.tsx.snap +2 -0
  80. package/src/components/TextArea/examples/TextArea.md +43 -0
  81. package/src/components/TextInput/TextInput.tsx +5 -0
  82. package/src/components/TextInput/__tests__/__snapshots__/TextInput.test.tsx.snap +2 -0
  83. package/src/components/TextInput/examples/TextInput.md +104 -27
  84. package/src/components/Toolbar/__tests__/Generated/ToolbarToggleGroup.test.tsx +25 -11
  85. package/src/components/Toolbar/__tests__/Generated/__snapshots__/ToolbarToggleGroup.test.tsx.snap +26 -4
  86. package/src/components/Toolbar/__tests__/Toolbar.test.tsx +129 -0
  87. package/src/components/Toolbar/__tests__/ToolbarItem.test.tsx +19 -0
  88. package/src/components/Toolbar/__tests__/ToolbarToggleGroup.test.tsx +12 -135
  89. package/src/components/Toolbar/__tests__/__snapshots__/Toolbar.test.tsx.snap +7 -0
  90. package/src/components/Toolbar/__tests__/__snapshots__/ToolbarItem.test.tsx.snap +3 -0
  91. package/src/components/Tooltip/examples/Tooltip.md +9 -1
  92. package/src/components/Tooltip/examples/TooltipExamples.css +4 -4
  93. package/src/components/Select/__tests__/Generated/SelectOption.test.tsx +0 -29
  94. package/src/components/Select/__tests__/Generated/__snapshots__/SelectOption.test.tsx.snap +0 -7
  95. package/src/components/Toolbar/__tests__/__snapshots__/ToolbarToggleGroup.test.tsx.snap +0 -516
  96. package/src/components/Wizard/__tests__/Generated/Wizard.test.tsx +0 -43
  97. package/src/components/Wizard/__tests__/Generated/__snapshots__/Wizard.test.tsx.snap +0 -69
@@ -6,7 +6,9 @@ propComponents: ['TextInput']
6
6
  ---
7
7
 
8
8
  ## Examples
9
+
9
10
  ### Basic
11
+
10
12
  ```js
11
13
  import React from 'react';
12
14
  import { TextInput } from '@patternfly/react-core';
@@ -139,37 +141,112 @@ TextInputSelectAll = () => {
139
141
  ```
140
142
 
141
143
  ### Icon variants
144
+
142
145
  ```js
143
146
  import React from 'react';
144
147
  import { TextInput } from '@patternfly/react-core';
145
148
 
146
- class SimpleTextInput extends React.Component {
147
- constructor(props) {
148
- super(props);
149
- this.state = {
150
- calendar: '',
151
- clock: '',
152
- custom: ''
153
- };
154
- this.handleTextInputChange = (value, field) => {
155
- this.setState({ [field]: value });
156
- };
157
- }
149
+ SimpleTextInput = () => {
150
+ const [calendar, setCalendar] = React.useState('');
151
+ const [clock, setClock] = React.useState('');
152
+ const [custom, setCustom] = React.useState('');
158
153
 
159
- render() {
160
- const { calendar, clock, custom } = this.state;
154
+ return (
155
+ <>
156
+ <TextInput
157
+ value={calendar}
158
+ type="text"
159
+ iconVariant="calendar"
160
+ onChange={value => setCalendar(value)}
161
+ aria-label="text input example"
162
+ />
163
+ <br />
164
+ <br />
165
+ <TextInput
166
+ value={clock}
167
+ type="text"
168
+ iconVariant="clock"
169
+ onChange={value => setClock(value)}
170
+ aria-label="text input example"
171
+ />
172
+ <br />
173
+ <br />
174
+ <TextInput
175
+ value={custom}
176
+ type="text"
177
+ customIconDimensions="24px 24px"
178
+ customIconUrl='data:image/svg+xml;charset=utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"%3E%3Cpath fill="%23a18fff" d="M158.87.15c-16.16-1.52-31.2 8.42-35.33 24.12l-14.81 56.27c187.62 5.49 314.54 130.61 322.48 317l56.94-15.78c15.72-4.36 25.49-19.68 23.62-35.9C490.89 165.08 340.78 17.32 158.87.15zm-58.47 112L.55 491.64a16.21 16.21 0 0 0 20 19.75l379-105.1c-4.27-174.89-123.08-292.14-299.15-294.1zM128 416a32 32 0 1 1 32-32 32 32 0 0 1-32 32zm48-152a32 32 0 1 1 32-32 32 32 0 0 1-32 32zm104 104a32 32 0 1 1 32-32 32 32 0 0 1-32 32z"/%3E%3C/svg%3E'
179
+ onChange={value => setCustom(value)}
180
+ aria-label="text input example"
181
+ />
182
+ </>
183
+ );
184
+ };
185
+ ```
161
186
 
162
- return (
163
- <>
164
- <TextInput value={calendar} type="text" iconVariant='calendar' onChange={(value) => this.handleTextInputChange(value, "calendar")} aria-label="text input example" />
165
- <br />
166
- <br />
167
- <TextInput value={clock} type="text" iconVariant='clock' onChange={(value) => this.handleTextInputChange(value, "clock")} aria-label="text input example" />
168
- <br />
169
- <br />
170
- <TextInput value={custom} type="text" customIconDimensions='24px 24px' customIconUrl='data:image/svg+xml;charset=utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"%3E%3Cpath fill="%23a18fff" d="M158.87.15c-16.16-1.52-31.2 8.42-35.33 24.12l-14.81 56.27c187.62 5.49 314.54 130.61 322.48 317l56.94-15.78c15.72-4.36 25.49-19.68 23.62-35.9C490.89 165.08 340.78 17.32 158.87.15zm-58.47 112L.55 491.64a16.21 16.21 0 0 0 20 19.75l379-105.1c-4.27-174.89-123.08-292.14-299.15-294.1zM128 416a32 32 0 1 1 32-32 32 32 0 0 1-32 32zm48-152a32 32 0 1 1 32-32 32 32 0 0 1-32 32zm104 104a32 32 0 1 1 32-32 32 32 0 0 1-32 32z"/%3E%3C/svg%3E' onChange={(value) => this.handleTextInputChange(value, "custom")} aria-label="text input example" />
171
- </>
172
- );
173
- }
174
- }
187
+ ### Icon sprite variants
188
+
189
+ **Note:** The icons for the success, invalid, calendar, etc. variations in form control elements are applied as background images to the form element. By default, the image URLs for these icons are data URIs. However, there may be cases where data URIs are not ideal, such as in an application with a content security policy that disallows data URIs for security reasons. The `isIconSprite` variation changes the icon source to an external SVG file that serves as a sprite for all of the supported icons.
190
+
191
+ ```js isBeta
192
+ import React from 'react';
193
+ import { TextInput } from '@patternfly/react-core';
194
+
195
+ IconSpriteTextInputs = () => {
196
+ const [success, setSuccess] = React.useState('');
197
+ const [warning, setWarning] = React.useState('');
198
+ const [error, setError] = React.useState('');
199
+ const [calendar, setCalendar] = React.useState('');
200
+ const [clock, setClock] = React.useState('');
201
+
202
+ return (
203
+ <>
204
+ <TextInput
205
+ validated={ValidatedOptions.success}
206
+ isIconSprite
207
+ type="text"
208
+ onChange={value => setSuccess(value)}
209
+ aria-label="success icon sprite text input example"
210
+ />
211
+ <br />
212
+ <br />
213
+ <TextInput
214
+ validated={ValidatedOptions.warning}
215
+ isIconSprite
216
+ type="text"
217
+ onChange={value => setWarning(value)}
218
+ aria-label="warning icon sprite text input example"
219
+ />
220
+ <br />
221
+ <br />
222
+ <TextInput
223
+ validated={ValidatedOptions.error}
224
+ isIconSprite
225
+ type="text"
226
+ onChange={value => setError(value)}
227
+ aria-label="error icon sprite text input example"
228
+ />
229
+ <br />
230
+ <br />
231
+ <TextInput
232
+ value={calendar}
233
+ isIconSprite
234
+ type="text"
235
+ iconVariant="calendar"
236
+ onChange={value => setCalendar(value)}
237
+ aria-label="calendar icon sprite text input example"
238
+ />
239
+ <br />
240
+ <br />
241
+ <TextInput
242
+ value={clock}
243
+ isIconSprite
244
+ type="text"
245
+ iconVariant="clock"
246
+ onChange={value => setClock(value)}
247
+ aria-label="clock icon sprite text input example"
248
+ />
249
+ </>
250
+ );
251
+ };
175
252
  ```
@@ -1,13 +1,27 @@
1
- /**
2
- * This test was generated
3
- */
4
- import * as React from 'react';
5
- import { shallow } from 'enzyme';
6
- import { ToolbarToggleGroup } from '../../ToolbarToggleGroup';
7
- // any missing imports can usually be resolved by adding them here
8
- import {} from '../..';
1
+ import React from 'react';
9
2
 
10
- it('ToolbarToggleGroup should match snapshot (auto-generated)', () => {
11
- const view = shallow(<ToolbarToggleGroup breakpoint="xl" toggleIcon={<div>ReactNode</div>} />);
12
- expect(view).toMatchSnapshot();
3
+ import { render } from '@testing-library/react';
4
+
5
+ import { ToolbarContentContext, ToolbarToggleGroup } from '../..';
6
+ import { PageContext } from '../../../Page/Page';
7
+
8
+ describe('ToolbarToggleGroup', () => {
9
+ it('should match snapshot', () => {
10
+ const view = render(
11
+ <PageContext.Provider
12
+ value={{ isManagedSidebar: false, onNavToggle: jest.fn(), isNavOpen: true, width: 1, getBreakpoint: jest.fn() }}
13
+ >
14
+ <ToolbarContentContext.Provider
15
+ value={{
16
+ expandableContentId: 'test',
17
+ expandableContentRef: { current: ((<></>) as unknown) as HTMLDivElement },
18
+ chipContainerRef: { current: ((<></>) as unknown) as HTMLDivElement }
19
+ }}
20
+ >
21
+ <ToolbarToggleGroup breakpoint="xl" toggleIcon={<div>ReactNode</div>} />
22
+ </ToolbarContentContext.Provider>
23
+ </PageContext.Provider>
24
+ );
25
+ expect(view.container).toMatchSnapshot();
26
+ });
13
27
  });
@@ -1,7 +1,29 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`ToolbarToggleGroup should match snapshot (auto-generated) 1`] = `
4
- <ContextConsumer>
5
- <Component />
6
- </ContextConsumer>
3
+ exports[`ToolbarToggleGroup should match snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="pf-c-toolbar__group pf-m-toggle-group pf-m-show-on-xl"
7
+ >
8
+ <div
9
+ class="pf-c-toolbar__toggle"
10
+ >
11
+ <button
12
+ aria-controls="test"
13
+ aria-disabled="false"
14
+ aria-haspopup="false"
15
+ aria-label="Show Filters"
16
+ class="pf-c-button pf-m-plain"
17
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
18
+ data-ouia-component-type="PF4/Button"
19
+ data-ouia-safe="true"
20
+ type="button"
21
+ >
22
+ <div>
23
+ ReactNode
24
+ </div>
25
+ </button>
26
+ </div>
27
+ </div>
28
+ </div>
7
29
  `;
@@ -0,0 +1,129 @@
1
+ import React from 'react';
2
+
3
+ import { render, screen } from '@testing-library/react';
4
+
5
+ import { ToolbarToggleGroup } from '../ToolbarToggleGroup';
6
+ import { Toolbar } from '../Toolbar';
7
+ import { ToolbarItem } from '../ToolbarItem';
8
+ import { ToolbarContent } from '../ToolbarContent';
9
+ import { ToolbarFilter } from '../ToolbarFilter';
10
+ import { ToolbarGroup } from '../ToolbarGroup';
11
+ import { Select, SelectVariant, SelectOption } from '../../Select';
12
+ import { Button } from '../../Button';
13
+
14
+ describe('Toolbar', () => {
15
+ it('should render inset', () => {
16
+ const items = (
17
+ <React.Fragment>
18
+ <ToolbarItem>Test</ToolbarItem>
19
+ <ToolbarItem>Test 2</ToolbarItem>
20
+ <ToolbarItem variant="separator" />
21
+ <ToolbarItem>Test 3 </ToolbarItem>
22
+ </React.Fragment>
23
+ );
24
+
25
+ render(
26
+ <Toolbar
27
+ id="toolbar"
28
+ inset={{
29
+ default: 'insetNone',
30
+ md: 'insetSm',
31
+ xl: 'inset2xl',
32
+ '2xl': 'insetLg'
33
+ }}
34
+ data-testid="toolbar-test-id"
35
+ >
36
+ <ToolbarContent>{items}</ToolbarContent>
37
+ </Toolbar>
38
+ );
39
+
40
+ expect(screen.getByTestId('toolbar-test-id').outerHTML).toMatchSnapshot();
41
+ });
42
+
43
+ it('should render with page inset flag', () => {
44
+ const items = (
45
+ <React.Fragment>
46
+ <ToolbarItem>Test</ToolbarItem>
47
+ <ToolbarItem>Test 2</ToolbarItem>
48
+ <ToolbarItem variant="separator" />
49
+ <ToolbarItem>Test 3 </ToolbarItem>
50
+ </React.Fragment>
51
+ );
52
+
53
+ render(
54
+ <Toolbar id="toolbar" usePageInsets data-testid="toolbar-test-id">
55
+ <ToolbarContent>{items}</ToolbarContent>
56
+ </Toolbar>
57
+ );
58
+
59
+ expect(screen.getByTestId('toolbar-test-id').outerHTML).toMatchSnapshot();
60
+ });
61
+
62
+ it('should render with custom chip content', () => {
63
+ const statusMenuItems = [
64
+ <SelectOption key="statusNew" value="New" />,
65
+ <SelectOption key="statusPending" value="Pending" />,
66
+ <SelectOption key="statusRunning" value="Running" />,
67
+ <SelectOption key="statusCancelled" value="Cancelled" />
68
+ ];
69
+
70
+ const items = (
71
+ <React.Fragment>
72
+ <ToolbarToggleGroup toggleIcon={<React.Fragment />} breakpoint="xl">
73
+ <ToolbarGroup variant="filter-group">
74
+ <ToolbarFilter
75
+ chips={['New', 'Pending']}
76
+ deleteChip={(category, chip) => {}}
77
+ deleteChipGroup={category => {}}
78
+ categoryName="Status"
79
+ >
80
+ <Select
81
+ variant={SelectVariant.checkbox}
82
+ aria-label="Status"
83
+ onToggle={(isExpanded: boolean) => {}}
84
+ onSelect={(event, selection) => {}}
85
+ selections={['New', 'Pending']}
86
+ isOpen={true}
87
+ placeholderText="Status"
88
+ >
89
+ {statusMenuItems}
90
+ </Select>
91
+ </ToolbarFilter>
92
+ </ToolbarGroup>
93
+ </ToolbarToggleGroup>
94
+ </React.Fragment>
95
+ );
96
+
97
+ const customChipGroupContent = (
98
+ <React.Fragment>
99
+ <ToolbarItem>
100
+ <Button variant="link" onClick={() => {}} isInline>
101
+ Save filters
102
+ </Button>
103
+ </ToolbarItem>
104
+ <ToolbarItem>
105
+ <Button variant="link" onClick={() => {}} isInline>
106
+ Clear all filters
107
+ </Button>
108
+ </ToolbarItem>
109
+ </React.Fragment>
110
+ );
111
+
112
+ render(
113
+ <Toolbar
114
+ id="toolbar-with-filter"
115
+ className="pf-m-toggle-group-container"
116
+ collapseListedFiltersBreakpoint="xl"
117
+ customChipGroupContent={customChipGroupContent}
118
+ data-testid="toolbar-test-id"
119
+ >
120
+ <ToolbarContent>{items}</ToolbarContent>
121
+ </Toolbar>
122
+ );
123
+
124
+ // Expecting 2 matches for text because the buttons also exist in hidden expandable content for mobile view
125
+ expect(screen.getAllByRole('button', { name: 'Save filters' }).length).toBe(2);
126
+ expect(screen.getAllByRole('button', { name: 'Clear all filters' }).length).toBe(2);
127
+ expect(screen.getByTestId('toolbar-test-id').outerHTML).toMatchSnapshot();
128
+ });
129
+ });
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ToolbarItem } from '../ToolbarItem';
4
+
5
+ describe('ToolbarItem', () => {
6
+ it('should map width breakpoints', () => {
7
+ const widths = {
8
+ default: '100px',
9
+ sm: '80px',
10
+ md: '150px',
11
+ lg: '200px',
12
+ xl: '250px',
13
+ '2xl': '300px'
14
+ };
15
+
16
+ render(<ToolbarItem widths={widths}>Test</ToolbarItem>);
17
+ expect(screen.getByText('Test').outerHTML).toMatchSnapshot();
18
+ });
19
+ });
@@ -1,148 +1,25 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { shallow } from 'enzyme';
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
4
3
  import { ToolbarToggleGroup } from '../ToolbarToggleGroup';
5
- import { Toolbar } from '../Toolbar';
6
- import { ToolbarItem } from '../ToolbarItem';
7
- import { ToolbarContent } from '../ToolbarContent';
8
- import { ToolbarFilter } from '../ToolbarFilter';
9
- import { ToolbarGroup } from '../ToolbarGroup';
10
- import { Select, SelectVariant, SelectOption } from '../../Select';
11
- import { Button } from '../../Button';
4
+ import { ToolbarContentContext } from '../ToolbarUtils';
12
5
 
13
6
  describe('ToolbarToggleGroup', () => {
14
7
  it('should warn on bad props', () => {
15
8
  const myMock = jest.fn() as any;
16
9
  global.console = { error: myMock } as any;
17
- shallow(<ToolbarToggleGroup breakpoint={undefined as 'xl'} toggleIcon={null} />);
18
- expect(myMock).toBeCalled();
19
- });
20
- });
21
10
 
22
- describe('Toolbar', () => {
23
- it('should render inset', () => {
24
- const items = (
25
- <React.Fragment>
26
- <ToolbarItem>Test</ToolbarItem>
27
- <ToolbarItem>Test 2</ToolbarItem>
28
- <ToolbarItem variant="separator" />
29
- <ToolbarItem>Test 3 </ToolbarItem>
30
- </React.Fragment>
31
- );
32
-
33
- const view = render(
34
- <Toolbar
35
- id="toolbar"
36
- inset={{
37
- default: 'insetNone',
38
- md: 'insetSm',
39
- xl: 'inset2xl',
40
- '2xl': 'insetLg'
11
+ render(
12
+ <ToolbarContentContext.Provider
13
+ value={{
14
+ expandableContentId: 'some-id',
15
+ expandableContentRef: { current: undefined },
16
+ chipContainerRef: { current: undefined }
41
17
  }}
42
18
  >
43
- <ToolbarContent>{items}</ToolbarContent>
44
- </Toolbar>
45
- );
46
- expect(view.container).toMatchSnapshot();
47
- });
48
-
49
- it('should render with page inset flag', () => {
50
- const items = (
51
- <React.Fragment>
52
- <ToolbarItem>Test</ToolbarItem>
53
- <ToolbarItem>Test 2</ToolbarItem>
54
- <ToolbarItem variant="separator" />
55
- <ToolbarItem>Test 3 </ToolbarItem>
56
- </React.Fragment>
57
- );
58
-
59
- const view = render(
60
- <Toolbar id="toolbar" usePageInsets>
61
- <ToolbarContent>{items}</ToolbarContent>
62
- </Toolbar>
19
+ <ToolbarToggleGroup breakpoint={undefined as 'xl'} toggleIcon={null} />
20
+ </ToolbarContentContext.Provider>
63
21
  );
64
- expect(view.container).toMatchSnapshot();
65
- });
66
-
67
- it('should render with custom chip content', () => {
68
- const statusMenuItems = [
69
- <SelectOption key="statusNew" value="New" />,
70
- <SelectOption key="statusPending" value="Pending" />,
71
- <SelectOption key="statusRunning" value="Running" />,
72
- <SelectOption key="statusCancelled" value="Cancelled" />
73
- ];
74
22
 
75
- const items = (
76
- <React.Fragment>
77
- <ToolbarToggleGroup toggleIcon={<React.Fragment />} breakpoint="xl">
78
- <ToolbarGroup variant="filter-group">
79
- <ToolbarFilter
80
- chips={['New', 'Pending']}
81
- deleteChip={(category, chip) => {}}
82
- deleteChipGroup={category => {}}
83
- categoryName="Status"
84
- >
85
- <Select
86
- variant={SelectVariant.checkbox}
87
- aria-label="Status"
88
- onToggle={(isExpanded: boolean) => {}}
89
- onSelect={(event, selection) => {}}
90
- selections={['New', 'Pending']}
91
- isOpen={true}
92
- placeholderText="Status"
93
- >
94
- {statusMenuItems}
95
- </Select>
96
- </ToolbarFilter>
97
- </ToolbarGroup>
98
- </ToolbarToggleGroup>
99
- </React.Fragment>
100
- );
101
-
102
- const customChipGroupContent = (
103
- <React.Fragment>
104
- <ToolbarItem>
105
- <Button variant="link" onClick={() => {}} isInline>
106
- Save filters
107
- </Button>
108
- </ToolbarItem>
109
- <ToolbarItem>
110
- <Button variant="link" onClick={() => {}} isInline>
111
- Clear all filters
112
- </Button>
113
- </ToolbarItem>
114
- </React.Fragment>
115
- );
116
-
117
- const view = render(
118
- <Toolbar
119
- id="toolbar-with-filter"
120
- className="pf-m-toggle-group-container"
121
- collapseListedFiltersBreakpoint="xl"
122
- customChipGroupContent={customChipGroupContent}
123
- >
124
- <ToolbarContent>{items}</ToolbarContent>
125
- </Toolbar>
126
- );
127
- // Expecting 2 matches for text because the buttons also exist in hidden expandable content for mobile view
128
- expect(screen.getAllByRole('button', { name: 'Save filters' }).length).toBe(2);
129
- expect(screen.getAllByRole('button', { name: 'Clear all filters' }).length).toBe(2);
130
- expect(view.container).toMatchSnapshot();
131
- });
132
- });
133
-
134
- describe('ToolbarItem', () => {
135
- it('should map width breakpoints', () => {
136
- const widths = {
137
- default: '100px',
138
- sm: '80px',
139
- md: '150px',
140
- lg: '200px',
141
- xl: '250px',
142
- '2xl': '300px'
143
- };
144
-
145
- const view = render(<ToolbarItem widths={widths}>Test</ToolbarItem>);
146
- expect(view.container).toMatchSnapshot();
23
+ expect(myMock).toBeCalled();
147
24
  });
148
25
  });
@@ -0,0 +1,7 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Toolbar should render inset 1`] = `"<div class=\\"pf-c-toolbar pf-m-inset-none pf-m-inset-sm-on-md pf-m-inset-2xl-on-xl pf-m-inset-lg-on-2xl\\" id=\\"toolbar\\" data-ouia-component-type=\\"PF4/Toolbar\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Toolbar-1\\" data-testid=\\"toolbar-test-id\\"><div class=\\"pf-c-toolbar__content\\"><div class=\\"pf-c-toolbar__content-section\\"><div class=\\"pf-c-toolbar__item\\">Test</div><div class=\\"pf-c-toolbar__item\\">Test 2</div><hr class=\\"pf-c-divider pf-m-vertical\\"><div class=\\"pf-c-toolbar__item\\">Test 3 </div></div><div class=\\"pf-c-toolbar__expandable-content\\" id=\\"toolbar-expandable-content-0\\"><div class=\\"pf-c-toolbar__group\\"></div></div></div><div class=\\"pf-c-toolbar__content pf-m-hidden\\" hidden=\\"\\"><div class=\\"pf-c-toolbar__group\\"></div></div></div>"`;
4
+
5
+ exports[`Toolbar should render with custom chip content 1`] = `"<div class=\\"pf-c-toolbar pf-m-toggle-group-container\\" id=\\"toolbar-with-filter\\" data-ouia-component-type=\\"PF4/Toolbar\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Toolbar-3\\" data-testid=\\"toolbar-test-id\\"><div class=\\"pf-c-toolbar__content\\"><div class=\\"pf-c-toolbar__content-section\\"><div class=\\"pf-c-toolbar__group pf-m-toggle-group pf-m-show-on-xl\\"><div class=\\"pf-c-toolbar__toggle\\"><button aria-haspopup=\\"false\\" aria-controls=\\"toolbar-with-filter-expandable-content-3\\" aria-disabled=\\"false\\" aria-label=\\"Show Filters\\" class=\\"pf-c-button pf-m-plain\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Button-plain-1\\"></button></div><div class=\\"pf-c-toolbar__group pf-m-filter-group\\"><div class=\\"pf-c-toolbar__item\\"><div class=\\"pf-c-select pf-m-expanded\\" data-ouia-component-type=\\"PF4/Select\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Select-checkbox-2\\"><button id=\\"pf-select-toggle-id-1\\" aria-labelledby=\\" pf-select-toggle-id-1\\" aria-expanded=\\"true\\" type=\\"button\\" class=\\"pf-c-select__toggle\\" aria-label=\\"Options menu\\"><div class=\\"pf-c-select__toggle-wrapper\\"><span class=\\"pf-c-select__toggle-text\\">Status</span><div class=\\"pf-c-select__toggle-badge\\"><span class=\\"pf-c-badge pf-m-read\\">2</span></div></div><span class=\\"pf-c-select__toggle-arrow\\"><svg style=\\"vertical-align: -0.125em;\\" fill=\\"currentColor\\" height=\\"1em\\" width=\\"1em\\" viewBox=\\"0 0 320 512\\" aria-hidden=\\"true\\" role=\\"img\\"><path d=\\"M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z\\"></path></svg></span></button><ul class=\\"pf-c-select__menu\\" role=\\"listbox\\" aria-label=\\"Status\\"><label class=\\"pf-c-check pf-c-select__menu-item\\"><input id=\\"pf-random-id-1-New\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" checked=\\"\\"><span class=\\"pf-c-check__label\\">New</span></label><label class=\\"pf-c-check pf-c-select__menu-item\\"><input id=\\"pf-random-id-1-Pending\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\" checked=\\"\\"><span class=\\"pf-c-check__label\\">Pending</span></label><label class=\\"pf-c-check pf-c-select__menu-item\\"><input id=\\"pf-random-id-1-Running\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\"><span class=\\"pf-c-check__label\\">Running</span></label><label class=\\"pf-c-check pf-c-select__menu-item\\"><input id=\\"pf-random-id-1-Cancelled\\" class=\\"pf-c-check__input\\" type=\\"checkbox\\"><span class=\\"pf-c-check__label\\">Cancelled</span></label></ul></div></div></div></div></div><div class=\\"pf-c-toolbar__expandable-content\\" id=\\"toolbar-with-filter-expandable-content-3\\"><div class=\\"pf-c-toolbar__group\\"></div><div class=\\"pf-c-toolbar__group pf-m-chip-container\\"><div class=\\"pf-c-toolbar__group\\"></div><div class=\\"pf-c-toolbar__item\\"><button aria-disabled=\\"false\\" class=\\"pf-c-button pf-m-link pf-m-inline\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Button-link-3\\">Save filters</button></div><div class=\\"pf-c-toolbar__item\\"><button aria-disabled=\\"false\\" class=\\"pf-c-button pf-m-link pf-m-inline\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Button-link-4\\">Clear all filters</button></div></div></div></div><div class=\\"pf-c-toolbar__content\\"><div class=\\"pf-c-toolbar__group pf-m-hidden\\" hidden=\\"\\" aria-hidden=\\"true\\"><div class=\\"pf-c-toolbar__item pf-m-chip-group\\"><div class=\\"pf-c-chip-group pf-m-category\\" role=\\"group\\" aria-labelledby=\\"pf-random-id-2\\" data-ouia-component-type=\\"PF4/ChipGroup\\" data-ouia-safe=\\"true\\"><div class=\\"pf-c-chip-group__main\\"><span class=\\"pf-c-chip-group__label\\" id=\\"pf-random-id-2\\">Status</span><ul class=\\"pf-c-chip-group__list\\" aria-labelledby=\\"pf-random-id-2\\" role=\\"list\\"><li class=\\"pf-c-chip-group__list-item\\"><div class=\\"pf-c-chip\\" data-ouia-component-type=\\"PF4/Chip\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Chip-1\\"><span class=\\"pf-c-chip__text\\" id=\\"pf-random-id-3\\">New</span><button id=\\"remove_pf-random-id-3\\" aria-labelledby=\\"remove_pf-random-id-3 pf-random-id-3\\" aria-disabled=\\"false\\" aria-label=\\"close\\" class=\\"pf-c-button pf-m-plain\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"close\\"><svg style=\\"vertical-align: -0.125em;\\" fill=\\"currentColor\\" height=\\"1em\\" width=\\"1em\\" viewBox=\\"0 0 352 512\\" aria-hidden=\\"true\\" role=\\"img\\"><path d=\\"M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z\\"></path></svg></button></div></li><li class=\\"pf-c-chip-group__list-item\\"><div class=\\"pf-c-chip\\" data-ouia-component-type=\\"PF4/Chip\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Chip-2\\"><span class=\\"pf-c-chip__text\\" id=\\"pf-random-id-4\\">Pending</span><button id=\\"remove_pf-random-id-4\\" aria-labelledby=\\"remove_pf-random-id-4 pf-random-id-4\\" aria-disabled=\\"false\\" aria-label=\\"close\\" class=\\"pf-c-button pf-m-plain\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"close\\"><svg style=\\"vertical-align: -0.125em;\\" fill=\\"currentColor\\" height=\\"1em\\" width=\\"1em\\" viewBox=\\"0 0 352 512\\" aria-hidden=\\"true\\" role=\\"img\\"><path d=\\"M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z\\"></path></svg></button></div></li></ul></div><div class=\\"pf-c-chip-group__close\\"><button id=\\"remove_group_pf-random-id-2\\" aria-labelledby=\\"remove_group_pf-random-id-2 pf-random-id-2\\" aria-disabled=\\"false\\" aria-label=\\"Close chip group\\" class=\\"pf-c-button pf-m-plain\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"Close chip group\\"><svg style=\\"vertical-align: -0.125em;\\" fill=\\"currentColor\\" height=\\"1em\\" width=\\"1em\\" viewBox=\\"0 0 512 512\\" aria-hidden=\\"true\\" role=\\"img\\"><path d=\\"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z\\"></path></svg></button></div></div></div></div><div class=\\"pf-c-toolbar__group\\"><div class=\\"pf-c-toolbar__item\\">2 filters applied</div></div><div class=\\"pf-c-toolbar__item\\"><button aria-disabled=\\"false\\" class=\\"pf-c-button pf-m-link pf-m-inline\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Button-link-1\\">Save filters</button></div><div class=\\"pf-c-toolbar__item\\"><button aria-disabled=\\"false\\" class=\\"pf-c-button pf-m-link pf-m-inline\\" type=\\"button\\" data-ouia-component-type=\\"PF4/Button\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Button-link-2\\">Clear all filters</button></div></div></div>"`;
6
+
7
+ exports[`Toolbar should render with page inset flag 1`] = `"<div class=\\"pf-c-toolbar pf-m-page-insets\\" id=\\"toolbar\\" data-ouia-component-type=\\"PF4/Toolbar\\" data-ouia-safe=\\"true\\" data-ouia-component-id=\\"OUIA-Generated-Toolbar-2\\" data-testid=\\"toolbar-test-id\\"><div class=\\"pf-c-toolbar__content\\"><div class=\\"pf-c-toolbar__content-section\\"><div class=\\"pf-c-toolbar__item\\">Test</div><div class=\\"pf-c-toolbar__item\\">Test 2</div><hr class=\\"pf-c-divider pf-m-vertical\\"><div class=\\"pf-c-toolbar__item\\">Test 3 </div></div><div class=\\"pf-c-toolbar__expandable-content\\" id=\\"toolbar-expandable-content-1\\"><div class=\\"pf-c-toolbar__group\\"></div></div></div><div class=\\"pf-c-toolbar__content pf-m-hidden\\" hidden=\\"\\"><div class=\\"pf-c-toolbar__group\\"></div></div></div>"`;
@@ -0,0 +1,3 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ToolbarItem should map width breakpoints 1`] = `"<div class=\\"pf-c-toolbar__item\\" style=\\"--pf-c-toolbar__item--Width: 100px; --pf-c-toolbar__item--Width-on-sm: 80px; --pf-c-toolbar__item--Width-on-md: 150px; --pf-c-toolbar__item--Width-on-lg: 200px; --pf-c-toolbar__item--Width-on-xl: 250px; --pf-c-toolbar__item--Width-on-2xl: 300px;\\">Test</div>"`;
@@ -105,10 +105,18 @@ OptionsTooltip = () => {
105
105
  const [exitDelayInput, setExitDelayInput] = React.useState(0);
106
106
  const [animationDuration, setAnimationDuration] = React.useState(300);
107
107
  const tipBoxRef = React.useRef(null);
108
- const scrollToRef = ref => ref && ref.current && (ref.current.scrollTop = 400);
108
+
109
+ const scrollToRef = ref => {
110
+ if (ref && ref.current) {
111
+ ref.current.scrollTop = 400;
112
+ ref.current.scrollLeft = 300;
113
+ }
114
+ }
115
+
109
116
  React.useEffect(() => {
110
117
  scrollToRef(tipBoxRef);
111
118
  }, []);
119
+
112
120
  return (
113
121
  <>
114
122
  <div>
@@ -2,7 +2,7 @@
2
2
  height: 450px;
3
3
  position: relative;
4
4
  width: 100%;
5
- overflow-y: scroll;
5
+ overflow: scroll;
6
6
  overscroll-behavior: contain;
7
7
  margin: 0 auto;
8
8
  border: 2px dashed #ff6b81;
@@ -12,10 +12,10 @@
12
12
  .tooltip-box::after {
13
13
  content: '';
14
14
  display: block;
15
- width: 1px;
15
+ width: 1500px;
16
16
  height: 600px;
17
17
  }
18
18
  .tooltip-button {
19
19
  position: absolute;
20
- left: 300px;
21
- }
20
+ left: 600px;
21
+ }
@@ -1,29 +0,0 @@
1
- /**
2
- * This test was generated
3
- */
4
- import * as React from 'react';
5
- import { shallow } from 'enzyme';
6
- import { SelectOption } from '../../SelectOption';
7
- // any missing imports can usually be resolved by adding them here
8
- import {} from '../..';
9
-
10
- it('SelectOption should match snapshot (auto-generated)', () => {
11
- const view = shallow(
12
- <SelectOption
13
- children={<div>ReactNode</div>}
14
- className={"''"}
15
- index={0}
16
- component={'button'}
17
- value={''}
18
- isDisabled={false}
19
- isPlaceholder={false}
20
- isSelected={false}
21
- isChecked={false}
22
- isFocused={false}
23
- sendRef={() => {}}
24
- keyHandler={() => {}}
25
- onClick={() => {}}
26
- />
27
- );
28
- expect(view).toMatchSnapshot();
29
- });
@@ -1,7 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`SelectOption should match snapshot (auto-generated) 1`] = `
4
- <ContextConsumer>
5
- <Component />
6
- </ContextConsumer>
7
- `;