@navikt/ds-react 5.17.2 → 5.17.3

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.
@@ -43,6 +43,7 @@ const react_1 = __importStar(require("react"));
43
43
  const typography_1 = require("../typography");
44
44
  const util_1 = require("../util");
45
45
  const TextareaAutoSize_1 = __importDefault(require("../util/TextareaAutoSize"));
46
+ const composeEventHandlers_1 = require("../util/composeEventHandlers");
46
47
  const hooks_1 = require("../util/hooks");
47
48
  const ReadOnlyIcon_1 = require("./ReadOnlyIcon");
48
49
  const TextareaCounter_1 = __importDefault(require("./TextareaCounter"));
@@ -64,7 +65,7 @@ exports.Textarea = (0, react_1.forwardRef)((props, ref) => {
64
65
  const { label, className, description, maxLength, hideLabel = false, resize, UNSAFE_autoScrollbar, i18n, readOnly } = props, rest = __rest(props, ["label", "className", "description", "maxLength", "hideLabel", "resize", "UNSAFE_autoScrollbar", "i18n", "readOnly"]);
65
66
  const maxLengthId = (0, hooks_1.useId)();
66
67
  const hasMaxLength = maxLength !== undefined && maxLength > 0;
67
- const [controlledValue, setControlledValue] = (0, react_1.useState)((_a = props === null || props === void 0 ? void 0 : props.defaultValue) !== null && _a !== void 0 ? _a : "");
68
+ const [uncontrolledValue, setUncontrolledValue] = (0, react_1.useState)((_a = props === null || props === void 0 ? void 0 : props.defaultValue) !== null && _a !== void 0 ? _a : "");
68
69
  const getMinRows = () => {
69
70
  let rows = (rest === null || rest === void 0 ? void 0 : rest.minRows) ? rest === null || rest === void 0 ? void 0 : rest.minRows : 3;
70
71
  if (size === "small") {
@@ -92,12 +93,12 @@ exports.Textarea = (0, react_1.forwardRef)((props, ref) => {
92
93
  "navds-sr-only": hideLabel,
93
94
  }), id: inputDescriptionId, size: size, as: "div" }, description)),
94
95
  react_1.default.createElement("div", { className: "navds-textarea__wrapper" },
95
- react_1.default.createElement(TextareaAutoSize_1.default, Object.assign({}, (0, util_1.omit)(rest, ["error", "errorId", "size"]), inputProps, { onChange: (e) => props.onChange
96
- ? props.onChange(e)
97
- : setControlledValue(e.target.value), minRows: getMinRows(), autoScrollbar: UNSAFE_autoScrollbar, ref: ref, readOnly: readOnly, className: (0, clsx_1.default)("navds-textarea__input", "navds-body-short", `navds-body-short--${size !== null && size !== void 0 ? size : "medium"}`) }, (describedBy ? { "aria-describedby": describedBy } : {}))),
96
+ react_1.default.createElement(TextareaAutoSize_1.default, Object.assign({}, (0, util_1.omit)(rest, ["error", "errorId", "size"]), inputProps, { onChange: (0, composeEventHandlers_1.composeEventHandlers)(props.onChange, props.value === undefined
97
+ ? (e) => setUncontrolledValue(e.target.value)
98
+ : undefined), minRows: getMinRows(), autoScrollbar: UNSAFE_autoScrollbar, ref: ref, readOnly: readOnly, className: (0, clsx_1.default)("navds-textarea__input", "navds-body-short", `navds-body-short--${size !== null && size !== void 0 ? size : "medium"}`) }, (describedBy ? { "aria-describedby": describedBy } : {}))),
98
99
  hasMaxLength && !readOnly && !inputProps.disabled && (react_1.default.createElement(react_1.default.Fragment, null,
99
100
  react_1.default.createElement("span", { id: maxLengthId, className: "navds-sr-only" }, `Tekstområde med plass til ${maxLength} tegn.`),
100
- react_1.default.createElement(TextareaCounter_1.default, { maxLength: maxLength, currentLength: (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : controlledValue === null || controlledValue === void 0 ? void 0 : controlledValue.length, size: size, i18n: i18n })))),
101
+ react_1.default.createElement(TextareaCounter_1.default, { maxLength: maxLength, currentLength: (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : uncontrolledValue.length, size: size, i18n: i18n })))),
101
102
  react_1.default.createElement("div", { className: "navds-form-field__error", id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (react_1.default.createElement(typography_1.ErrorMessage, { size: size }, props.error)))));
