@patternfly/react-core 4.268.1 → 4.269.0

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 (69) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/components/LabelGroup/LabelGroup.d.ts.map +1 -1
  3. package/components/LabelGroup/LabelGroup.js +4 -5
  4. package/components/LabelGroup/LabelGroup.js.map +1 -1
  5. package/components/NumberInput/NumberInput.d.ts +2 -0
  6. package/components/NumberInput/NumberInput.d.ts.map +1 -1
  7. package/components/NumberInput/NumberInput.js +4 -1
  8. package/components/NumberInput/NumberInput.js.map +1 -1
  9. package/components/SearchInput/AdvancedSearchMenu.d.ts +2 -2
  10. package/components/SearchInput/AdvancedSearchMenu.d.ts.map +1 -1
  11. package/components/SearchInput/AdvancedSearchMenu.js.map +1 -1
  12. package/components/SearchInput/SearchInput.d.ts +5 -5
  13. package/components/SearchInput/SearchInput.d.ts.map +1 -1
  14. package/components/SearchInput/SearchInput.js +1 -1
  15. package/components/SearchInput/SearchInput.js.map +1 -1
  16. package/components/Tabs/Tabs.d.ts +1 -1
  17. package/components/Tabs/Tabs.d.ts.map +1 -1
  18. package/dist/esm/components/LabelGroup/LabelGroup.d.ts.map +1 -1
  19. package/dist/esm/components/LabelGroup/LabelGroup.js +4 -5
  20. package/dist/esm/components/LabelGroup/LabelGroup.js.map +1 -1
  21. package/dist/esm/components/NumberInput/NumberInput.d.ts +2 -0
  22. package/dist/esm/components/NumberInput/NumberInput.d.ts.map +1 -1
  23. package/dist/esm/components/NumberInput/NumberInput.js +4 -1
  24. package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
  25. package/dist/esm/components/SearchInput/AdvancedSearchMenu.d.ts +2 -2
  26. package/dist/esm/components/SearchInput/AdvancedSearchMenu.d.ts.map +1 -1
  27. package/dist/esm/components/SearchInput/AdvancedSearchMenu.js.map +1 -1
  28. package/dist/esm/components/SearchInput/SearchInput.d.ts +5 -5
  29. package/dist/esm/components/SearchInput/SearchInput.d.ts.map +1 -1
  30. package/dist/esm/components/SearchInput/SearchInput.js +1 -1
  31. package/dist/esm/components/SearchInput/SearchInput.js.map +1 -1
  32. package/dist/esm/components/Tabs/Tabs.d.ts +1 -1
  33. package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
  34. package/dist/js/components/LabelGroup/LabelGroup.d.ts.map +1 -1
  35. package/dist/js/components/LabelGroup/LabelGroup.js +4 -5
  36. package/dist/js/components/LabelGroup/LabelGroup.js.map +1 -1
  37. package/dist/js/components/NumberInput/NumberInput.d.ts +2 -0
  38. package/dist/js/components/NumberInput/NumberInput.d.ts.map +1 -1
  39. package/dist/js/components/NumberInput/NumberInput.js +4 -1
  40. package/dist/js/components/NumberInput/NumberInput.js.map +1 -1
  41. package/dist/js/components/SearchInput/AdvancedSearchMenu.d.ts +2 -2
  42. package/dist/js/components/SearchInput/AdvancedSearchMenu.d.ts.map +1 -1
  43. package/dist/js/components/SearchInput/AdvancedSearchMenu.js.map +1 -1
  44. package/dist/js/components/SearchInput/SearchInput.d.ts +5 -5
  45. package/dist/js/components/SearchInput/SearchInput.d.ts.map +1 -1
  46. package/dist/js/components/SearchInput/SearchInput.js +1 -1
  47. package/dist/js/components/SearchInput/SearchInput.js.map +1 -1
  48. package/dist/js/components/Tabs/Tabs.d.ts +1 -1
  49. package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
  50. package/dist/umd/react-core.min.js +2 -2
  51. package/package.json +2 -2
  52. package/src/components/LabelGroup/LabelGroup.tsx +4 -5
  53. package/src/components/NumberInput/NumberInput.tsx +6 -0
  54. package/src/components/NumberInput/__tests__/NumberInput.test.tsx +7 -1
  55. package/src/components/NumberInput/examples/NumberInputCustomStep.tsx +1 -0
  56. package/src/components/NumberInput/examples/NumberInputCustomStepAndThreshold.tsx +1 -0
  57. package/src/components/NumberInput/examples/NumberInputDefault.tsx +1 -0
  58. package/src/components/NumberInput/examples/NumberInputDisabled.tsx +1 -0
  59. package/src/components/NumberInput/examples/NumberInputUnit.tsx +2 -0
  60. package/src/components/NumberInput/examples/NumberInputUnitThreshold.tsx +1 -0
  61. package/src/components/NumberInput/examples/NumberInputVaryingSizes.tsx +4 -0
  62. package/src/components/NumberInput/examples/NumberInputWithStatus.tsx +1 -0
  63. package/src/components/SearchInput/AdvancedSearchMenu.tsx +3 -3
  64. package/src/components/SearchInput/SearchInput.tsx +6 -6
  65. package/src/components/SearchInput/__tests__/SearchInput.test.tsx +1 -1
  66. package/src/components/SearchInput/examples/SearchInput.md +1 -1
  67. package/src/components/SearchInput/examples/SearchInputWithExpandable.tsx +1 -1
  68. package/src/components/Tabs/Tabs.tsx +1 -1
  69. package/src/demos/examples/AlertGroup/AlertGroupToastWithNotificationDrawer.tsx +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.268.1",
