@patternfly/react-core 4.224.4 → 4.224.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.224.4",
3
+ "version": "4.224.5",
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",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.75.4",
38
- "@patternfly/react-styles": "^4.74.4",
39
- "@patternfly/react-tokens": "^4.76.4",
37
+ "@patternfly/react-icons": "^4.75.5",
38
+ "@patternfly/react-styles": "^4.74.5",
39
+ "@patternfly/react-tokens": "^4.76.5",
40
40
  "focus-trap": "6.9.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "6bb7572d64d0b745ff5735006ec72d8eb4a432bc"
63
+ "gitHead": "90d8af769386bbe44a52b1fc1169ab991666d15d"
64
64
  }
@@ -8,79 +8,11 @@ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
8
8
  import './notificationBadge.css';
9
9
 
10
10
  ## Examples
11
- ### Basic
12
- ```js
13
- import React from 'react';
14
- import { NotificationBadge } from '@patternfly/react-core';
15
- import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
16
-
17
- class SimpleNotificationBadge extends React.Component {
18
- constructor(props) {
19
- super(props);
20
- this.state = {
21
- unreadVariant: 'unread',
22
- attentionVariant: 'attention'
23
- };
24
- this.onFirstClick = () => {
25
- this.setState({
26
- unreadVariant: 'read'
27
- });
28
- };
29
- this.onSecondClick = () => {
30
- this.setState({
31
- attentionVariant: 'read'
32
- });
33
- };
34
- }
35
11
 
36
- render() {
37
- const { unreadVariant, attentionVariant } = this.state;
38
- return (
39
- <div className="pf-t-dark">
40
- <NotificationBadge variant={unreadVariant} onClick={this.onFirstClick} aria-label="First notifications" />
41
- <NotificationBadge variant={attentionVariant} onClick={this.onSecondClick} aria-label="Second notifications" />
42
- </div>
43
- );
44
- }
45
- }
12
+ ### Basic
13
+ ```ts file='./NotificationBadgeBasic.tsx'
46
14
  ```
47
15
 
48
- ## Examples
49
16
  ### With count
50
- ```js
51
- import React from 'react';
52
- import { NotificationBadge } from '@patternfly/react-core';
53
- import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
54
-
55
- class NotificationBadgeWithCount extends React.Component {
56
- constructor(props) {
57
- super(props);
58
- this.state = {
59
- firstVariant: 'unread',
60
- firstCount: 30,
61
- secondVariant: 'attention',
62
- secondCount: 30
63
- };
64
- this.onFirstClick = () => {
65
- this.setState({
66
- firstVariant: 'read',
67
- });
68
- };
69
- this.onSecondClick = () => {
70
- this.setState({
71
- secondVariant: 'read'
72
- });
73
- };
74
- }
75
-
76
- render() {
77
- const { firstVariant, firstCount, secondVariant, secondCount } = this.state;
78
- return (
79
- <div className="pf-t-dark">
80
- <NotificationBadge variant={firstVariant} onClick={this.onFirstClick} aria-label="First notifications" count={firstCount} />
81
- <NotificationBadge variant={secondVariant} onClick={this.onSecondClick} aria-label="Second notifications" count={secondCount} />
82
- </div>
83
- );
84
- }
85
- }
86
- ```
17
+ ```ts file='./NotificationBadgeWithCount.tsx'
18
+ ```
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { NotificationBadge, NotificationBadgeVariant } from '@patternfly/react-core';
3
+
4
+ export const SimpleNotificationBadge: React.FunctionComponent = () => {
5
+ const [unreadVariant, setUnreadVariant] = React.useState(NotificationBadgeVariant.unread);
6
+ const [attentionVariant, setAttentionVariant] = React.useState(NotificationBadgeVariant.attention);
7
+
8
+ const onFirstClick = (value: NotificationBadgeVariant) => {
9
+ setUnreadVariant(value);
10
+ };
11
+
12
+ const onSecondClick = (value: NotificationBadgeVariant) => {
13
+ setAttentionVariant(value);
14
+ };
15
+
16
+ return (
17
+ <div className="pf-t-dark">
18
+ <NotificationBadge
19
+ variant={unreadVariant}
20
+ onClick={() => onFirstClick(NotificationBadgeVariant.read)}
21
+ aria-label="First notifications"
22
+ />
23
+ <NotificationBadge
24
+ variant={attentionVariant}
25
+ onClick={() => onSecondClick(NotificationBadgeVariant.read)}
26
+ aria-label="Second notifications"
27
+ />
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { NotificationBadge, NotificationBadgeVariant } from '@patternfly/react-core';
3
+
4
+ export const NotificationBadgeWithCount: React.FunctionComponent = () => {
5
+ const [firstVariant, setFirstVariant] = React.useState(NotificationBadgeVariant.unread);
6
+ const [firstVariantCount, setFirstVariantCount] = React.useState(30);
7
+ const [secondVariant, setSecondVariant] = React.useState(NotificationBadgeVariant.attention);
8
+ const [secondVariantCount, setSecondVariantCount] = React.useState(30);
9
+
10
+ const onFirstClick = (value: NotificationBadgeVariant) => {
11
+ setFirstVariant(value);
12
+ setFirstVariantCount(10);
13
+ };
14
+
15
+ const onSecondClick = (value: NotificationBadgeVariant) => {
16
+ setSecondVariant(value);
17
+ setSecondVariantCount(10);
18
+ };
19
+
20
+ return (
21
+ <div className="pf-t-dark">
22
+ <NotificationBadge
23
+ variant={firstVariant}
24
+ onClick={() => onFirstClick(NotificationBadgeVariant.read)}
25
+ aria-label="First notifications"
26
+ count={firstVariantCount}
27
+ />
28
+ <NotificationBadge
29
+ variant={secondVariant}
30
+ onClick={() => onSecondClick(NotificationBadgeVariant.read)}
31
+ aria-label="Second notifications"
32
+ count={secondVariantCount}
33
+ />
34
+ </div>
35
+ );
36
+ };
@@ -87,6 +87,16 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
87
87
  const keyDownHandler =
88
88
  inputProps && inputProps.onKeyDown ? inputProps.onKeyDown : defaultKeyDownHandler({ inputName, onMinus, onPlus });
89
89
 
90
+ const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
91
+ event.target.value = Number(event.target.value).toString();
92
+ if (onChange) {
93
+ onChange(event);
94
+ }
95
+ if (onBlur) {
96
+ onBlur(event);
97
+ }
98
+ };
99
+
90
100
  return (
91
101
  <div
92
102
  className={css(styles.numberInput, className)}
@@ -119,7 +129,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
119
129
  aria-label={inputAriaLabel}
120
130
  {...(isDisabled && { disabled: isDisabled })}
121
131
  {...(onChange && { onChange })}
122
- {...(onBlur && { onBlur })}
132
+ onBlur={handleBlur}
123
133
  {...(!onChange && { readOnly: true })}
124
134
  {...inputProps}
125
135
  onKeyDown={keyDownHandler}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import { NumberInput } from '../NumberInput';
4
+ import userEvent from '@testing-library/user-event';
4
5
 
5
6
  describe('numberInput', () => {
6
7
  test('renders defaults & extra props', () => {
@@ -60,4 +61,96 @@ describe('numberInput', () => {
60
61
  );
61
62
  expect(asFragment()).toMatchSnapshot();
62
63
  });
64
+
65
+ test('renders negative value', () => {
66
+ render(<NumberInput value={-999} />);
67
+ expect(screen.getByDisplayValue('-999')).toBeInTheDocument();
68
+ });
69
+
70
+ test('renders decimal value', () => {
71
+ render(<NumberInput value={5.5} />);
72
+ expect(screen.getByDisplayValue('5.5')).toBeInTheDocument();
73
+ });
74
+
75
+ test('renders negative decimal value', () => {
76
+ render(<NumberInput value={-5.2} />);
77
+ expect(screen.getByDisplayValue('-5.2')).toBeInTheDocument();
78
+ });
79
+
80
+ test('does not call onChange callback when the input does not change', () => {
81
+ const onChangeMock = jest.fn();
82
+
83
+ render(<NumberInput onChange={onChangeMock}>5</NumberInput>);
84
+
85
+ expect(onChangeMock).not.toHaveBeenCalled();
86
+ });
87
+
88
+ test('calls onChange callback when input changes', () => {
89
+ const onChangeMock = jest.fn();
90
+ render(<NumberInput onChange={onChangeMock}>55</NumberInput>);
91
+
92
+ const input = screen.getByRole('spinbutton');
93
+ userEvent.type(input, '55');
94
+
95
+ expect(onChangeMock).toHaveBeenCalledTimes(2);
96
+ });
97
+
98
+ test('does not call onBlur callback when input does not lose focus', () => {
99
+ const onBlurMock = jest.fn();
100
+
101
+ render(<NumberInput onBlur={onBlurMock}>5</NumberInput>);
102
+
103
+ const input = screen.getByRole('spinbutton');
104
+ userEvent.click(input);
105
+
106
+ expect(onBlurMock).not.toHaveBeenCalled();
107
+ });
108
+
109
+ test('calls onBlur callback when input loses focus', () => {
110
+ const onBlurMock = jest.fn();
111
+
112
+ render(<NumberInput onBlur={onBlurMock}>5</NumberInput>);
113
+
114
+ const input = screen.getByRole('spinbutton');
115
+ userEvent.click(input);
116
+ userEvent.click(document.body);
117
+
118
+ expect(onBlurMock).toHaveBeenCalledTimes(1);
119
+ });
120
+
121
+ test('removes leading zeros from a positive whole number', () => {
122
+ render(<NumberInput value={10} onChange={() => {}} />);
123
+
124
+ const input = screen.getByRole('spinbutton');
125
+ userEvent.type(input, '{arrowleft}{arrowleft}0');
126
+ expect(input).toHaveDisplayValue('010');
127
+
128
+ userEvent.click(document.body);
129
+
130
+ expect(input).toHaveDisplayValue('10');
131
+ });
132
+
133
+ test('removes leading zeros from a negative whole number', () => {
134
+ render(<NumberInput value={-18} onChange={() => {}} />);
135
+
136
+ const input = screen.getByRole('spinbutton');
137
+ userEvent.type(input, '{arrowleft}{arrowleft}0');
138
+ expect(input).toHaveDisplayValue('-018');
139
+
140
+ userEvent.click(document.body);
141
+
142
+ expect(input).toHaveDisplayValue('-18');
143
+ });
144
+
145
+ test('removes leading zeros from a decimal number', () => {
146
+ render(<NumberInput value={47.01} onChange={() => {}} />);
147
+
148
+ const input = screen.getByRole('spinbutton');
149
+ userEvent.type(input, '{arrowleft}{arrowleft}{arrowleft}{arrowleft}{arrowleft}0');
150
+ expect(input).toHaveDisplayValue('047.01');
151
+
152
+ userEvent.click(document.body);
153
+
154
+ expect(input).toHaveDisplayValue('47.01');
155
+ });
63
156
  });
@@ -96,7 +96,6 @@ class UnitNumberInput extends React.Component {
96
96
  };
97
97
 
98
98
  this.onChange2 = event => {
99
- console.log(event.target.value);
100
99
  this.setState({
101
100
  value2: event.target.value
102
101
  });