102
103
  });
103
104
  exports.default = exports.Textarea;
@@ -14,6 +14,7 @@ import React, { forwardRef, useState } from "react";
14
14
  import { BodyShort, ErrorMessage, Label } from "../typography";
15
15
  import { omit } from "../util";
16
16
  import TextareaAutosize from "../util/TextareaAutoSize";
17
+ import { composeEventHandlers } from "../util/composeEventHandlers";
17
18
  import { useId } from "../util/hooks";
18
19
  import { ReadOnlyIcon } from "./ReadOnlyIcon";
19
20
  import Counter from "./TextareaCounter";
@@ -35,7 +36,7 @@ export const Textarea = forwardRef((props, ref) => {
35
36
  const { label, className, description, maxLength, hideLabel = false, resize, UNSAFE_autoScrollbar, i18n, readOnly } = props, rest = __rest(props, ["label", "className", "description", "maxLength", "hideLabel", "resize", "UNSAFE_autoScrollbar", "i18n", "readOnly"]);
36
37
  const maxLengthId = useId();
37
38
  const hasMaxLength = maxLength !== undefined && maxLength > 0;
38
- const [controlledValue, setControlledValue] = useState((_a = props === null || props === void 0 ? void 0 : props.defaultValue) !== null && _a !== void 0 ? _a : "");
39
+ const [uncontrolledValue, setUncontrolledValue] = useState((_a = props === null || props === void 0 ? void 0 : props.defaultValue) !== null && _a !== void 0 ? _a : "");
39
40
  const getMinRows = () => {
40
41
  let rows = (rest === null || rest === void 0 ? void 0 : rest.minRows) ? rest === null || rest === void 0 ? void 0 : rest.minRows : 3;
41
42
  if (size === "small") {
@@ -63,12 +64,12 @@ export const Textarea = forwardRef((props, ref) => {
63
64
  "navds-sr-only": hideLabel,
64
65
  }), id: inputDescriptionId, size: size, as: "div" }, description)),
65
66
  React.createElement("div", { className: "navds-textarea__wrapper" },
66
- React.createElement(TextareaAutosize, Object.assign({}, omit(rest, ["error", "errorId", "size"]), inputProps, { onChange: (e) => props.onChange
67
- ? props.onChange(e)
68
- : setControlledValue(e.target.value), minRows: getMinRows(), autoScrollbar: UNSAFE_autoScrollbar, ref: ref, readOnly: readOnly, className: cl("navds-textarea__input", "navds-body-short", `navds-body-short--${size !== null && size !== void 0 ? size : "medium"}`) }, (describedBy ? { "aria-describedby": describedBy } : {}))),
67
+ React.createElement(TextareaAutosize, Object.assign({}, omit(rest, ["error", "errorId", "size"]), inputProps, { onChange: composeEventHandlers(props.onChange, props.value === undefined
68
+ ? (e) => setUncontrolledValue(e.target.value)
69
+ : undefined), minRows: getMinRows(), autoScrollbar: UNSAFE_autoScrollbar, ref: ref, readOnly: readOnly, className: cl("navds-textarea__input", "navds-body-short", `navds-body-short--${size !== null && size !== void 0 ? size : "medium"}`) }, (describedBy ? { "aria-describedby": describedBy } : {}))),
69
70
  hasMaxLength && !readOnly && !inputProps.disabled && (React.createElement(React.Fragment, null,
70
71
  React.createElement("span", { id: maxLengthId, className: "navds-sr-only" }, `Tekstområde med plass til ${maxLength} tegn.`),
71
- React.createElement(Counter, { maxLength: maxLength, currentLength: (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : controlledValue === null || controlledValue === void 0 ? void 0 : controlledValue.length, size: size, i18n: i18n })))),
72
+ React.createElement(Counter, { maxLength: maxLength, currentLength: (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : uncontrolledValue.length, size: size, i18n: i18n })))),
72
73
  React.createElement("div", { className: "navds-form-field__error", id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (React.createElement(ErrorMessage, { size: size }, props.error)))));
73
74
  });