3
+ "version": "4.269.0",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -71,5 +71,5 @@
71
71
  "react": "^16.8 || ^17 || ^18",
72
72
  "react-dom": "^16.8 || ^17 || ^18"
73
73
  },
74
- "gitHead": "a4fca9d0be55199414a01de809cc041561207489"
74
+ "gitHead": "bf9cf833bd7117fcfdb71fc68cab3d2453374336"
75
75
  }
@@ -156,15 +156,14 @@ export class LabelGroup extends React.Component<LabelGroupProps, LabelGroupState
156
156
  ...rest
157
157
  } = this.props;
158
158
  const { isOpen } = this.state;
159
- const numChildren = React.Children.count(children);
159
+ const renderedChildren = React.Children.toArray(children);
160
+ const numChildren = renderedChildren.length;
160
161
  const collapsedTextResult = fillTemplate(collapsedText as string, {
161
- remaining: React.Children.count(children) - numLabels
162
+ remaining: numChildren - numLabels
162
163
  });
163
164
 
164
165
  const renderLabelGroup = (id: string) => {
165
- const labelArray = !isOpen
166
- ? React.Children.toArray(children).slice(0, numLabels)
167
- : React.Children.toArray(children);
166
+ const labelArray = !isOpen ? renderedChildren.slice(0, numLabels) : renderedChildren;
168
167
 
169
168
  const content = (
170
169
  <React.Fragment>
@@ -51,6 +51,8 @@ export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
51
51
  minusBtnProps?: ButtonProps;
52
52
  /** Additional properties added to the plus button */
53
53
  plusBtnProps?: ButtonProps;
54
+ /** Allow the user to clear out the input to an empty string (recommended) */
55
+ allowEmptyInput?: boolean;
54
56
  }
55
57
 
56
58
  type DefaultKeyDownHandlerArgs = Pick<NumberInputProps, 'inputName' | 'onMinus' | 'onPlus'>;
@@ -87,8 +89,12 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
87
89
  inputProps,
88
90
  minusBtnProps,
89
91
  plusBtnProps,
92
+ allowEmptyInput = false,
90
93
  ...props
91
94
  }: NumberInputProps) => {
95
+ if (!allowEmptyInput) {
96
+ value = value || 0;
97
+ }
92
98
  const numberInputUnit = <div className={css(styles.numberInputUnit)}>{unit}</div>;
93
99
  const keyDownHandler =
94
100
  inputProps && inputProps.onKeyDown ? inputProps.onKeyDown : defaultKeyDownHandler({ inputName, onMinus, onPlus });
@@ -207,9 +207,15 @@ describe('numberInput', () => {
207
207
  expect(input).toHaveDisplayValue('0');
208
208
  });
209
209
 
210
- test('renders nothing if null value passed', () => {
210
+ test('renders 0 if null value passed without allow empty', () => {
211
211
  render(<NumberInput value={null} />);
212
212
  const input = screen.getByRole('spinbutton');
213
+ expect(input).toHaveDisplayValue('0');
214
+ });
215
+
216
+ test('renders nothing if null value passed with allow empty', () => {
217
+ render(<NumberInput allowEmptyInput value={null} />);
218
+ const input = screen.getByRole('spinbutton');
213
219
  expect(input).toHaveDisplayValue('');
214
220
  });
215
221
 
@@ -24,6 +24,7 @@ export const NumberInputCustomStep: React.FunctionComponent = () => {
24
24
  inputAriaLabel="number input"
25
25
  minusBtnAriaLabel="minus"
26
26
  plusBtnAriaLabel="plus"
27
+ allowEmptyInput
27
28
  />
28
29
  );
29
30
  };
@@ -46,6 +46,7 @@ export const NumberInputCustomStepAndThreshold: React.FunctionComponent = () =>
46
46
  inputAriaLabel="number input"
47
47
  minusBtnAriaLabel="minus"
48
48
  plusBtnAriaLabel="plus"
49
+ allowEmptyInput
49
50
  />
50
51
  );
51
52
  };
