@navikt/ds-react 7.0.0 → 7.1.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 (78) hide show
  1. package/cjs/collapsible/Collapsible.context.d.ts +1 -1
  2. package/cjs/form/combobox/FilteredOptions/filtered-options-util.js +1 -3
  3. package/cjs/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -1
  4. package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +2 -2
  5. package/cjs/form/combobox/types.d.ts +10 -11
  6. package/cjs/form/error-summary/ErrorSummary.d.ts +3 -3
  7. package/cjs/form/error-summary/ErrorSummary.js +6 -7
  8. package/cjs/form/error-summary/ErrorSummary.js.map +1 -1
  9. package/cjs/form/file-upload/FileUpload.context.d.ts +1 -1
  10. package/cjs/form/form-summary/FormSummaryEditLink.js +2 -2
  11. package/cjs/form/form-summary/FormSummaryEditLink.js.map +1 -1
  12. package/cjs/layout/page/parts/PageBlock.js +1 -1
  13. package/cjs/layout/page/parts/PageBlock.js.map +1 -1
  14. package/cjs/layout/stack/HStack.js +14 -2
  15. package/cjs/layout/stack/HStack.js.map +1 -1
  16. package/cjs/layout/stack/VStack.js +14 -2
  17. package/cjs/layout/stack/VStack.js.map +1 -1
  18. package/cjs/overlays/floating/Floating.utils.d.ts +1 -1
  19. package/cjs/pagination/Pagination.js +6 -7
  20. package/cjs/pagination/Pagination.js.map +1 -1
  21. package/cjs/pagination/PaginationItem.d.ts +3 -2
  22. package/cjs/pagination/PaginationItem.js +1 -1
  23. package/cjs/pagination/PaginationItem.js.map +1 -1
  24. package/cjs/provider/i18n/LanguageProvider.d.ts +1 -1
  25. package/cjs/provider/i18n/LanguageProvider.js +4 -14
  26. package/cjs/provider/i18n/LanguageProvider.js.map +1 -1
  27. package/cjs/stepper/context.d.ts +1 -1
  28. package/cjs/tabs/Tabs.context.d.ts +1 -1
  29. package/cjs/toggle-group/ToggleGroup.context.d.ts +1 -1
  30. package/cjs/util/create-context.js.map +1 -1
  31. package/cjs/util/virtualfocus/Context.d.ts +1 -1
  32. package/esm/collapsible/Collapsible.context.d.ts +1 -1
  33. package/esm/form/combobox/FilteredOptions/filtered-options-util.js +1 -3
  34. package/esm/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -1
  35. package/esm/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +2 -2
  36. package/esm/form/combobox/types.d.ts +10 -11
  37. package/esm/form/error-summary/ErrorSummary.d.ts +3 -3
  38. package/esm/form/error-summary/ErrorSummary.js +7 -8
  39. package/esm/form/error-summary/ErrorSummary.js.map +1 -1
  40. package/esm/form/file-upload/FileUpload.context.d.ts +1 -1
  41. package/esm/form/form-summary/FormSummaryEditLink.js +2 -2
  42. package/esm/form/form-summary/FormSummaryEditLink.js.map +1 -1
  43. package/esm/layout/page/parts/PageBlock.js +1 -1
  44. package/esm/layout/page/parts/PageBlock.js.map +1 -1
  45. package/esm/layout/stack/HStack.js +14 -2
  46. package/esm/layout/stack/HStack.js.map +1 -1
  47. package/esm/layout/stack/VStack.js +14 -2
  48. package/esm/layout/stack/VStack.js.map +1 -1
  49. package/esm/overlays/floating/Floating.utils.d.ts +1 -1
  50. package/esm/pagination/Pagination.js +6 -7
  51. package/esm/pagination/Pagination.js.map +1 -1
  52. package/esm/pagination/PaginationItem.d.ts +3 -2
  53. package/esm/pagination/PaginationItem.js +1 -1
  54. package/esm/pagination/PaginationItem.js.map +1 -1
  55. package/esm/provider/i18n/LanguageProvider.d.ts +1 -1
  56. package/esm/provider/i18n/LanguageProvider.js +4 -14
  57. package/esm/provider/i18n/LanguageProvider.js.map +1 -1
  58. package/esm/stepper/context.d.ts +1 -1
  59. package/esm/tabs/Tabs.context.d.ts +1 -1
  60. package/esm/toggle-group/ToggleGroup.context.d.ts +1 -1
  61. package/esm/util/create-context.js.map +1 -1
  62. package/esm/util/virtualfocus/Context.d.ts +1 -1
  63. package/package.json +3 -3
  64. package/src/date/datepicker/datepicker.test.tsx +1 -1
  65. package/src/date/utils/__tests__/parse-dates.test.ts +12 -12
  66. package/src/form/combobox/FilteredOptions/filtered-options-util.test.ts +18 -0
  67. package/src/form/combobox/FilteredOptions/filtered-options-util.ts +1 -3
  68. package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +2 -2
  69. package/src/form/combobox/types.ts +10 -12
  70. package/src/form/error-summary/ErrorSummary.tsx +9 -15
  71. package/src/form/form-summary/FormSummaryEditLink.tsx +12 -9
  72. package/src/layout/page/parts/PageBlock.tsx +1 -1
  73. package/src/layout/stack/HStack.tsx +2 -2
  74. package/src/layout/stack/VStack.tsx +4 -2
  75. package/src/pagination/Pagination.tsx +7 -22
  76. package/src/pagination/PaginationItem.tsx +4 -3
  77. package/src/provider/i18n/LanguageProvider.tsx +0 -2
  78. package/src/util/create-context.tsx +2 -2