74
75
  export default Textarea;
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../src/form/Textarea.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,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E,IAAI,GACV,CACD,CACJ,CACG;QACN,6BACE,SAAS,EAAC,yBAAyB,EACnC,EAAE,EAAE,OAAO,mBACG,oBAAoB,eACxB,QAAQ,IAEjB,YAAY,IAAI,CACf,oBAAC,YAAY,IAAC,IAAI,EAAE,IAAI,IAAG,KAAK,CAAC,KAAK,CAAgB,CACvD,CACG,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "5.17.2",
3
+ "version": "5.17.3",
4
4
  "description": "Aksel react-components for NAV designsystem",
5
5
  "author": "Aksel | NAV designsystem team",
6
6
  "license": "MIT",
@@ -38,8 +38,8 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@floating-ui/react": "0.25.4",
41
- "@navikt/aksel-icons": "^5.17.2",
42
- "@navikt/ds-tokens": "^5.17.2",
41
+ "@navikt/aksel-icons": "^5.17.3",
42
+ "@navikt/ds-tokens": "^5.17.3",
43
43
  "@radix-ui/react-tabs": "1.0.0",
44
44
  "@radix-ui/react-toggle-group": "1.0.0",
45
45
  "clsx": "^1.2.1",
@@ -3,6 +3,7 @@ import React, { forwardRef, useState } from "react";
3
3
  import { BodyShort, ErrorMessage, Label } from "../typography";
4
4
  import { omit } from "../util";
5
5
  import TextareaAutosize from "../util/TextareaAutoSize";
6
+ import { composeEventHandlers } from "../util/composeEventHandlers";
6
7
  import { useId } from "../util/hooks";
7
8
  import { ReadOnlyIcon } from "./ReadOnlyIcon";
8
9
  import Counter from "./TextareaCounter";
@@ -102,7 +103,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
102
103
  const maxLengthId = useId();
103
104
  const hasMaxLength = maxLength !== undefined && maxLength > 0;
104
105
 
105
- const [controlledValue, setControlledValue] = useState<string>(
106
+ const [uncontrolledValue, setUncontrolledValue] = useState(
106
107
  props?.defaultValue ?? "",
107
108
  );
108
109
 
@@ -161,11 +162,12 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
161
162
  <TextareaAutosize
162
163
  {...omit(rest, ["error", "errorId", "size"])}
163
164
  {...inputProps}
164
- onChange={(e) =>
165
- props.onChange
166
- ? props.onChange(e)
167
- : setControlledValue(e.target.value)
168
- }
165
+ onChange={composeEventHandlers(
166
+ props.onChange,
167
+ props.value === undefined
168
+ ? (e) => setUncontrolledValue(e.target.value)
169
+ : undefined,
170
+ )}
169
171
  minRows={getMinRows()}
170
172
  autoScrollbar={UNSAFE_autoScrollbar}
171
173
  ref={ref}
@@ -184,7 +186,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
184
186
  </span>
185
187
  <Counter
186
188
  maxLength={maxLength}
187
- currentLength={props.value?.length ?? controlledValue?.length}
189
+ currentLength={props.value?.length ?? uncontrolledValue.length}
188
190
  size={size}
189
191
  i18n={i18n}
190
192
  />
@@ -1,4 +1,5 @@
1
1
  import { Meta, StoryFn, StoryObj } from "@storybook/react";
2
+ import { expect, userEvent, within } from "@storybook/test";
2
3
  import React, { useState } from "react";
3
4
  import { Button } from "../../button";
4
5
  import { Modal } from "../../modal";
@@ -125,6 +126,24 @@ export const Resize: StoryFn = () => {
125
126
  return <Textarea resize label="Ipsum enim quis culpa" />;
126
127
  };
127
128
 
129
+ export const OnChange: StoryFn = () => {
130
+ return (
131
+ <Textarea
132
+ label="Ipsum enim quis culpa"
133
+ onChange={console.log}
134
+ maxLength={50}
135
+ />
136
+ );
137
+ };
138
+ OnChange.play = async ({ canvasElement }) => {
139
+ const canvas = within(canvasElement);
140
+ const input = canvas.getByLabelText("Ipsum enim quis culpa");
141
+ userEvent.click(input);
142
+ await userEvent.type(input, "Aute fugiat ut culpa");
143
+ const text = canvas.getByText("30 tegn igjen");
144
+ expect(text).toBeVisible();
145
+ };
146
+
128
147
  export const Controlled: StoryFn = () => {
129
148
  const [value, setValue] = useState("");
130
149
  return (