Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh committed Mar 8, 2023
2 parents 18d0349 + 08006cc commit 4754eb3
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 67 deletions.
2 changes: 2 additions & 0 deletions @navikt/codemod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @navikt/ds-codemod

## 2.6.2

## 2.6.1

## 2.6.0
Expand Down
2 changes: 1 addition & 1 deletion @navikt/codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-codemod",
"version": "2.6.1",
"version": "2.6.2",
"description": "Aksel codemods for NAVs designsystem",
"author": "Aksel | NAV designsystem team",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions @navikt/community/navno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"build-pict": "svgr --silent --index-template index-template.js --out-dir src/pictograms pictograms"
},
"dependencies": {
"@navikt/ds-icons": "^2.6.1",
"@navikt/ds-react": "^2.6.1",
"@navikt/ds-icons": "^2.6.2",
"@navikt/ds-react": "^2.6.2",
"clsx": "^1.1.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions @navikt/core/css/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @navikt/ds-css

## 2.6.2

## 2.6.1

## 2.6.0
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-css",
"version": "2.6.1",
"version": "2.6.2",
"description": "CSS for NAV Designsystem",
"author": "Aksel | NAV designsystem team",
"keywords": [
Expand All @@ -20,7 +20,7 @@
"watch": "postcss --watch --use postcss-import -o dist/index.css index.css"
},
"devDependencies": {
"@navikt/ds-tokens": "^2.6.1",
"@navikt/ds-tokens": "^2.6.2",
"normalize.css": "^8.0.1",
"postcss": "^8.4.0",
"postcss-cli": "^9.0.0",
Expand Down
9 changes: 9 additions & 0 deletions @navikt/core/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @navikt/ds-react

## 2.6.2

### Patch Changes

- [`59d32e52c`](https://github.com/navikt/aksel/commit/59d32e52c437759e66aa50d200b4264a6ba53069) Thanks [@KenAJoh](https://github.com/KenAJoh)! - Fikset React18 problem med TextareaAutosize

- Updated dependencies []:
- @navikt/ds-icons@2.6.2

## 2.6.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-react",
"version": "2.6.1",
"version": "2.6.2",
"description": "Aksel react-components for NAV designsystem",
"author": "Aksel | NAV designsystem team",
"license": "MIT",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@floating-ui/react": "0.17.0",
"@navikt/ds-icons": "^2.6.1",
"@navikt/ds-icons": "^2.6.2",
"@radix-ui/react-tabs": "1.0.0",
"@radix-ui/react-toggle-group": "1.0.0",
"clsx": "^1.2.1",
Expand Down
120 changes: 79 additions & 41 deletions @navikt/core/react/src/util/TextareaAutoSize.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* https://github.com/mui/material-ui/blob/master/packages/mui-base/src/TextareaAutosize/TextareaAutosize.js */
import React, {
forwardRef,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import React, { forwardRef, useEffect, useMemo, useRef, useState } from "react";
import ReactDOM from "react-dom";
import { debounce, mergeRefs, useClientLayoutEffect } from "..";

/**
Expand Down Expand Up @@ -50,7 +44,7 @@ const TextareaAutosize = forwardRef<HTMLTextAreaElement, TextareaAutosizeProps>(
const renders = useRef(0);
const [state, setState] = useState<any>({});

const syncHeight = useCallback(() => {
const getUpdatedState = React.useCallback(() => {
if (!inputRef.current || !shadowRef.current) return;
const input = inputRef.current;
const containerWindow = ownerWindow(input);
Expand Down Expand Up @@ -102,50 +96,85 @@ const TextareaAutosize = forwardRef<HTMLTextAreaElement, TextareaAutosizeProps>(
outerHeight + (boxSizing === "border-box" ? padding + border : 0);
const overflow = Math.abs(outerHeight - innerHeight) <= 1;

return { outerHeightStyle, overflow };
}, [maxRows, minRows, other?.placeholder]);

const syncHeight = React.useCallback(() => {
const newState = getUpdatedState();

if (isEmpty(newState)) {
return;
}

setState((prevState) => {
// Need a large enough difference to update the height.
// This prevents infinite rendering loop.
if (
renders.current < 20 &&
((outerHeightStyle > 0 &&
Math.abs((prevState.outerHeightStyle || 0) - outerHeightStyle) >
1) ||
prevState.overflow !== overflow)
) {
renders.current += 1;
return {
overflow,
outerHeightStyle,
};
}
return updateState(prevState, newState);
});
}, [getUpdatedState]);

if (process.env.NODE_ENV !== "production") {
if (renders.current === 20) {
console.error(
[
"Textarea: Too many re-renders. The layout is unstable.",
"TextareaAutosize limits the number of renders to prevent an infinite loop.",
].join("\n")
);
}
const updateState = (prevState, newState) => {
const { outerHeightStyle, overflow } = newState;
// Need a large enough difference to update the height.
// This prevents infinite rendering loop.
if (
renders.current < 20 &&
((outerHeightStyle > 0 &&
Math.abs((prevState.outerHeightStyle || 0) - outerHeightStyle) > 1) ||
prevState.overflow !== overflow)
) {
renders.current += 1;
return {
overflow,
outerHeightStyle,
};
}
if (process.env.NODE_ENV !== "production") {
if (renders.current === 20) {
console.error(
[
"Textarea: Too many re-renders. The layout is unstable.",
"TextareaAutosize limits the number of renders to prevent an infinite loop.",
].join("\n")
);
}
}
return prevState;
};

return prevState;
const withFlushSync = () => {
const newState = getUpdatedState();

if (isEmpty(newState)) {
return;
}

// In React 18, state updates in a ResizeObserver's callback are happening after the paint which causes flickering
// when doing some visual updates in it. Using flushSync ensures that the dom will be painted after the states updates happen
// Related issue - https://github.com/facebook/react/issues/24331
ReactDOM.flushSync(() => {
setState((prevState) => {
return updateState(prevState, newState);
});
});
}, [maxRows, minRows, other?.placeholder]);
};

useEffect(() => {
React.useEffect(() => {
const handleResize = debounce(() => {
renders.current = 0;
syncHeight();

if (inputRef.current) {
withFlushSync();
}
});
const containerWindow = ownerWindow(inputRef.current);
let resizeObserver: ResizeObserver;

const input = inputRef.current!;
const containerWindow = ownerWindow(input);

containerWindow.addEventListener("resize", handleResize);
let resizeObserver;

if (typeof ResizeObserver !== "undefined") {
resizeObserver = new ResizeObserver(handleResize);
resizeObserver.observe(inputRef.current);
resizeObserver.observe(input);
}

return () => {
Expand All @@ -155,7 +184,7 @@ const TextareaAutosize = forwardRef<HTMLTextAreaElement, TextareaAutosizeProps>(
resizeObserver.disconnect();
}
};
}, [syncHeight]);
});

useClientLayoutEffect(() => {
syncHeight();
Expand Down Expand Up @@ -221,4 +250,13 @@ const TextareaAutosize = forwardRef<HTMLTextAreaElement, TextareaAutosizeProps>(
}
);

function isEmpty(obj: any) {
return (
obj === undefined ||
obj === null ||
Object.keys(obj).length === 0 ||
(obj?.outerHeightStyle === 0 && !obj?.overflow)
);
}

export default TextareaAutosize;
2 changes: 2 additions & 0 deletions @navikt/core/tailwind/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @navikt/ds-tailwind

## 2.6.2

## 2.6.1

## 2.6.0
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/tailwind/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-tailwind",
"version": "2.6.1",
"version": "2.6.2",
"description": "Tailwind config based on @navikt/ds-tokens",
"author": "Aksel | NAV designsystem team",
"keywords": [
Expand All @@ -22,7 +22,7 @@
"directory": "@navikt/core/tailwind"
},
"devDependencies": {
"@navikt/ds-tokens": "^2.6.1",
"@navikt/ds-tokens": "^2.6.2",
"@types/jest": "^29.0.0",
"color": "4.2.3",
"jest": "^29.0.0",
Expand Down
2 changes: 2 additions & 0 deletions @navikt/core/tokens/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @navikt/ds-tokens

## 2.6.2

## 2.6.1

## 2.6.0
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/tokens/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-tokens",
"version": "2.6.1",
"version": "2.6.2",
"description": "Design-tokens for NAV designsystem",
"author": "Aksel | NAV designsystem team",
"keywords": [
Expand Down
2 changes: 2 additions & 0 deletions @navikt/icons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @navikt/ds-icons

## 2.6.2

## 2.6.1

## 2.6.0
Expand Down
2 changes: 1 addition & 1 deletion @navikt/icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-icons",
"version": "2.6.1",
"version": "2.6.2",
"description": "Aksel icons for NAV",
"author": "Aksel | NAV designsystem team",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions @navikt/internal/css/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @navikt/ds-css-internal

## 2.6.2

## 2.6.1

## 2.6.0
Expand Down
2 changes: 1 addition & 1 deletion @navikt/internal/css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-css-internal",
"version": "2.6.1",
"version": "2.6.2",
"description": "CSS for NAV internal Designsystem-components",
"author": "Aksel | NAV designsystem team",
"keywords": [
Expand Down
8 changes: 8 additions & 0 deletions @navikt/internal/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @navikt/ds-react-internal

## 2.6.2

### Patch Changes

- Updated dependencies [[`59d32e52c`](https://github.com/navikt/aksel/commit/59d32e52c437759e66aa50d200b4264a6ba53069)]:
- @navikt/ds-react@2.6.2
- @navikt/ds-icons@2.6.2

## 2.6.1

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions @navikt/internal/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-react-internal",
"version": "2.6.1",
"version": "2.6.2",
"description": "Aksel react components for internal UIs in NAV",
"author": "Aksel | NAV designsystem team",
"license": "MIT",
Expand Down Expand Up @@ -35,8 +35,8 @@
"watch": "tsc --watch -p tsconfig.esm.json"
},
"dependencies": {
"@navikt/ds-icons": "^2.6.1",
"@navikt/ds-react": "^2.6.1",
"@navikt/ds-icons": "^2.6.2",
"@navikt/ds-react": "^2.6.2",
"clsx": "^1.1.1",
"copy-to-clipboard": "^3.3.1"
},
Expand Down
18 changes: 9 additions & 9 deletions aksel.nav.no/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"website"
],
"dependencies": {
"@navikt/aksel-icons": "^2.6.1",
"@navikt/ds-codemod": "^2.6.1",
"@navikt/ds-css": "^2.6.1",
"@navikt/ds-css-internal": "^2.6.1",
"@navikt/ds-icons": "^2.6.1",
"@navikt/ds-react": "^2.6.1",
"@navikt/ds-react-internal": "^2.6.1",
"@navikt/ds-tailwind": "^2.6.1",
"@navikt/ds-tokens": "^2.6.1"
"@navikt/aksel-icons": "^2.6.2",
"@navikt/ds-codemod": "^2.6.2",
"@navikt/ds-css": "^2.6.2",
"@navikt/ds-css-internal": "^2.6.2",
"@navikt/ds-icons": "^2.6.2",
"@navikt/ds-react": "^2.6.2",
"@navikt/ds-react-internal": "^2.6.2",
"@navikt/ds-tailwind": "^2.6.2",
"@navikt/ds-tokens": "^2.6.2"
},
"devDependencies": {
"prettier-plugin-tailwindcss": "^0.2.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/shadow-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"@navikt/ds-css": "2.6.1",
"@navikt/ds-react": "2.6.1",
"@navikt/ds-css": "2.6.2",
"@navikt/ds-react": "2.6.2",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
Expand Down

0 comments on commit 4754eb3

Please sign in to comment.