@patternfly/react-core 4.237.4 → 4.237.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.237.4",
3
+ "version": "4.237.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",
@@ -44,9 +44,9 @@
44
44
  "generate": "node scripts/copyStyles.js"
45
45
  },
46
46
  "dependencies": {
47
- "@patternfly/react-icons": "^4.88.4",
48
- "@patternfly/react-styles": "^4.87.4",
49
- "@patternfly/react-tokens": "^4.89.4",
47
+ "@patternfly/react-icons": "^4.88.5",
48
+ "@patternfly/react-styles": "^4.87.5",
49
+ "@patternfly/react-tokens": "^4.89.5",
50
50
  "focus-trap": "6.9.2",
51
51
  "react-dropzone": "9.0.0",
52
52
  "tippy.js": "5.1.2",
@@ -70,5 +70,5 @@
70
70
  "react": "^16.8.0 || ^17.0.0",
71
71
  "react-dom": "^16.8.0 || ^17.0.0"
72
72
  },
73
- "gitHead": "c45164ec148b97dd7fe65152852de24813fba68e"
73
+ "gitHead": "418c3382f60536603adfb5b23d41dfbe03ddca39"
74
74
  }
@@ -54,6 +54,21 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
54
54
  'aria-label': null as string
55
55
  };
56
56
 
57
+ inputRef = React.createRef<HTMLTextAreaElement>();
58
+
59
+ private setAutoHeight = (field: HTMLTextAreaElement) => {
60
+ field.style.setProperty(heightToken.name, 'inherit');
61
+ const computed = window.getComputedStyle(field);
62
+ // Calculate the height
63
+ const height =
64
+ parseInt(computed.getPropertyValue('border-top-width')) +
65
+ parseInt(computed.getPropertyValue('padding-top')) +
66
+ field.scrollHeight +
67
+ parseInt(computed.getPropertyValue('padding-bottom')) +
68
+ parseInt(computed.getPropertyValue('border-bottom-width'));
69
+ field.style.setProperty(heightToken.name, `${height}px`);
70
+ };
71
+
57
72
  constructor(props: TextAreaProps) {
58
73
  super(props);
59
74
  if (!props.id && !props['aria-label']) {
@@ -62,20 +77,19 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
62
77
  }
63
78
  }
64
79
 
80
+ componentDidMount(): void {
81
+ const inputRef = this.props.innerRef || this.inputRef;
82
+ if (this.props.autoResize && canUseDOM) {
83
+ const field = inputRef.current;
84
+ this.setAutoHeight(field);
85
+ }
86
+ }
87
+
65
88
  private handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
66
89
  // https://gomakethings.com/automatically-expand-a-textarea-as-the-user-types-using-vanilla-javascript/
67
90
  const field = event.currentTarget;
68
91
  if (this.props.autoResize && canUseDOM) {
69
- field.style.setProperty(heightToken.name, 'inherit');
70
- const computed = window.getComputedStyle(field);
71
- // Calculate the height
72
- const height =
73
- parseInt(computed.getPropertyValue('border-top-width')) +
74
- parseInt(computed.getPropertyValue('padding-top')) +
75
- field.scrollHeight +
76
- parseInt(computed.getPropertyValue('padding-bottom')) +
77
- parseInt(computed.getPropertyValue('border-bottom-width'));
78
- field.style.setProperty(heightToken.name, `${height}px`);
92
+ this.setAutoHeight(field);
79
93
  }
80
94
  if (this.props.onChange) {
81
95
  this.props.onChange(field.value, event);
@@ -118,14 +132,14 @@ export class TextAreaBase extends React.Component<TextAreaProps> {
118
132
  required={isRequired}
119
133
  disabled={isDisabled || disabled}
120
134
  readOnly={isReadOnly || readOnly}
121
- ref={innerRef}
135
+ ref={innerRef || this.inputRef}
122
136
  {...props}
123
137
  />
124
138
  );
125
139
  }
126
140
  }
127
141
 