@@ -29,6 +29,7 @@ export const NumberInputDefault: React.FunctionComponent = () => {
29
29
  inputAriaLabel="number input"
30
30
  minusBtnAriaLabel="minus"
31
31
  plusBtnAriaLabel="plus"
32
+ allowEmptyInput
32
33
  />
33
34
  );
34
35
  };
@@ -35,6 +35,7 @@ export const NumberInputDisabled: React.FunctionComponent = () => {
35
35
  plusBtnAriaLabel="plus"
36
36
  unit="%"
37
37
  isDisabled
38
+ allowEmptyInput
38
39
  />
39
40
  );
40
41
  };
@@ -37,6 +37,7 @@ export const NumberInputUnit: React.FunctionComponent = () => {
37
37
  minusBtnAriaLabel="minus 1"
38
38
  plusBtnAriaLabel="plus 1"
39
39
  unit="%"
40
+ allowEmptyInput
40
41
  />
41
42
  <br />
42
43
  <br />
@@ -51,6 +52,7 @@ export const NumberInputUnit: React.FunctionComponent = () => {
51
52
  plusBtnAriaLabel="plus 0.01"
52
53
  unit="$"
53
54
  unitPosition="before"
55
+ allowEmptyInput
54
56
  />
55
57
  </React.Fragment>
56
58
  );
@@ -59,6 +59,7 @@ export const NumberInputUnitThreshold: React.FunctionComponent = () => {
59
59
  minusBtnAriaLabel="minus"
60
60
  plusBtnAriaLabel="plus"
61
61
  unit="%"
62
+ allowEmptyInput
62
63
  />
63
64
  </React.Fragment>
64
65
  );
@@ -35,6 +35,7 @@ export const NumberInputVaryingSizes: React.FunctionComponent = () => {
35
35
  minusBtnAriaLabel="input 2 minus"
36
36
  plusBtnAriaLabel="input 2 plus"
37
37
  widthChars={1}
38
+ allowEmptyInput
38
39
  />
39
40
  <br />
40
41
  <br />
@@ -48,6 +49,7 @@ export const NumberInputVaryingSizes: React.FunctionComponent = () => {
48
49
  minusBtnAriaLabel="input 2 minus"
49
50
  plusBtnAriaLabel="input 2 plus"
50
51
  widthChars={10}
52
+ allowEmptyInput
51
53
  />
52
54
  <br />
53
55
  <br />
@@ -61,6 +63,7 @@ export const NumberInputVaryingSizes: React.FunctionComponent = () => {
61
63
  minusBtnAriaLabel="input 3 minus"
62
64
  plusBtnAriaLabel="input 3 plus"
63
65
  widthChars={5}
66
+ allowEmptyInput
64
67
  />
65
68
  <br />
66
69
  <br />
@@ -74,6 +77,7 @@ export const NumberInputVaryingSizes: React.FunctionComponent = () => {
74
77
  minusBtnAriaLabel="input 4 minus"
75
78
  plusBtnAriaLabel="input 4 plus"
76
79
  widthChars={5}
80
+ allowEmptyInput
77
81
  />
78
82
  </React.Fragment>
79
83
  );
@@ -53,6 +53,7 @@ export const NumberInputWithStatus: React.FunctionComponent = () => {
53
53
  inputAriaLabel="number input"
54
54
  minusBtnAriaLabel="minus"
55
55
  plusBtnAriaLabel="plus"
56
+ allowEmptyInput
56
57
  />
57
58
  </>
58
59
  );
@@ -3,7 +3,7 @@ import { Button } from '../Button';
3
3
  import { ActionGroup, Form, FormGroup } from '../Form';
4
4
  import { TextInput } from '../TextInput';
5
5
  import { GenerateId, KeyTypes } from '../../helpers';
6
- import { SearchAttribute } from './SearchInput';
6
+ import { SearchInputSearchAttribute } from './SearchInput';
7
7
  import { Panel, PanelMain, PanelMainBody } from '../Panel';
8
8
  import { css } from '@patternfly/react-styles';
9
9
 
@@ -13,7 +13,7 @@ export interface AdvancedSearchMenuProps extends Omit<React.HTMLProps<HTMLDivEle
13
13
  */
14
14
  advancedSearchDelimiter?: string;
15
15
  /** Array of attribute values used for dynamically generated advanced search. */
16
- attributes?: string[] | SearchAttribute[];
16
+ attributes?: string[] | SearchInputSearchAttribute[];
17
17
  /** Additional classes added to the advanced search menu. */
18
18
  className?: string;
19
19
  /* Additional elements added after the attributes in the form.
@@ -161,7 +161,7 @@ export const AdvancedSearchMenu: React.FunctionComponent<AdvancedSearchMenuProps
161
161
 
162
162
  const buildFormGroups = () => {
163
163
  const formGroups = [] as React.ReactNode[];
164
- attributes.forEach((attribute: string | SearchAttribute, index: number) => {
164
+ attributes.forEach((attribute: string | SearchInputSearchAttribute, index: number) => {
165
165
  const display = typeof attribute === 'string' ? attribute : attribute.display;
166
166
  const queryAttr = typeof attribute === 'string' ? attribute : attribute.attr;
167
167
  if (index === 0) {
@@ -17,7 +17,7 @@ import { Popper } from '../../helpers';
17
17
  * be passed in as an object within an array to the search input component's attribute properrty.
18
18
  */
19
19
 
20
- export interface SearchAttribute {
20
+ export interface SearchInputSearchAttribute {
21
21
  /** The search attribute's value to be provided in the search input's query string.
22
22
  * It should have no spaces and be unique for every attribute.
23
23
  */
@@ -32,11 +32,11 @@ export interface SearchAttribute {
32
32
  * the search input component's expandableInput property.
33
33
  */
34
34
 
35
- export interface ExpandableInput {
35
+ export interface SearchInputExpandable {
36
36
  /** Flag to indicate if the search input is expanded. */
37
37
  isExpanded: boolean;
38
38
  /** Callback function to toggle the expandable search input. */
39
- onToggleExpand: (isExpanded: boolean, event: React.SyntheticEvent<HTMLButtonElement>) => void;
39
+ onToggleExpand: (event: React.SyntheticEvent<HTMLButtonElement>, isExpanded: boolean) => void;
40
40
  /** An accessible label for the expandable search input toggle. */
41
41
  toggleAriaLabel: string;
42
42
  }
@@ -58,11 +58,11 @@ export interface SearchInputProps extends Omit<React.HTMLProps<HTMLDivElement>,
58
58
  /** An accessible label for the search input. */
59
59
  'aria-label'?: string;
60
60
  /** Array of attribute values used for dynamically generated advanced search. */
61
- attributes?: string[] | SearchAttribute[];
61
+ attributes?: string[] | SearchInputSearchAttribute[];
62
62
  /** Additional classes added to the search input. */
63
63
  className?: string;
64
64
  /** Object that makes the search input expandable/collapsible. */
65
- expandableInput?: ExpandableInput;
65
+ expandableInput?: SearchInputExpandable;
66
66
  /* Additional elements added after the attributes in the form.
67
67
  * The new form elements can be wrapped in a form group component for automatic formatting. */
68
68
  formAdditionalItems?: React.ReactNode;
@@ -285,7 +285,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
285
285
 
286
286
  const onExpandHandler = (event: React.SyntheticEvent<HTMLButtonElement>) => {
287
287
  setSearchValue('');
288
- onToggleExpand(isExpanded, event);
288
+ onToggleExpand(event, isExpanded);
289
289
  setFocusAfterExpandChange(true);
290
290
  };
291
291
 
@@ -239,7 +239,7 @@ test('onToggleExpand is called if the expandable toggle is clicked', async () =>
239
239
  await user.click(screen.getByRole('button'));
240
240
 
241
241
  expect(mockOnToggleExpand).toHaveBeenCalledTimes(1);
242
- expect(mockOnToggleExpand).toHaveBeenCalledWith(true, expect.objectContaining({ type: 'click' }));
242
+ expect(mockOnToggleExpand).toHaveBeenCalledWith(expect.objectContaining({ type: 'click' }), true);
243
243
  });
244
244
 
245
245
  test('toggleAriaLabel is applied to the expandable toggle', () => {
@@ -2,7 +2,7 @@
2
2
  id: 'Search input'
3
3
  section: components
4
4
  cssPrefix: 'pf-c-search-input'
5
- propComponents: ['SearchInput', 'SearchAttribute', 'ExpandableInput']
5
+ propComponents: ['SearchInput', 'SearchInputSearchAttribute', 'SearchInputExpandable']
6
6
  beta: true
7
7
  ---
8
8
 
@@ -9,7 +9,7 @@ export const SearchInputWithExpandable: React.FunctionComponent = () => {
9
9
  setValue(value);
10
10
  };
11
11
 
12
- const onToggleExpand = (isExpanded: boolean) => {
12
+ const onToggleExpand = (_event: React.SyntheticEvent<HTMLButtonElement>, isExpanded: boolean) => {
13
13
  setIsExpanded(!isExpanded);
14
14
  };
15
15
 
@@ -45,7 +45,7 @@ export interface TabsProps extends Omit<React.HTMLProps<HTMLElement | HTMLDivEle
45
45
  /** @beta Callback to handle tab closing and adds a basic close button to all tabs. This is overridden by the tab actions property. */
46
46
  onClose?: (event: React.MouseEvent<HTMLElement, MouseEvent>, eventKey: number | string) => void;
47
47
  /** @beta Callback for the add button. Passing this property inserts the add button */
48
- onAdd?: () => void;
48
+ onAdd?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
49
49
  /** @beta Aria-label for the add button */
50
50
  addButtonAriaLabel?: string;
51
51
  /** Uniquely identifies the tabs */
@@ -344,6 +344,7 @@ export const AlertGroupToastWithNotificationDrawer: React.FunctionComponent = ()
344
344
  minusBtnAriaLabel="minus"
345
345
  plusBtnAriaLabel="plus"
346
346
  style={{ margin: '12px 0' }}
347
+ allowEmptyInput
347
348
  />
348
349
  </PageSection>
349
350
  <PageSection variant={PageSectionVariants.light}>