@entur/form 10.0.2-beta.0 → 10.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.
package/dist/form.mjs CHANGED
@@ -9,46 +9,28 @@ import { IconButton } from "@entur/button";
9
9
  import { SubLabel, Paragraph, Heading5, Label } from "@entur/typography";
10
10
  import { colors } from "@entur/tokens";
11
11
  const info = "info";
12
- const error$1 = "error";
12
+ const error$3 = "error";
13
13
  const AlertIcon = ({
14
14
  variant
15
15
  }) => {
16
16
  const iconClass = `eds-feedback-text__icon eds-feedback-text__icon--${variant}`;
17
17
  switch (variant) {
18
18
  case "success":
19
- return /* @__PURE__ */ jsx(
20
- ValidationSuccessFilledIcon,
21
- {
22
- "aria-label": "Suksessmelding",
23
- className: iconClass
24
- }
25
- );
19
+ return /* @__PURE__ */ jsx(ValidationSuccessFilledIcon, { "aria-hidden": "true", className: iconClass });
26
20
  case "negative":
27
- return /* @__PURE__ */ jsx(
28
- ValidationErrorFilledIcon,
29
- {
30
- "aria-label": "Feilmelding",
31
- className: iconClass
32
- }
33
- );
21
+ return /* @__PURE__ */ jsx(ValidationErrorFilledIcon, { "aria-hidden": "true", className: iconClass });
34
22
  case "information":
35
23
  return null;
36
24
  case "warning":
37
25
  return /* @__PURE__ */ jsx(
38
26
  ValidationExclamationFilledIcon,
39
27
  {
40
- "aria-label": "Varselmelding",
41
- className: iconClass
42
- }
43
- );
44
- case error$1:
45
- return /* @__PURE__ */ jsx(
46
- ValidationErrorFilledIcon,
47
- {
48
- "aria-label": "Feilmelding",
28
+ "aria-hidden": "true",
49
29
  className: iconClass
50
30
  }
51
31
  );
32
+ case error$3:
33
+ return /* @__PURE__ */ jsx(ValidationErrorFilledIcon, { "aria-hidden": "true", className: iconClass });
52
34
  case info:
53
35
  return null;
54
36
  default:
@@ -62,20 +44,22 @@ const FeedbackText = ({
62
44
  className,
63
45
  ...rest
64
46
  }) => {
47
+ const hasContent = children !== void 0 && children !== null;
65
48
  return /* @__PURE__ */ jsxs(
66
49
  SubLabel,
67
50
  {
68
51
  className: classNames(
69
52
  "eds-feedback-text",
70
53
  {
71
- "eds-feedback-text--information": variant === info || variant === "information"
54
+ "eds-feedback-text--information": variant === info || variant === "information",
55
+ "eds-feedback-text--empty": !hasContent
72
56
  },
73
57
  className
74
58
  ),
75
59
  ...rest,
76
60
  children: [
77
- !hideIcon && /* @__PURE__ */ jsx(AlertIcon, { variant }),
78
- /* @__PURE__ */ jsx("span", { className: "eds-feedback-text__text", children })
61
+ hasContent && !hideIcon && variant && /* @__PURE__ */ jsx(AlertIcon, { variant }),
62
+ hasContent && /* @__PURE__ */ jsx("span", { className: "eds-feedback-text__text", children })
79
63
  ]
80
64
  }
81
65
  );
@@ -142,7 +126,7 @@ const useVariant = () => {
142
126
  const context = React__default.useContext(VariantContext);
143
127
  return context;
144
128
  };
145
- const error = "error";
129
+ const error$2 = "error";
146
130
  const BaseFormControl = React__default.forwardRef(
147
131
  ({
148
132
  after,
@@ -166,12 +150,22 @@ const BaseFormControl = React__default.forwardRef(
166
150
  labelProps,
167
151
  style,
168
152
  disableLabelAnimation = false,
169
- ariaAlertOnFeedback = false,
153
+ ariaAlertOnFeedback = "status",
154
+ feedbackProps,
170
155
  ariaLabelOnReadOnly = "Dette skjemafeltet kan bare leses",
171
156
  ...rest
172
157
  }, ref) => {
173
158
  const contextVariant = useVariant();
174
- const currentVariant = variant || contextVariant;
159
+ const currentVariant = variant || contextVariant || void 0;
160
+ const {
161
+ role: feedbackRoleOverride,
162
+ "aria-live": feedbackAriaLive,
163
+ ...restFeedbackProps
164
+ } = feedbackProps ?? {};
165
+ const defaultFeedbackRole = ariaAlertOnFeedback === true || ariaAlertOnFeedback === "alert" ? "alert" : ariaAlertOnFeedback === "status" ? "status" : void 0;
166
+ const feedbackRole = feedbackRoleOverride ?? (feedbackAriaLive !== void 0 ? void 0 : defaultFeedbackRole);
167
+ const isLiveRegion = feedbackRole !== void 0 || feedbackAriaLive !== void 0;
168
+ const showFeedback = Boolean(feedback && currentVariant);
175
169
  return /* @__PURE__ */ jsx(InputGroupContextProvider, { children: /* @__PURE__ */ jsxs(
176
170
  "div",
177
171
  {
@@ -193,7 +187,7 @@ const BaseFormControl = React__default.forwardRef(
193
187
  `eds-form-control-wrapper--size-${size}`,
194
188
  {
195
189
  "eds-form-control-wrapper--success": currentVariant === "success",
196
- "eds-form-control-wrapper--negative": currentVariant === "negative" || currentVariant === error,
190
+ "eds-form-control-wrapper--negative": currentVariant === "negative" || currentVariant === error$2,
197
191
  "eds-form-control-wrapper--disabled": disabled,
198
192
  "eds-form-control-wrapper--readonly": readOnly,
199
193
  "eds-form-control-wrapper--is-filled": isFilled2
@@ -249,12 +243,17 @@ const BaseFormControl = React__default.forwardRef(
249
243
  ]
250
244
  }
251
245
  ),
252
- feedback && currentVariant && /* @__PURE__ */ jsx(
246
+ (isLiveRegion || showFeedback) && // Live region-en rendres alltid, slik at den finnes i DOM før
247
+ // feedback-teksten settes — ellers annonserer ikke skjermlesere
248
+ // innholdet pålitelig
249
+ /* @__PURE__ */ jsx(
253
250
  FeedbackText,
254
251
  {
255
252
  variant: currentVariant,
256
- role: ariaAlertOnFeedback === true || ariaAlertOnFeedback === "alert" ? "alert" : ariaAlertOnFeedback === "status" ? "status" : void 0,
257
- children: feedback
253
+ role: feedbackRole,
254
+ "aria-live": feedbackAriaLive,
255
+ ...restFeedbackProps,
256
+ children: showFeedback ? feedback : void 0
258
257
  }
259
258
  ),
260
259
  after
@@ -709,6 +708,7 @@ function isFilled(obj, SSR = false) {
709
708
  }
710
709
  return false;
711
710
  }
711
+ const error$1 = "error";
712
712
  const TextArea = React__default.forwardRef(
713
713
  ({
714
714
  variant,
@@ -724,6 +724,8 @@ const TextArea = React__default.forwardRef(
724
724
  onChange,
725
725
  disableLabelAnimation,
726
726
  resize,
727
+ ariaAlertOnFeedback,
728
+ feedbackProps,
727
729
  ...rest
728
730
  }, ref) => {
729
731
  const textAreaId = `eds-textarea${useId()}`;
@@ -744,6 +746,8 @@ const TextArea = React__default.forwardRef(
744
746
  labelTooltipPlacement,
745
747
  labelProps: { className: "eds-textarea__label" },
746
748
  disableLabelAnimation,
749
+ ariaAlertOnFeedback,
750
+ feedbackProps,
747
751
  onClick: (e) => {
748
752
  if (e.target === e.currentTarget) textareaRef?.current?.focus();
749
753
  },
@@ -798,13 +802,14 @@ const TextAreaBase = React__default.forwardRef(
798
802
  disabled,
799
803
  onChange: handleChange,
800
804
  value,
801
- "aria-invalid": currentVariant === "error",
805
+ "aria-invalid": currentVariant === "negative" || currentVariant === error$1,
802
806
  style: resize ? { ...style, resize } : style,
803
807
  ...rest
804
808
  }
805
809
  );
806
810
  }
807
811
  );
812
+ const error = "error";
808
813
  const TextField = React__default.forwardRef(
809
814
  ({
810
815
  prepend,
@@ -828,7 +833,8 @@ const TextField = React__default.forwardRef(
828
833
  onClear,
829
834
  clearButtonAriaLabel = "Tøm felt",
830
835
  value,
831
- ariaAlertOnFeedback = false,
836
+ ariaAlertOnFeedback,
837
+ feedbackProps,
832
838
  ...rest
833
839
  }, ref) => {
834
840
  const randomId = `eds-textfield${useId()}`;
@@ -879,6 +885,7 @@ const TextField = React__default.forwardRef(
879
885
  disableLabelAnimation,
880
886
  labelProps,
881
887
  ariaAlertOnFeedback,
888
+ feedbackProps,
882
889
  onClick: (e) => {
883
890
  if (e.target === e.currentTarget) textFieldRef?.current?.focus();
884
891
  },
@@ -927,7 +934,7 @@ const TextFieldBase = React__default.forwardRef(
927
934
  return /* @__PURE__ */ jsx(
928
935
  "input",
929
936
  {
930
- "aria-invalid": currentVariant === "error",
937
+ "aria-invalid": currentVariant === "negative" || currentVariant === error,
931
938
  className: "eds-form-control",
932
939
  disabled,
933
940
  readOnly,