@@ -2,7 +2,7 @@ import cl from "clsx";
2
2
  import React, { HTMLAttributes, forwardRef, useRef } from "react";
3
3
  import { BodyShort, Heading } from "../../typography";
4
4
  import { composeEventHandlers } from "../../util/composeEventHandlers";
5
- import { useId, useMergeRefs } from "../../util/hooks";
5
+ import { useMergeRefs } from "../../util/hooks";
6
6
  import ErrorSummaryItem from "./ErrorSummaryItem";
7
7
 
8
8
  export interface ErrorSummaryProps
@@ -33,13 +33,13 @@ interface ErrorSummaryComponent
33
33
  ErrorSummaryProps & React.RefAttributes<HTMLDivElement>
34
34
  > {
35
35
  /**
36
- * Link to error.
36
+ * Error message with link to field.
37
37
  *
38
38
  * @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
39
39
  *
40
40
  * @example
41
41
  * ```jsx
42
- * <ErrorSummary.Item href="#1">
42
+ * <ErrorSummary.Item href="#id-til-alderfelt">
43
43
  * Felt må fylles ut med alder
44
44
  * </ErrorSummary.Item>
45
45
  * ```
@@ -48,7 +48,7 @@ interface ErrorSummaryComponent
48
48
  }
49
49
 
50
50
  /**
51
- * A component that displays a summary of errors.
51
+ * Summary of errors in a form.
52
52
  *
53
53
  * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/errorsummary)
54
54
  * @see 🏷️ {@link ErrorSummaryProps}
@@ -77,15 +77,13 @@ export const ErrorSummary = forwardRef<HTMLDivElement, ErrorSummaryProps>(
77
77
  },
78
78
  ref,
79
79
  ) => {
80
- const headingId = useId();
81
-
82
- const sectionRef = useRef<HTMLDivElement>(null);
80
+ const wrapperRef = useRef<HTMLDivElement>(null);
83
81
  const headingRef = useRef<HTMLHeadingElement>(null);
84
82
 
85
- const mergedRef = useMergeRefs(ref, sectionRef);
83
+ const mergedRef = useMergeRefs(ref, wrapperRef);
86
84
 
87
85
  return (
88
- <section
86
+ <div
89
87
  ref={mergedRef}
90
88
  {...rest}
91
89
  className={cl(
@@ -94,11 +92,8 @@ export const ErrorSummary = forwardRef<HTMLDivElement, ErrorSummaryProps>(
94
92
  `navds-error-summary--${size}`,
95
93
  )}
96
94
  tabIndex={-1}
97
- aria-live="polite"
98
- aria-relevant="all"
99
- aria-labelledby={headingId}
100
95
  onFocus={composeEventHandlers(rest.onFocus, (event) => {
101
- if (event.target === sectionRef.current) {
96
+ if (event.target === wrapperRef.current) {
102
97
  headingRef?.current?.focus();
103
98
  }
104
99
  })}
@@ -107,7 +102,6 @@ export const ErrorSummary = forwardRef<HTMLDivElement, ErrorSummaryProps>(
107
102
  className="navds-error-summary__heading"
108
103
  as={headingTag}
109
104
  size="small"
110
- id={headingId}
111
105
  ref={headingRef}
112
106
  tabIndex={-1}
113
107
  >
@@ -116,7 +110,7 @@ export const ErrorSummary = forwardRef<HTMLDivElement, ErrorSummaryProps>(
116
110
  <BodyShort as="ul" size={size} className="navds-error-summary__list">
117
111
  {children}
118
112
  </BodyShort>
119
- </section>
113
+ </div>
120
114
  );
121
115
  },
122
116
  ) as ErrorSummaryComponent;
@@ -22,14 +22,17 @@ export interface FormSummaryEditProps
22
22
  export const FormSummaryEditLink: OverridableComponent<
23
23
  FormSummaryEditProps,
24
24
  HTMLAnchorElement
25
- > = forwardRef(({ children = "Endre svar", className, ...rest }, ref) => (
26
- <Link
27
- ref={ref}
28
- {...rest}
29
- className={cl("navds-form-summary__edit", className)}
30
- >
31
- {children}
32
- </Link>
33
- ));
25
+ > = forwardRef(
26
+ ({ children = "Endre svar", className, as = "a", ...rest }, ref) => (
27
+ <Link
28
+ ref={ref}
29
+ as={as}
30
+ {...rest}
31
+ className={cl("navds-form-summary__edit", className)}
32
+ >
33
+ {children}
34
+ </Link>
35
+ ),
36
+ );
34
37
 
35
38
  export default FormSummaryEditLink;
@@ -63,7 +63,7 @@ export const PageBlock: OverridableComponent<PageBlockProps, HTMLDivElement> =
63
63
  {...rest}
64
64
  className={cl(
65
65
  "navds-pageblock",
66
- `navds-pageblock--${width}`,
66
+ width && `navds-pageblock--${width}`,
67
67
  className,
68
68
  { "navds-pageblock--gutters": gutters },
69
69
  )}
@@ -26,8 +26,8 @@ export type HStackProps = PrimitiveAsChildProps & Omit<StackProps, "direction">;
26
26
  * </HStack>
27
27
  */
28
28
  export const HStack: OverridableComponent<HStackProps, HTMLDivElement> =
29
- forwardRef((props, ref) => {
30
- return <Stack {...props} ref={ref} direction="row" />;
29
+ forwardRef(({ as = "div", ...rest }, ref) => {
30
+ return <Stack as={as} {...rest} ref={ref} direction="row" />;
31
31
  });
32
32
 
33
33
  export default HStack;
@@ -27,8 +27,10 @@ export type VStackProps = PrimitiveAsChildProps &
27
27
  * </VStack>
28
28
  */
29
29
  export const VStack: OverridableComponent<VStackProps, HTMLDivElement> =
30
- forwardRef((props, ref) => {
31
- return <Stack {...props} ref={ref} direction="column" wrap={false} />;
30
+ forwardRef(({ as = "div", ...rest }, ref) => {
31
+ return (
32
+ <Stack as={as} {...rest} ref={ref} direction="column" wrap={false} />
33
+ );
32
34
  });
33
35
 
34
36
  export default VStack;
@@ -189,21 +189,13 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
189
189
  size={size}
190
190
  icon={
191
191
  <ChevronLeftIcon
192
- className="navds-pagination__prev-next-icon"
193
192
  {...(prevNextTexts
194
193
  ? { "aria-hidden": true }
195
194
  : { title: "Forrige" })}
196
195
  />
197
196
  }
198
197
  >
199
- {prevNextTexts && (
200
- <BodyShort
201
- size={size === "xsmall" ? "small" : size}
202
- className="navds-pagination__prev-text"
203
- >
204
- Forrige
205
- </BodyShort>
206
- )}
198
+ {prevNextTexts && `Forrige`}
207
199
  </Item>
208
200
  </li>
209
201
  {getSteps({ page, count, siblingCount, boundaryCount }).map(
@@ -211,7 +203,10 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
211
203
  const n = Number(step);
212
204
  return Number.isNaN(n) ? (
213
205
  <li className="navds-pagination__ellipsis" key={`${step}${i}`}>
214
- <BodyShort size={size === "xsmall" ? "small" : size}>
206
+ <BodyShort
207
+ size={size === "xsmall" ? "small" : size}
208
+ as="span"
209
+ >
215
210
  ...
216
211
  </BodyShort>
217
212
  </li>
@@ -223,9 +218,7 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
223
218
  page={n}
224
219
  size={size}
225
220
  >
226
- <BodyShort size={size === "xsmall" ? "small" : size}>
227
- {n}
228
- </BodyShort>
221
+ {n}
229
222
  </Item>
230
223
  </li>
231
224
  );
@@ -243,7 +236,6 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
243
236
  size={size}
244
237
  icon={
245
238
  <ChevronRightIcon
246
- className="navds-pagination__prev-next-icon"
247
239
  {...(prevNextTexts
248
240
  ? { "aria-hidden": true }
249
241
  : { title: "Neste" })}
@@ -251,14 +243,7 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
251
243
  }
252
244
  iconPosition="right"
253
245
  >
254
- {prevNextTexts && (
255
- <BodyShort
256
- size={size === "xsmall" ? "small" : size}
257
- className="navds-pagination__next-text"
258
- >
259
- Neste
260
- </BodyShort>
261
- )}
246
+ {prevNextTexts && `Neste`}
262
247
  </Item>
263
248
  </li>
264
249
  </ul>
@@ -11,9 +11,10 @@ export interface PaginationItemProps extends ButtonProps {
11
11
  */
12
12
  selected?: boolean;
13
13
  /**
14
- * The page the item represents
14
+ * Currently only sets `data-page` attribute.
15
+ * @deprecated Use `data-page` instead if you need to access the items page number in the future.
15
16
  */
16
- page: number;
17
+ page?: number;
17
18
  /**
18
19
  * Changes padding, height and font-size
19
20
  * @default "medium"
@@ -48,7 +49,7 @@ export const Item: PaginationItemType = forwardRef(
48
49
  "navds-pagination__item--selected": selected,
49
50
  })}
50
51
  data-page={page}
51
- /* TODO: Breaking change to remove. Add to future major version. */
52
+ /* TODO: Breaking change to remove since it's in use by some applications. Add to future major version. */
52
53
  page={page}
53
54
  {...(Component === "button" && { type: "button" })}
54
55
  {...rest}
@@ -34,13 +34,11 @@ export const useProvider = () => useContext(LanguageProviderContext);
34
34
  export const UNSAFE_AkselLanguageProvider = ({
35
35
  children,
36
36
  translations,
37
- ...rest
38
37
  }: LanguageProviderProps) => {
39
38
  return (
40
39
  <LanguageProviderContext.Provider
41
40
  value={{
42
41
  translations: translations ?? nb,
43
- ...rest,
44
42
  }}
45
43
  >
46
44
  {children}
@@ -40,8 +40,8 @@ export function createContext<T>(options: CreateContextOptions<T> = {}) {
40
40
  * We use forwardRef to allow `ref` to be used as a regular context value
41
41
  * @see https://reactjs.org/docs/forwarding-refs.html#forwarding-refs-to-dom-components
42
42
  */
43
- const Provider = forwardRef(
44
- ({ children, ...context }: ProviderProps<T>, ref) => {
43
+ const Provider = forwardRef<unknown, ProviderProps<T>>(
44
+ ({ children, ...context }, ref) => {
45
45
  // Only re-memoize when prop values change
46
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
47
47
  const value = React.useMemo(() => context, Object.values(context)) as T;