Skip to content

Commit

Permalink
Merge 0a2a35c into 8fce648
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh authored Mar 23, 2023
2 parents 8fce648 + 0a2a35c commit 193471a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-pants-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

Textarea har oppdatert counter-tekst + mulighet for lokalisering
17 changes: 14 additions & 3 deletions @navikt/core/react/src/form/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export interface TextareaProps
* Enables resizing of field
*/
resize?: boolean;
/**
* i18n-translations for counter-text
*/
i18n?: {
/** @default Antall tegn igjen */
counterLeft?: string;
/** @default tegn for mye */
counterTooMuch?: string;
};
}

export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
Expand All @@ -65,6 +74,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
maxLength,
hideLabel = false,
resize,
i18n,
...rest
} = props;

Expand Down Expand Up @@ -166,6 +176,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
maxLength={maxLength}
currentLength={props.value?.length ?? controlledValue?.length}
size={size}
i18n={i18n}
/>
</>
)}
Expand All @@ -185,7 +196,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
}
);

export const Counter = ({ maxLength, currentLength, size }) => {
export const Counter = ({ maxLength, currentLength, size, i18n }) => {
const difference = maxLength - currentLength;

return (
Expand All @@ -197,8 +208,8 @@ export const Counter = ({ maxLength, currentLength, size }) => {
size={size}
>
{difference < 0
? `Antall tegn for mye ${Math.abs(difference)}`
: `Antall tegn igjen ${difference}`}
? `${Math.abs(difference)} ${i18n?.counterLeft ?? "tegn for mye"}`
: `${difference} ${i18n?.counterTooMuch ?? "tegn igjen"}`}
</BodyShort>
);
};
Expand Down

0 comments on commit 193471a

Please sign in to comment.