carbon-react 104.58.5 → 104.58.6

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.
@@ -11,7 +11,7 @@ import { InputBehaviour } from "../../__internal__/input-behaviour";
11
11
  import { filterStyledSystemMarginProps } from "../../style/utils";
12
12
  import InputIconToggle from "../../__internal__/input-icon-toggle";
13
13
  import guid from "../../__internal__/utils/helpers/guid";
14
- import StyledTextarea from "./textarea.style";
14
+ import StyledTextarea, { MIN_HEIGHT } from "./textarea.style";
15
15
  import LocaleContext from "../../__internal__/i18n-context";
16
16
  import { TooltipProvider } from "../../__internal__/tooltip-provider";
17
17
  import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
@@ -72,13 +72,12 @@ const Textarea = ({
72
72
  current: id
73
73
  } = useRef(idProp || guid());
74
74
  const inputRef = useRef();
75
- const minHeight = useRef(0);
75
+ const minHeight = useRef(MIN_HEIGHT);
76
76
 
77
77
  const expandTextarea = () => {
78
78
  const textarea = inputRef.current;
79
79
 
80
80
  if (textarea.scrollHeight > minHeight.current) {
81
- // Reset height to zero - IE specific
82
81
  textarea.style.height = "0px"; // Set the height so all content is shown
83
82
 
84
83
  textarea.style.height = `${Math.max(textarea.scrollHeight, minHeight.current)}px`;
@@ -99,6 +98,11 @@ const Textarea = ({
99
98
  label,
100
99
  fieldHelp
101
100
  });
101
+ useEffect(() => {
102
+ if (rows) {
103
+ minHeight.current = inputRef.current.scrollHeight;
104
+ }
105
+ }, [rows]);
102
106
  useEffect(() => {
103
107
  if (expandable) {
104
108
  expandTextarea();
@@ -1,2 +1,3 @@
1
+ export const MIN_HEIGHT: 40;
1
2
  export default StyledTextarea;
2
3
  declare const StyledTextarea: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -4,12 +4,13 @@ import StyledInput from "../../__internal__/input/input.style";
4
4
  import { StyledLabelContainer } from "../../__internal__/label/label.style";
5
5
  import InputIconToggleStyle from "../../__internal__/input-icon-toggle/input-icon-toggle.style";
6
6
  import BaseTheme from "../../style/themes/base";
7
+ export const MIN_HEIGHT = 40;
7
8
  const StyledTextarea = styled.div`
8
9
  ${margin};
9
10
 
10
11
  ${StyledInput} {
11
12
  resize: none;
12
- min-height: 40px;
13
+ min-height: ${MIN_HEIGHT}px;
13
14
  margin-top: 5px;
14
15
  margin-bottom: 5px;
15
16
  }
@@ -27,7 +27,7 @@ var _inputIconToggle = _interopRequireDefault(require("../../__internal__/input-
27
27
 
28
28
  var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/guid"));
29
29
 
30
- var _textarea = _interopRequireDefault(require("./textarea.style"));
30
+ var _textarea = _interopRequireWildcard(require("./textarea.style"));
31
31
 
32
32
  var _i18nContext = _interopRequireDefault(require("../../__internal__/i18n-context"));
33
33
 
@@ -102,13 +102,12 @@ const Textarea = ({
102
102
  current: id
103
103
  } = (0, _react.useRef)(idProp || (0, _guid.default)());
104
104
  const inputRef = (0, _react.useRef)();
105
- const minHeight = (0, _react.useRef)(0);
105
+ const minHeight = (0, _react.useRef)(_textarea.MIN_HEIGHT);
106
106
 
107
107
  const expandTextarea = () => {
108
108
  const textarea = inputRef.current;
109
109
 
110
110
  if (textarea.scrollHeight > minHeight.current) {
111
- // Reset height to zero - IE specific
112
111
  textarea.style.height = "0px"; // Set the height so all content is shown
113
112
 
114
113
  textarea.style.height = `${Math.max(textarea.scrollHeight, minHeight.current)}px`;
@@ -129,6 +128,11 @@ const Textarea = ({
129
128
  label,
130
129
  fieldHelp
131
130
  });
131
+ (0, _react.useEffect)(() => {
132
+ if (rows) {
133
+ minHeight.current = inputRef.current.scrollHeight;
134
+ }
135
+ }, [rows]);
132
136
  (0, _react.useEffect)(() => {
133
137
  if (expandable) {
134
138
  expandTextarea();
@@ -1,2 +1,3 @@
1
+ export const MIN_HEIGHT: 40;
1
2
  export default StyledTextarea;
2
3
  declare const StyledTextarea: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.MIN_HEIGHT = void 0;
7
7
 
8
8
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
 
@@ -23,12 +23,14 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
23
23
 
24
24
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
25
 
26
+ const MIN_HEIGHT = 40;
27
+ exports.MIN_HEIGHT = MIN_HEIGHT;
26
28
  const StyledTextarea = _styledComponents.default.div`
27
29
  ${_styledSystem.margin};
28
30
 
29
31
  ${_input.default} {
30
32
  resize: none;
31
- min-height: 40px;
33
+ min-height: ${MIN_HEIGHT}px;
32
34
  margin-top: 5px;
33
35
  margin-bottom: 5px;
34
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "104.58.5",
3
+ "version": "104.58.6",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {