@navikt/ds-react 7.1.2 → 7.2.0

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.
Files changed (73) hide show
  1. package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +3 -1
  2. package/cjs/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
  3. package/cjs/form/combobox/Input/Input.context.js +1 -1
  4. package/cjs/form/combobox/Input/Input.context.js.map +1 -1
  5. package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +2 -1
  6. package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
  7. package/cjs/form/combobox/customOptionsContext.js +2 -2
  8. package/cjs/form/combobox/customOptionsContext.js.map +1 -1
  9. package/cjs/form/file-upload/index.d.ts +4 -4
  10. package/cjs/form/file-upload/index.js +5 -5
  11. package/cjs/form/file-upload/index.js.map +1 -1
  12. package/cjs/index.d.ts +1 -1
  13. package/cjs/index.js +2 -2
  14. package/cjs/index.js.map +1 -1
  15. package/cjs/list/List.js +7 -2
  16. package/cjs/list/List.js.map +1 -1
  17. package/cjs/list/types.d.ts +1 -1
  18. package/cjs/modal/Modal.js +2 -2
  19. package/cjs/modal/Modal.js.map +1 -1
  20. package/cjs/overlays/dismissablelayer/DismissableLayer.js +2 -0
  21. package/cjs/overlays/dismissablelayer/DismissableLayer.js.map +1 -1
  22. package/cjs/progress-bar/ProgressBar.js +6 -2
  23. package/cjs/progress-bar/ProgressBar.js.map +1 -1
  24. package/cjs/table/AnimateHeight.js +12 -14
  25. package/cjs/table/AnimateHeight.js.map +1 -1
  26. package/cjs/util/TextareaAutoSize.js +1 -0
  27. package/cjs/util/TextareaAutoSize.js.map +1 -1
  28. package/cjs/util/create-context.js +3 -3
  29. package/cjs/util/create-context.js.map +1 -1
  30. package/esm/form/combobox/FilteredOptions/FilteredOptions.js +3 -1
  31. package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
  32. package/esm/form/combobox/Input/Input.context.js +1 -1
  33. package/esm/form/combobox/Input/Input.context.js.map +1 -1
  34. package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +2 -1
  35. package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
  36. package/esm/form/combobox/customOptionsContext.js +2 -2
  37. package/esm/form/combobox/customOptionsContext.js.map +1 -1
  38. package/esm/form/file-upload/index.d.ts +4 -4
  39. package/esm/form/file-upload/index.js +4 -4
  40. package/esm/form/file-upload/index.js.map +1 -1
  41. package/esm/index.d.ts +1 -1
  42. package/esm/index.js +1 -1
  43. package/esm/index.js.map +1 -1
  44. package/esm/list/List.js +7 -2
  45. package/esm/list/List.js.map +1 -1
  46. package/esm/list/types.d.ts +1 -1
  47. package/esm/modal/Modal.js +2 -2
  48. package/esm/modal/Modal.js.map +1 -1
  49. package/esm/overlays/dismissablelayer/DismissableLayer.js +2 -0
  50. package/esm/overlays/dismissablelayer/DismissableLayer.js.map +1 -1
  51. package/esm/progress-bar/ProgressBar.js +6 -2
  52. package/esm/progress-bar/ProgressBar.js.map +1 -1
  53. package/esm/table/AnimateHeight.js +12 -14
  54. package/esm/table/AnimateHeight.js.map +1 -1
  55. package/esm/util/TextareaAutoSize.js +1 -0
  56. package/esm/util/TextareaAutoSize.js.map +1 -1
  57. package/esm/util/create-context.js +3 -3
  58. package/esm/util/create-context.js.map +1 -1
  59. package/package.json +5 -5
  60. package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +1 -0
  61. package/src/form/combobox/Input/Input.context.tsx +1 -1
  62. package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +2 -1
  63. package/src/form/combobox/customOptionsContext.tsx +2 -2
  64. package/src/form/file-upload/index.ts +4 -4
  65. package/src/index.ts +1 -1
  66. package/src/list/List.tsx +12 -6
  67. package/src/list/types.ts +1 -1
  68. package/src/modal/Modal.tsx +2 -2
  69. package/src/overlays/dismissablelayer/DismissableLayer.tsx +3 -0
  70. package/src/progress-bar/ProgressBar.tsx +2 -0
  71. package/src/table/AnimateHeight.tsx +15 -16
  72. package/src/util/TextareaAutoSize.tsx +1 -0
  73. package/src/util/create-context.tsx +3 -2