128
- export const TextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps>((props, ref) => (
142
+ export const TextArea = React.forwardRef((props: TextAreaProps, ref: React.Ref<HTMLTextAreaElement>) => (
129
143
  <TextAreaBase {...props} innerRef={ref as React.MutableRefObject<any>} />
130
144
  ));
131
145
  TextArea.displayName = 'TextArea';
@@ -6,7 +6,9 @@ propComponents: ['TextArea']
6
6
  ---
7
7
 
8
8
  ## Examples
9
+
9
10
  ### Basic
11
+
10
12
  ```js
11
13
  import React from 'react';
12
14
  import { TextArea } from '@patternfly/react-core';
@@ -32,6 +34,7 @@ class SimpleTextArea extends React.Component {
32
34
  ```
33
35
 
34
36
  ### Invalid
37
+
35
38
  ```js
36
39
  import React from 'react';
37
40
  import { TextArea } from '@patternfly/react-core';
@@ -42,7 +45,7 @@ class InvalidTextArea extends React.Component {
42
45
  this.state = {
43
46
  value: ''
44
47
  };
45
-
48
+
46
49
  this.handleInvalidTextAreaChange = value => {
47
50
  this.setState({ value });
48
51
  };
@@ -65,6 +68,7 @@ class InvalidTextArea extends React.Component {
65
68
  ```
66
69
 
67
70
  ### Validated
71
+
68
72
  ```js
69
73
  import React from 'react';
70
74
  import { Form, FormGroup, TextArea } from '@patternfly/react-core';
@@ -78,28 +82,30 @@ class InvalidTextArea extends React.Component {
78
82
  validated: 'default',
79
83
  helperText: 'Share your thoughts.'
80
84
  };
81
-
85
+
82
86
  this.simulateNetworkCall = callback => {
83
87
  setTimeout(callback, 2000);
84
- }
85
-
86
- this.handleTextAreaChange = value => {
88
+ };
87
89
 
88
- this.setState({
89
- value,
90
- validated: 'default',
91
- helperText: 'Validating...',
92
- },
90
+ this.handleTextAreaChange = value => {
91
+ this.setState(
92
+ {
93
+ value,
94
+ validated: 'default',
95
+ helperText: 'Validating...'
96
+ },
93
97
  this.simulateNetworkCall(() => {
94
98
  if (value && value.length > 0) {
95
99
  if (value.length >= 10) {
96
- this.setState({validated: 'success', helperText: 'Thanks for your comments!'});
100
+ this.setState({ validated: 'success', helperText: 'Thanks for your comments!' });
97
101
  } else {
98
- this.setState({validated: 'error', invalidText: 'Your being too brief, please enter at least 10 characters.'});
102
+ this.setState({
103
+ validated: 'error',
104
+ invalidText: 'Your being too brief, please enter at least 10 characters.'
105
+ });
99
106
  }
100
- }
101
- else {
102
- this.setState({validated: 'warning', helperText: 'You must have something to say'});
107
+ } else {
108
+ this.setState({ validated: 'warning', helperText: 'You must have something to say' });
103
109
  }
104
110
  })
105
111
  );
@@ -134,6 +140,7 @@ class InvalidTextArea extends React.Component {
134
140
  ```
135
141
 
136
142
  ### Vertically resizable text area
143
+
137
144
  ```js
138
145
  import React from 'react';
139
146
  import { TextArea } from '@patternfly/react-core';
@@ -153,12 +160,20 @@ class VerticalResizeTextArea extends React.Component {
153
160
  render() {
154
161
  const { value } = this.state;
155
162
 
156
- return <TextArea value={value} onChange={this.handleTextAreaChange} resizeOrientation='vertical' aria-label="text vertical resize example" />;
163
+ return (
164
+ <TextArea
165
+ value={value}
166
+ onChange={this.handleTextAreaChange}
167
+ resizeOrientation="vertical"
168
+ aria-label="text vertical resize example"
169
+ />
170
+ );
157
171
  }
158
172
  }
159
173
  ```
160
174
 
161
175
  ### Horizontally resizable text area
176
+
162
177
  ```js
163
178
  import React from 'react';
164
179
  import { TextArea } from '@patternfly/react-core';
@@ -178,33 +193,43 @@ class HorizontalResizeTextArea extends React.Component {
178
193
  render() {
179
194
  const { value } = this.state;
180
195
 
181
- return <TextArea value={value} onChange={this.handleTextAreaChange} resizeOrientation='horizontal' aria-label="text horizontal resize example" />;
196
+ return (
197
+ <TextArea
198
+ value={value}
199
+ onChange={this.handleTextAreaChange}
200
+ resizeOrientation="horizontal"
201
+ aria-label="text horizontal resize example"
202
+ />
203
+ );
182
204
  }
183
205
  }
184
206
  ```
185
207
 
186
208
  ### Uncontrolled
209
+
187
210
  ```js
188
211
  import React from 'react';
189
212
  import { TextArea } from '@patternfly/react-core';
190
213
 
191
- <TextArea defaultValue="default value" aria-label="uncontrolled text area example" />
214
+ <TextArea defaultValue="default value" aria-label="uncontrolled text area example" />;
192
215
  ```
193
216
 
194
217
  ### Disabled
218
+
195
219
  ```js
196
220
  import React from 'react';
197
221
  import { TextArea } from '@patternfly/react-core';
198
222
 
199
- <TextArea aria-label="disabled text area example" isDisabled />
223
+ <TextArea aria-label="disabled text area example" isDisabled />;
200
224
  ```
201
225
 
202
226
  ### Auto resizing
227
+
203
228
  ```js
204
229
  import React from 'react';
205
230
  import { TextArea } from '@patternfly/react-core';
206
231
 
207
- <TextArea aria-label="auto resizing text area example" autoResize />
232
+ <TextArea aria-label="auto resizing text area example" autoResize />;
208
233
  ```
209
234
 
210
235
  ### Icon sprite variants
@@ -249,4 +274,5 @@ IconSpriteTextArea = () => {
249
274
  />
250
275
  </>
251
276
  );
252
- };
277
+ };
278
+ ```