@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/BaseFormControl.d.ts +20 -14
- package/dist/FeedbackText.d.ts +4 -3
- package/dist/TextArea.d.ts +3 -2
- package/dist/TextField.d.ts +3 -14
- package/dist/form.cjs +44 -37
- package/dist/form.cjs.map +1 -1
- package/dist/form.mjs +44 -37
- package/dist/form.mjs.map +1 -1
- package/dist/styles.css +4 -1
- package/package.json +7 -7
|
@@ -5,7 +5,25 @@ import { Placement } from '../../tooltip';
|
|
|
5
5
|
declare const info = "info";
|
|
6
6
|
/** @deprecated use variant="negative" instead */
|
|
7
7
|
declare const error = "error";
|
|
8
|
-
|
|
8
|
+
/** Props som styrer hvordan feedback-teksten annonseres av skjermlesere.
|
|
9
|
+
* Deles av alle skjemakomponentene som rendrer en feedback-tekst */
|
|
10
|
+
export type FeedbackAnnouncementProps = {
|
|
11
|
+
/** Styrer hvordan feedback-teksten annonseres av skjermlesere.
|
|
12
|
+
* Standarden 'status' lar skjermleseren annonsere meldingen når
|
|
13
|
+
* brukeren er ferdig med det den holder på med, og live region-en
|
|
14
|
+
* rendres da alltid i DOM, også før meldingen finnes.
|
|
15
|
+
* true/'alert' gir role="alert", som avbryter skjermleseren og
|
|
16
|
+
* annonserer meldingen umiddelbart – bruk den bare til meldinger som
|
|
17
|
+
* hindrer brukeren i å komme videre. false skrur av automatisk
|
|
18
|
+
* annonsering.
|
|
19
|
+
* @default 'status'
|
|
20
|
+
*/
|
|
21
|
+
ariaAlertOnFeedback?: boolean | 'alert' | 'status';
|
|
22
|
+
/** Ekstra props som sendes til feedback-teksten. Egne `role`- og
|
|
23
|
+
* `aria-live`-verdier her overstyrer ariaAlertOnFeedback */
|
|
24
|
+
feedbackProps?: React.HTMLAttributes<HTMLElement>;
|
|
25
|
+
};
|
|
26
|
+
export type BaseFormControlProps = React.HTMLAttributes<HTMLDivElement> & FeedbackAnnouncementProps & {
|
|
9
27
|
/** Et skjemaelement med `eds-form-control`-klassen */
|
|
10
28
|
children: React.ReactNode;
|
|
11
29
|
/** Ekstra klassenavn */
|
|
@@ -47,13 +65,7 @@ export type BaseFormControlProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
|
47
65
|
style?: React.CSSProperties;
|
|
48
66
|
/** Plasserer labelen statisk på toppen av inputfeltet */
|
|
49
67
|
disableLabelAnimation?: boolean;
|
|
50
|
-
/** Setter feedback-tekstens rolle for skjermlesere.
|
|
51
|
-
* 'alert' = aria-live="assertive" (avbryter umiddelbart)
|
|
52
|
-
* 'status' = aria-live="polite" (venter til bruker er ferdig)
|
|
53
|
-
* undefined/false = ingen automatisk annonsering
|
|
54
|
-
*/
|
|
55
68
|
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
56
|
-
ariaAlertOnFeedback?: boolean | 'alert' | 'status';
|
|
57
69
|
/** Legg til et element etter feltet */
|
|
58
70
|
after?: React.ReactNode;
|
|
59
71
|
/** Legg til et element før feltet */
|
|
@@ -61,7 +73,7 @@ export type BaseFormControlProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
|
61
73
|
/** Aria-label som brukes når inputfeltet er i read-only modus */
|
|
62
74
|
ariaLabelOnReadOnly?: string;
|
|
63
75
|
};
|
|
64
|
-
export declare const BaseFormControl: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
76
|
+
export declare const BaseFormControl: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & FeedbackAnnouncementProps & {
|
|
65
77
|
/** Et skjemaelement med `eds-form-control`-klassen */
|
|
66
78
|
children: React.ReactNode;
|
|
67
79
|
/** Ekstra klassenavn */
|
|
@@ -103,13 +115,7 @@ export declare const BaseFormControl: React.ForwardRefExoticComponent<React.HTML
|
|
|
103
115
|
style?: React.CSSProperties;
|
|
104
116
|
/** Plasserer labelen statisk på toppen av inputfeltet */
|
|
105
117
|
disableLabelAnimation?: boolean;
|
|
106
|
-
/** Setter feedback-tekstens rolle for skjermlesere.
|
|
107
|
-
* 'alert' = aria-live="assertive" (avbryter umiddelbart)
|
|
108
|
-
* 'status' = aria-live="polite" (venter til bruker er ferdig)
|
|
109
|
-
* undefined/false = ingen automatisk annonsering
|
|
110
|
-
*/
|
|
111
118
|
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
112
|
-
ariaAlertOnFeedback?: boolean | "alert" | "status";
|
|
113
119
|
/** Legg til et element etter feltet */
|
|
114
120
|
after?: React.ReactNode;
|
|
115
121
|
/** Legg til et element før feltet */
|
package/dist/FeedbackText.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ declare const info = "info";
|
|
|
5
5
|
/** @deprecated use variant="negative" instead */
|
|
6
6
|
declare const error = "error";
|
|
7
7
|
export type FeedbackTextProps = {
|
|
8
|
-
/** Teksten som vises
|
|
9
|
-
|
|
8
|
+
/** Teksten som vises. Uten tekst rendres en tom (usynlig) container,
|
|
9
|
+
* slik at en aria-live-region kan eksistere i DOM før meldingen settes */
|
|
10
|
+
children?: React.ReactNode;
|
|
10
11
|
/** Skjuler ikonet */
|
|
11
12
|
hideIcon?: boolean;
|
|
12
13
|
/** Feedbackvarianten*/
|
|
13
|
-
variant
|
|
14
|
+
variant?: VariantType | typeof error | typeof info;
|
|
14
15
|
/** Ekstra klassenavn */
|
|
15
16
|
className?: string;
|
|
16
17
|
[key: string]: any;
|
package/dist/TextArea.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { VariantType } from '../../utils';
|
|
3
|
+
import { FeedbackAnnouncementProps } from './BaseFormControl';
|
|
3
4
|
import { Placement } from '../../tooltip';
|
|
4
5
|
/** @deprecated use variant="information" instead */
|
|
5
6
|
declare const info = "info";
|
|
@@ -32,7 +33,7 @@ export type TextAreaProps = {
|
|
|
32
33
|
* @default "vertical"
|
|
33
34
|
*/
|
|
34
35
|
resize?: 'vertical' | 'none';
|
|
35
|
-
} & React.TextareaHTMLAttributes<HTMLTextAreaElement>;
|
|
36
|
+
} & FeedbackAnnouncementProps & React.TextareaHTMLAttributes<HTMLTextAreaElement>;
|
|
36
37
|
export declare const TextArea: React.ForwardRefExoticComponent<{
|
|
37
38
|
/** Ekstra klassenavn */
|
|
38
39
|
className?: string;
|
|
@@ -60,5 +61,5 @@ export declare const TextArea: React.ForwardRefExoticComponent<{
|
|
|
60
61
|
* @default "vertical"
|
|
61
62
|
*/
|
|
62
63
|
resize?: "vertical" | "none";
|
|
63
|
-
} & React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
64
|
+
} & FeedbackAnnouncementProps & React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
64
65
|
export {};
|
package/dist/TextField.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Placement } from '../../tooltip';
|
|
3
3
|
import { VariantType } from '../../utils';
|
|
4
|
+
import { FeedbackAnnouncementProps } from './BaseFormControl';
|
|
4
5
|
/** @deprecated use variant="information" instead */
|
|
5
6
|
declare const info = "info";
|
|
6
7
|
/** @deprecated use variant="negative" instead */
|
|
@@ -48,13 +49,7 @@ export type TextFieldProps = {
|
|
|
48
49
|
* @default "Tøm felt"
|
|
49
50
|
*/
|
|
50
51
|
clearButtonAriaLabel?: string;
|
|
51
|
-
|
|
52
|
-
* 'alert' = aria-live="assertive" (avbryter umiddelbart)
|
|
53
|
-
* 'status' = aria-live="polite" (venter til bruker er ferdig)
|
|
54
|
-
* undefined/false = ingen automatisk annonsering
|
|
55
|
-
*/
|
|
56
|
-
ariaAlertOnFeedback?: boolean | 'alert' | 'status';
|
|
57
|
-
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'label'>;
|
|
52
|
+
} & FeedbackAnnouncementProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'label'>;
|
|
58
53
|
export declare const TextField: React.ForwardRefExoticComponent<{
|
|
59
54
|
/** Tekst eller ikon som kommer før inputfeltet */
|
|
60
55
|
prepend?: React.ReactNode;
|
|
@@ -98,11 +93,5 @@ export declare const TextField: React.ForwardRefExoticComponent<{
|
|
|
98
93
|
* @default "Tøm felt"
|
|
99
94
|
*/
|
|
100
95
|
clearButtonAriaLabel?: string;
|
|
101
|
-
|
|
102
|
-
* 'alert' = aria-live="assertive" (avbryter umiddelbart)
|
|
103
|
-
* 'status' = aria-live="polite" (venter til bruker er ferdig)
|
|
104
|
-
* undefined/false = ingen automatisk annonsering
|
|
105
|
-
*/
|
|
106
|
-
ariaAlertOnFeedback?: boolean | "alert" | "status";
|
|
107
|
-
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "label" | "size"> & React.RefAttributes<HTMLInputElement>>;
|
|
96
|
+
} & FeedbackAnnouncementProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, "label" | "size"> & React.RefAttributes<HTMLInputElement>>;
|
|
108
97
|
export {};
|
package/dist/form.cjs
CHANGED
|
@@ -27,46 +27,28 @@ function _interopNamespaceDefault(e) {
|
|
|
27
27
|
}
|
|
28
28
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
29
29
|
const info = "info";
|
|
30
|
-
const error$
|
|
30
|
+
const error$3 = "error";
|
|
31
31
|
const AlertIcon = ({
|
|
32
32
|
variant
|
|
33
33
|
}) => {
|
|
34
34
|
const iconClass = `eds-feedback-text__icon eds-feedback-text__icon--${variant}`;
|
|
35
35
|
switch (variant) {
|
|
36
36
|
case "success":
|
|
37
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
38
|
-
icons.ValidationSuccessFilledIcon,
|
|
39
|
-
{
|
|
40
|
-
"aria-label": "Suksessmelding",
|
|
41
|
-
className: iconClass
|
|
42
|
-
}
|
|
43
|
-
);
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsx(icons.ValidationSuccessFilledIcon, { "aria-hidden": "true", className: iconClass });
|
|
44
38
|
case "negative":
|
|
45
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
46
|
-
icons.ValidationErrorFilledIcon,
|
|
47
|
-
{
|
|
48
|
-
"aria-label": "Feilmelding",
|
|
49
|
-
className: iconClass
|
|
50
|
-
}
|
|
51
|
-
);
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx(icons.ValidationErrorFilledIcon, { "aria-hidden": "true", className: iconClass });
|
|
52
40
|
case "information":
|
|
53
41
|
return null;
|
|
54
42
|
case "warning":
|
|
55
43
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
56
44
|
icons.ValidationExclamationFilledIcon,
|
|
57
45
|
{
|
|
58
|
-
"aria-
|
|
59
|
-
className: iconClass
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
case error$1:
|
|
63
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
64
|
-
icons.ValidationErrorFilledIcon,
|
|
65
|
-
{
|
|
66
|
-
"aria-label": "Feilmelding",
|
|
46
|
+
"aria-hidden": "true",
|
|
67
47
|
className: iconClass
|
|
68
48
|
}
|
|
69
49
|
);
|
|
50
|
+
case error$3:
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsx(icons.ValidationErrorFilledIcon, { "aria-hidden": "true", className: iconClass });
|
|
70
52
|
case info:
|
|
71
53
|
return null;
|
|
72
54
|
default:
|
|
@@ -80,20 +62,22 @@ const FeedbackText = ({
|
|
|
80
62
|
className,
|
|
81
63
|
...rest
|
|
82
64
|
}) => {
|
|
65
|
+
const hasContent = children !== void 0 && children !== null;
|
|
83
66
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
84
67
|
typography.SubLabel,
|
|
85
68
|
{
|
|
86
69
|
className: classNames(
|
|
87
70
|
"eds-feedback-text",
|
|
88
71
|
{
|
|
89
|
-
"eds-feedback-text--information": variant === info || variant === "information"
|
|
72
|
+
"eds-feedback-text--information": variant === info || variant === "information",
|
|
73
|
+
"eds-feedback-text--empty": !hasContent
|
|
90
74
|
},
|
|
91
75
|
className
|
|
92
76
|
),
|
|
93
77
|
...rest,
|
|
94
78
|
children: [
|
|
95
|
-
!hideIcon && /* @__PURE__ */ jsxRuntime.jsx(AlertIcon, { variant }),
|
|
96
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "eds-feedback-text__text", children })
|
|
79
|
+
hasContent && !hideIcon && variant && /* @__PURE__ */ jsxRuntime.jsx(AlertIcon, { variant }),
|
|
80
|
+
hasContent && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "eds-feedback-text__text", children })
|
|
97
81
|
]
|
|
98
82
|
}
|
|
99
83
|
);
|
|
@@ -160,7 +144,7 @@ const useVariant = () => {
|
|
|
160
144
|
const context = React.useContext(VariantContext);
|
|
161
145
|
return context;
|
|
162
146
|
};
|
|
163
|
-
const error = "error";
|
|
147
|
+
const error$2 = "error";
|
|
164
148
|
const BaseFormControl = React.forwardRef(
|
|
165
149
|
({
|
|
166
150
|
after,
|
|
@@ -184,12 +168,22 @@ const BaseFormControl = React.forwardRef(
|
|
|
184
168
|
labelProps,
|
|
185
169
|
style,
|
|
186
170
|
disableLabelAnimation = false,
|
|
187
|
-
ariaAlertOnFeedback =
|
|
171
|
+
ariaAlertOnFeedback = "status",
|
|
172
|
+
feedbackProps,
|
|
188
173
|
ariaLabelOnReadOnly = "Dette skjemafeltet kan bare leses",
|
|
189
174
|
...rest
|
|
190
175
|
}, ref) => {
|
|
191
176
|
const contextVariant = useVariant();
|
|
192
|
-
const currentVariant = variant || contextVariant;
|
|
177
|
+
const currentVariant = variant || contextVariant || void 0;
|
|
178
|
+
const {
|
|
179
|
+
role: feedbackRoleOverride,
|
|
180
|
+
"aria-live": feedbackAriaLive,
|
|
181
|
+
...restFeedbackProps
|
|
182
|
+
} = feedbackProps ?? {};
|
|
183
|
+
const defaultFeedbackRole = ariaAlertOnFeedback === true || ariaAlertOnFeedback === "alert" ? "alert" : ariaAlertOnFeedback === "status" ? "status" : void 0;
|
|
184
|
+
const feedbackRole = feedbackRoleOverride ?? (feedbackAriaLive !== void 0 ? void 0 : defaultFeedbackRole);
|
|
185
|
+
const isLiveRegion = feedbackRole !== void 0 || feedbackAriaLive !== void 0;
|
|
186
|
+
const showFeedback = Boolean(feedback && currentVariant);
|
|
193
187
|
return /* @__PURE__ */ jsxRuntime.jsx(InputGroupContextProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
194
188
|
"div",
|
|
195
189
|
{
|
|
@@ -211,7 +205,7 @@ const BaseFormControl = React.forwardRef(
|
|
|
211
205
|
`eds-form-control-wrapper--size-${size}`,
|
|
212
206
|
{
|
|
213
207
|
"eds-form-control-wrapper--success": currentVariant === "success",
|
|
214
|
-
"eds-form-control-wrapper--negative": currentVariant === "negative" || currentVariant === error,
|
|
208
|
+
"eds-form-control-wrapper--negative": currentVariant === "negative" || currentVariant === error$2,
|
|
215
209
|
"eds-form-control-wrapper--disabled": disabled,
|
|
216
210
|
"eds-form-control-wrapper--readonly": readOnly,
|
|
217
211
|
"eds-form-control-wrapper--is-filled": isFilled2
|
|
@@ -267,12 +261,17 @@ const BaseFormControl = React.forwardRef(
|
|
|
267
261
|
]
|
|
268
262
|
}
|
|
269
263
|
),
|
|
270
|
-
|
|
264
|
+
(isLiveRegion || showFeedback) && // Live region-en rendres alltid, slik at den finnes i DOM før
|
|
265
|
+
// feedback-teksten settes — ellers annonserer ikke skjermlesere
|
|
266
|
+
// innholdet pålitelig
|
|
267
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
271
268
|
FeedbackText,
|
|
272
269
|
{
|
|
273
270
|
variant: currentVariant,
|
|
274
|
-
role:
|
|
275
|
-
|
|
271
|
+
role: feedbackRole,
|
|
272
|
+
"aria-live": feedbackAriaLive,
|
|
273
|
+
...restFeedbackProps,
|
|
274
|
+
children: showFeedback ? feedback : void 0
|
|
276
275
|
}
|
|
277
276
|
),
|
|
278
277
|
after
|
|
@@ -727,6 +726,7 @@ function isFilled(obj, SSR = false) {
|
|
|
727
726
|
}
|
|
728
727
|
return false;
|
|
729
728
|
}
|
|
729
|
+
const error$1 = "error";
|
|
730
730
|
const TextArea = React.forwardRef(
|
|
731
731
|
({
|
|
732
732
|
variant,
|
|
@@ -742,6 +742,8 @@ const TextArea = React.forwardRef(
|
|
|
742
742
|
onChange,
|
|
743
743
|
disableLabelAnimation,
|
|
744
744
|
resize,
|
|
745
|
+
ariaAlertOnFeedback,
|
|
746
|
+
feedbackProps,
|
|
745
747
|
...rest
|
|
746
748
|
}, ref) => {
|
|
747
749
|
const textAreaId = `eds-textarea${React.useId()}`;
|
|
@@ -762,6 +764,8 @@ const TextArea = React.forwardRef(
|
|
|
762
764
|
labelTooltipPlacement,
|
|
763
765
|
labelProps: { className: "eds-textarea__label" },
|
|
764
766
|
disableLabelAnimation,
|
|
767
|
+
ariaAlertOnFeedback,
|
|
768
|
+
feedbackProps,
|
|
765
769
|
onClick: (e) => {
|
|
766
770
|
if (e.target === e.currentTarget) textareaRef?.current?.focus();
|
|
767
771
|
},
|
|
@@ -816,13 +820,14 @@ const TextAreaBase = React.forwardRef(
|
|
|
816
820
|
disabled,
|
|
817
821
|
onChange: handleChange,
|
|
818
822
|
value,
|
|
819
|
-
"aria-invalid": currentVariant === "error
|
|
823
|
+
"aria-invalid": currentVariant === "negative" || currentVariant === error$1,
|
|
820
824
|
style: resize ? { ...style, resize } : style,
|
|
821
825
|
...rest
|
|
822
826
|
}
|
|
823
827
|
);
|
|
824
828
|
}
|
|
825
829
|
);
|
|
830
|
+
const error = "error";
|
|
826
831
|
const TextField = React.forwardRef(
|
|
827
832
|
({
|
|
828
833
|
prepend,
|
|
@@ -846,7 +851,8 @@ const TextField = React.forwardRef(
|
|
|
846
851
|
onClear,
|
|
847
852
|
clearButtonAriaLabel = "Tøm felt",
|
|
848
853
|
value,
|
|
849
|
-
ariaAlertOnFeedback
|
|
854
|
+
ariaAlertOnFeedback,
|
|
855
|
+
feedbackProps,
|
|
850
856
|
...rest
|
|
851
857
|
}, ref) => {
|
|
852
858
|
const randomId = `eds-textfield${React.useId()}`;
|
|
@@ -897,6 +903,7 @@ const TextField = React.forwardRef(
|
|
|
897
903
|
disableLabelAnimation,
|
|
898
904
|
labelProps,
|
|
899
905
|
ariaAlertOnFeedback,
|
|
906
|
+
feedbackProps,
|
|
900
907
|
onClick: (e) => {
|
|
901
908
|
if (e.target === e.currentTarget) textFieldRef?.current?.focus();
|
|
902
909
|
},
|
|
@@ -945,7 +952,7 @@ const TextFieldBase = React.forwardRef(
|
|
|
945
952
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
946
953
|
"input",
|
|
947
954
|
{
|
|
948
|
-
"aria-invalid": currentVariant === "error
|
|
955
|
+
"aria-invalid": currentVariant === "negative" || currentVariant === error,
|
|
949
956
|
className: "eds-form-control",
|
|
950
957
|
disabled,
|
|
951
958
|
readOnly,
|