package/src/list/types.ts CHANGED
@@ -22,7 +22,7 @@ export interface ListProps extends React.HTMLAttributes<HTMLDivElement> {
22
22
  * Changes margin-block on list and font size on items.
23
23
  * @default "medium"
24
24
  */
25
- size?: "medium" | "small";
25
+ size?: "small" | "medium" | "large";
26
26
  }
27
27
 
28
28
  export interface ListItemProps extends React.HTMLAttributes<HTMLLIElement> {
@@ -127,7 +127,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
127
127
  // We have to use JS because it doesn't work to set it with a prop (React bug?)
128
128
  // Currently doesn't seem to work in Chrome. See also Tooltip.tsx
129
129
  if (modalRef.current && portalNode) modalRef.current.autofocus = true;
130
- }, [modalRef, portalNode]);
130
+ }, [portalNode]);
131
131
 
132
132
  useEffect(() => {
133
133
  // We need to have this in a useEffect so that the content renders before the modal is displayed,
@@ -140,7 +140,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
140
140
  modalRef.current.close();
141
141
  }
142
142
  }
143
- }, [modalRef, portalNode, open]);
143
+ }, [portalNode, open]);
144
144
 
145
145
  useBodyScrollLock(modalRef, portalNode, isNested);
146
146
 
@@ -337,6 +337,8 @@ const DismissableLayerNode = forwardRef<HTMLDivElement, DismissableLayerProps>(
337
337
  * If `disableOutsidePointerEvents` is true,
338
338
  * we want to disable pointer events on the body when the first layer is opened.
339
339
  */
340
+
341
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Every time the descendants change, we want to update the body pointer events since we might have added or removed a layer.
340
342
  useEffect(() => {
341
343
  if (!node || !enabled || !disableOutsidePointerEvents) return;
342
344
 
@@ -362,6 +364,7 @@ const DismissableLayerNode = forwardRef<HTMLDivElement, DismissableLayerProps>(
362
364
  /**
363
365
  * To make sure pointerEvents are enabled for all parents and siblings when the layer is removed from the DOM
364
366
  */
367
+ // biome-ignore lint/correctness/useExhaustiveDependencies: We explicitly want to run this on unmount, including every time the node updates to make sure we don't lock the application behind pointer-events: none.
365
368
  useEffect(() => {
366
369
  return () => descendants.values().forEach((x) => x.forceUpdate());
367
370
  }, [descendants, node]);
@@ -107,6 +107,7 @@ export const ProgressBar = forwardRef<HTMLDivElement, ProgressBarProps>(
107
107
  }, [simulated?.seconds]);
108
108
 
109
109
  return (
110
+ /* biome-ignore lint/a11y/useFocusableInteractive: Progressbar is not interactive. */
110
111
  <div
111
112
  ref={ref}
112
113
  className={cl(
@@ -121,6 +122,7 @@ export const ProgressBar = forwardRef<HTMLDivElement, ProgressBarProps>(
121
122
  ? `Fremdrift kan ikke beregnes, antatt tid er: ${simulated?.seconds} sekunder`
122
123
  : `${Math.round(value)} av ${Math.round(valueMax)}`
123
124
  }
125
+ // biome-ignore lint/a11y/useAriaPropsForRole: We found that adding valueMin was not needed
124
126
  role="progressbar"
125
127
  aria-labelledby={ariaLabelledBy}
126
128
  aria-label={ariaLabel}
@@ -74,37 +74,36 @@ const AnimateHeight: React.FC<AnimateHeightProps> = ({
74
74
  const animationClassesTimeoutID = useRef<Timeout>();
75
75
  const timeoutID = useRef<Timeout>();
76
76
 
77
- const duration = prefersReducedMotion ? 0 : userDuration;
77
+ const initialHeight = useRef<Height>(height);
78
+ const initialOverflow = useRef<Overflow>("visible");
78
79
 
79
- let initHeight: Height = height;
80
- let initOverflow: Overflow = "visible";
80
+ const duration = prefersReducedMotion ? 0 : userDuration;
81
81
 
82
- if (typeof initHeight === "number") {
82
+ if (typeof initialHeight.current === "number") {
83
83
  // Reset negative height to 0
84
84
  if (typeof height !== "string") {
85
- initHeight = height < 0 ? 0 : height;
85
+ initialHeight.current = height < 0 ? 0 : height;
86
86
  }
87
- initOverflow = "hidden";
88
- } else if (isPercentage(initHeight)) {
87
+ initialOverflow.current = "hidden";
88
+ } else if (isPercentage(initialHeight.current)) {
89
89
  // If value is string "0%" make sure we convert it to number 0
90
- initHeight = height === "0%" ? 0 : height;
91
- initOverflow = "hidden";
90
+ initialHeight.current = height === "0%" ? 0 : height;
91
+ initialOverflow.current = "hidden";
92
92
  }
93
93
 
94
- const [currentHeight, setCurrentHeight] = useState<Height>(initHeight);
95
- const [overflow, setOverflow] = useState<Overflow>(initOverflow);
94
+ const [currentHeight, setCurrentHeight] = useState<Height>(
95
+ initialHeight.current,
96
+ );
97
+ const [overflow, setOverflow] = useState<Overflow>(initialOverflow.current);
96
98
  const [useTransitions, setUseTransitions] = useState<boolean>(false);
97
99
 
98
- // ------------------ Did mount
99
100
  useEffect(() => {
100
101
  // Hide content if height is 0 (to prevent tabbing into it)
101
- hideContent(contentElement.current, currentHeight);
102
-
103
- // This should be explicitly run only on mount
104
- // eslint-disable-next-line react-hooks/exhaustive-deps
102
+ hideContent(contentElement.current, initialHeight.current);
105
103
  }, []);
106
104
 
107
105
  // ------------------ Height update
106
+ // biome-ignore lint/correctness/useExhaustiveDependencies: This should be explicitly run only on height change
108
107
  useEffect(() => {
109
108
  if (height !== prevHeight.current && contentElement.current) {
110
109
  showContent(contentElement.current, prevHeight.current);
@@ -205,6 +205,7 @@ const TextareaAutosize = forwardRef<HTMLTextAreaElement, TextareaAutosizeProps>(
205
205
  syncHeight();
206
206
  });
207
207
 
208
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Since value is an external prop, we want to reset the renders on every time it changes, even when it is undefined or empty.
208
209
  useEffect(() => {
209
210
  renders.current = 0;
210
211
  }, [value]);
@@ -43,8 +43,9 @@ export function createContext<T>(options: CreateContextOptions<T> = {}) {
43
43
  const Provider = forwardRef<unknown, ProviderProps<T>>(
44
44
  ({ children, ...context }, ref) => {
45
45
  // Only re-memoize when prop values change
46
- // eslint-disable-next-line react-hooks/exhaustive-deps
47
- const value = React.useMemo(() => context, Object.values(context)) as T;
46
+
47
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Object.values(context) includes all dependencies.
48
+ const value = React.useMemo(() => context, Object.values(context)) as T; // eslint-disable-line react-hooks/exhaustive-deps
48
49
 
49
50
  return (
50
51
  <Context.Provider value={ref ? { ...value, ref } : value}>