@sproutsocial/seeds-react-form-field 1.1.19 → 1.1.21

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/CHANGELOG.md DELETED
@@ -1,277 +0,0 @@
1
- # @sproutsocial/seeds-react-form-field
2
-
3
- ## 1.1.19
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [85f9728]
8
- - Updated dependencies [fa7d859]
9
- - @sproutsocial/seeds-react-theme@4.2.0
10
- - @sproutsocial/seeds-react-box@1.1.23
11
- - @sproutsocial/seeds-react-label@1.0.25
12
- - @sproutsocial/seeds-react-visually-hidden@1.0.24
13
-
14
- ## 1.1.18
15
-
16
- ### Patch Changes
17
-
18
- - Updated dependencies [65b5879]
19
- - @sproutsocial/seeds-react-text@1.5.0
20
- - @sproutsocial/seeds-react-label@1.0.24
21
-
22
- ## 1.1.17
23
-
24
- ### Patch Changes
25
-
26
- - Updated dependencies [a13a571]
27
- - @sproutsocial/seeds-react-theme@4.1.1
28
- - @sproutsocial/seeds-react-box@1.1.22
29
- - @sproutsocial/seeds-react-label@1.0.23
30
- - @sproutsocial/seeds-react-visually-hidden@1.0.23
31
-
32
- ## 1.1.16
33
-
34
- ### Patch Changes
35
-
36
- - Updated dependencies [edc1819]
37
- - @sproutsocial/seeds-react-text@1.4.3
38
- - @sproutsocial/seeds-react-label@1.0.22
39
-
40
- ## 1.1.15
41
-
42
- ### Patch Changes
43
-
44
- - Updated dependencies [5892f44]
45
- - @sproutsocial/seeds-react-system-props@3.1.1
46
- - @sproutsocial/seeds-react-box@1.1.21
47
- - @sproutsocial/seeds-react-label@1.0.21
48
- - @sproutsocial/seeds-react-text@1.4.2
49
- - @sproutsocial/seeds-react-visually-hidden@1.0.22
50
-
51
- ## 1.1.14
52
-
53
- ### Patch Changes
54
-
55
- - Updated dependencies [5114a32]
56
- - @sproutsocial/seeds-react-theme@4.1.0
57
- - @sproutsocial/seeds-react-box@1.1.20
58
- - @sproutsocial/seeds-react-label@1.0.20
59
- - @sproutsocial/seeds-react-visually-hidden@1.0.21
60
-
61
- ## 1.1.13
62
-
63
- ### Patch Changes
64
-
65
- - Updated dependencies [132ef9d]
66
- - Updated dependencies [132ef9d]
67
- - @sproutsocial/seeds-react-theme@4.0.0
68
- - @sproutsocial/seeds-react-system-props@3.1.0
69
- - @sproutsocial/seeds-react-box@1.1.19
70
- - @sproutsocial/seeds-react-label@1.0.19
71
- - @sproutsocial/seeds-react-visually-hidden@1.0.20
72
- - @sproutsocial/seeds-react-text@1.4.1
73
-
74
- ## 1.1.12
75
-
76
- ### Patch Changes
77
-
78
- - Updated dependencies [47c62b3]
79
- - @sproutsocial/seeds-react-theme@3.7.1
80
- - @sproutsocial/seeds-react-box@1.1.18
81
- - @sproutsocial/seeds-react-label@1.0.18
82
- - @sproutsocial/seeds-react-visually-hidden@1.0.19
83
-
84
- ## 1.1.11
85
-
86
- ### Patch Changes
87
-
88
- - Updated dependencies [06da9c2]
89
- - @sproutsocial/seeds-react-theme@3.7.0
90
- - @sproutsocial/seeds-react-box@1.1.17
91
- - @sproutsocial/seeds-react-label@1.0.17
92
- - @sproutsocial/seeds-react-visually-hidden@1.0.18
93
-
94
- ## 1.1.10
95
-
96
- ### Patch Changes
97
-
98
- - Updated dependencies [4ba8720]
99
- - @sproutsocial/seeds-react-theme@3.6.2
100
- - @sproutsocial/seeds-react-box@1.1.16
101
- - @sproutsocial/seeds-react-label@1.0.16
102
- - @sproutsocial/seeds-react-visually-hidden@1.0.17
103
-
104
- ## 1.1.9
105
-
106
- ### Patch Changes
107
-
108
- - Updated dependencies [1f9a473]
109
- - @sproutsocial/seeds-react-theme@3.6.1
110
- - @sproutsocial/seeds-react-box@1.1.15
111
- - @sproutsocial/seeds-react-label@1.0.15
112
- - @sproutsocial/seeds-react-visually-hidden@1.0.16
113
-
114
- ## 1.1.8
115
-
116
- ### Patch Changes
117
-
118
- - Updated dependencies [17d4f12]
119
- - @sproutsocial/seeds-react-theme@3.6.0
120
- - @sproutsocial/seeds-react-box@1.1.14
121
- - @sproutsocial/seeds-react-label@1.0.14
122
- - @sproutsocial/seeds-react-visually-hidden@1.0.15
123
-
124
- ## 1.1.7
125
-
126
- ### Patch Changes
127
-
128
- - @sproutsocial/seeds-react-visually-hidden@1.0.14
129
-
130
- ## 1.1.6
131
-
132
- ### Patch Changes
133
-
134
- - Updated dependencies [118e300]
135
- - @sproutsocial/seeds-react-theme@3.5.1
136
- - @sproutsocial/seeds-react-box@1.1.13
137
- - @sproutsocial/seeds-react-label@1.0.13
138
- - @sproutsocial/seeds-react-visually-hidden@1.0.13
139
-
140
- ## 1.1.5
141
-
142
- ### Patch Changes
143
-
144
- - Updated dependencies [db6ce39]
145
- - Updated dependencies [20bb01b]
146
- - @sproutsocial/seeds-react-theme@3.5.0
147
- - @sproutsocial/seeds-react-box@1.1.12
148
- - @sproutsocial/seeds-react-label@1.0.12
149
- - @sproutsocial/seeds-react-visually-hidden@1.0.12
150
-
151
- ## 1.1.4
152
-
153
- ### Patch Changes
154
-
155
- - Updated dependencies [29ced53]
156
- - @sproutsocial/seeds-react-text@1.4.0
157
- - @sproutsocial/seeds-react-label@1.0.11
158
-
159
- ## 1.1.3
160
-
161
- ### Patch Changes
162
-
163
- - Updated dependencies [7716e16]
164
- - @sproutsocial/seeds-react-theme@3.4.0
165
- - @sproutsocial/seeds-react-box@1.1.11
166
- - @sproutsocial/seeds-react-label@1.0.10
167
- - @sproutsocial/seeds-react-visually-hidden@1.0.11
168
-
169
- ## 1.1.2
170
-
171
- ### Patch Changes
172
-
173
- - @sproutsocial/seeds-react-theme@3.3.2
174
- - @sproutsocial/seeds-react-box@1.1.10
175
- - @sproutsocial/seeds-react-label@1.0.9
176
- - @sproutsocial/seeds-react-visually-hidden@1.0.10
177
-
178
- ## 1.1.1
179
-
180
- ### Patch Changes
181
-
182
- - @sproutsocial/seeds-react-theme@3.3.1
183
- - @sproutsocial/seeds-react-box@1.1.9
184
- - @sproutsocial/seeds-react-label@1.0.8
185
- - @sproutsocial/seeds-react-visually-hidden@1.0.9
186
-
187
- ## 1.1.0
188
-
189
- ### Minor Changes
190
-
191
- - 81584cb: Add helper text to input element's `aria-describedby`
192
- Bug fix: only add `aria-describedby` if error or helper text exists
193
-
194
- ## 1.0.7
195
-
196
- ### Patch Changes
197
-
198
- - Updated dependencies [750d1ea]
199
- - @sproutsocial/seeds-react-theme@3.3.0
200
- - @sproutsocial/seeds-react-visually-hidden@1.0.8
201
- - @sproutsocial/seeds-react-box@1.1.8
202
- - @sproutsocial/seeds-react-label@1.0.7
203
-
204
- ## 1.0.6
205
-
206
- ### Patch Changes
207
-
208
- - Updated dependencies [fa7579a]
209
- - @sproutsocial/seeds-react-theme@3.2.1
210
- - @sproutsocial/seeds-react-box@1.1.7
211
- - @sproutsocial/seeds-react-label@1.0.6
212
- - @sproutsocial/seeds-react-visually-hidden@1.0.7
213
-
214
- ## 1.0.5
215
-
216
- ### Patch Changes
217
-
218
- - Updated dependencies [8f6ba8d]
219
- - @sproutsocial/seeds-react-theme@3.2.0
220
- - @sproutsocial/seeds-react-box@1.1.6
221
- - @sproutsocial/seeds-react-label@1.0.5
222
- - @sproutsocial/seeds-react-visually-hidden@1.0.6
223
-
224
- ## 1.0.4
225
-
226
- ### Patch Changes
227
-
228
- - Updated dependencies [b1c3b44]
229
- - @sproutsocial/seeds-react-theme@3.1.1
230
- - @sproutsocial/seeds-react-box@1.1.5
231
- - @sproutsocial/seeds-react-label@1.0.4
232
- - @sproutsocial/seeds-react-visually-hidden@1.0.5
233
-
234
- ## 1.0.3
235
-
236
- ### Patch Changes
237
-
238
- - Updated dependencies [47580c4]
239
- - @sproutsocial/seeds-react-theme@3.1.0
240
- - @sproutsocial/seeds-react-box@1.1.4
241
- - @sproutsocial/seeds-react-label@1.0.3
242
- - @sproutsocial/seeds-react-visually-hidden@1.0.4
243
-
244
- ## 1.0.2
245
-
246
- ### Patch Changes
247
-
248
- - Updated dependencies [22e1111]
249
- - @sproutsocial/seeds-react-text@1.3.2
250
- - @sproutsocial/seeds-react-theme@3.0.1
251
- - @sproutsocial/seeds-react-box@1.1.3
252
- - @sproutsocial/seeds-react-label@1.0.2
253
- - @sproutsocial/seeds-react-visually-hidden@1.0.3
254
-
255
- ## 1.0.1
256
-
257
- ### Patch Changes
258
-
259
- - 9fd8bac: Update dependencies to use semantic package version instead of wildcards
260
- - Updated dependencies [9fd8bac]
261
- - @sproutsocial/seeds-react-visually-hidden@1.0.2
262
- - @sproutsocial/seeds-react-system-props@3.0.2
263
- - @sproutsocial/seeds-react-label@1.0.1
264
- - @sproutsocial/seeds-react-theme@2.2.1
265
- - @sproutsocial/seeds-react-text@1.3.1
266
- - @sproutsocial/seeds-react-box@1.1.2
267
-
268
- ## 1.0.0
269
-
270
- ### Major Changes
271
-
272
- - 8ca97dd: Migrated FormField, Fieldset, and Label to their own seeds-react component
273
-
274
- ### Patch Changes
275
-
276
- - Updated dependencies [8ca97dd]
277
- - @sproutsocial/seeds-react-label@1.0.0
package/jest.config.js DELETED
@@ -1,9 +0,0 @@
1
- const baseConfig = require("@sproutsocial/seeds-testing");
2
-
3
- /** * @type {import('jest').Config} */
4
- const config = {
5
- ...baseConfig,
6
- displayName: "seeds-react-form-field",
7
- };
8
-
9
- module.exports = config;
@@ -1,126 +0,0 @@
1
- import React from "react";
2
- import type { Meta, StoryObj } from "@storybook/react";
3
- import { Box } from "@sproutsocial/seeds-react-box";
4
- import { Input } from "@sproutsocial/seeds-react-input";
5
- // import { Select } from "@sproutsocial/seeds-react-select";
6
- // import { Textarea } from "@sproutsocial/seeds-react-textarea";
7
- import FormField from "./FormField";
8
-
9
- interface FormFieldStoryArgs extends React.ComponentProps<typeof FormField> {
10
- value: string;
11
- }
12
-
13
- type Story = StoryObj<FormFieldStoryArgs>;
14
-
15
- const meta: Meta<FormFieldStoryArgs> = {
16
- title: "Components/Form Elements/FormField",
17
- component: FormField,
18
- args: {
19
- value: "",
20
- mb: 100,
21
- isInvalid: false,
22
- required: false,
23
- helperText: "This is a line of helper text",
24
- error: "",
25
- },
26
- argTypes: {
27
- helperText: {
28
- control: "text",
29
- description: "Text acting as a description blurb below the main label",
30
- },
31
- error: {
32
- control: "text",
33
- description: "Text describing any error with the field's content",
34
- },
35
- isInvalid: {
36
- control: "boolean",
37
- description: "Whether the current contents of the field are invalid",
38
- },
39
- value: {
40
- control: "text",
41
- description: "Input value",
42
- },
43
- },
44
- };
45
- export default meta;
46
-
47
- export const Default: Story = {
48
- render: (args) => (
49
- <Box width="443px" margin="0 auto">
50
- <FormField
51
- label="Form label"
52
- helperText={args.helperText}
53
- required={args.required}
54
- error={args.error}
55
- isInvalid={args.isInvalid}
56
- >
57
- {(props) => <Input {...props} name="title" value={args.value} />}
58
- </FormField>
59
- {/* TODO: COME BACK AND UNCOMMENT WHEN SELECT AND TEXTAREA ARE MIGRATED OVER */}
60
- {/* <FormField
61
- id="descriptionIdThatIWantedToPassIn"
62
- label="Description"
63
- mb={args.mb}
64
- required={args.required}
65
- >
66
- {(props) => (
67
- <Textarea {...props} name="description" value={args.value} />
68
- )}
69
- </FormField> */}
70
- {/* <FormField label="Reason" required={args.required}>
71
- {(props) => (
72
- <Select {...props} name="reason">
73
- <option value="">Select a reason</option>
74
- <option value="something">Something goes here</option>
75
- </Select>
76
- )}
77
- </FormField> */}
78
- </Box>
79
- ),
80
- };
81
-
82
- export const Error: Story = {
83
- args: {
84
- isInvalid: true,
85
- error: "There is an error associated with this input",
86
- },
87
- render: (args) => (
88
- <Box width="443px" margin="0 auto">
89
- <FormField
90
- label="Title"
91
- helperText="This is a line of helper text"
92
- error={args.error}
93
- isInvalid={args.isInvalid}
94
- required={args.required}
95
- >
96
- {(props) => <Input {...props} name="title" value={args.value} />}
97
- </FormField>
98
- {/* TODO: COME BACK AND UNCOMMENT WHEN SELECT AND TEXTAREA ARE MIGRATED OVER */}
99
- {/* <FormField
100
- id="descriptionIdThatIWantedToPassIn"
101
- label="Description"
102
- isInvalid={args.isInvalid}
103
- error="There is an error associated with this textarea"
104
- mb={args.mb}
105
- required={args.required}
106
- >
107
- {(props) => (
108
- <Textarea {...props} name="description" value={args.value} />
109
- )}
110
- </FormField> */}
111
- {/* <FormField
112
- label="Reason"
113
- error="There is an error associated with this select"
114
- isInvalid={args.isInvalid}
115
- required={args.required}
116
- >
117
- {(props) => (
118
- <Select {...props} name="reason">
119
- <option value="">Select a reason</option>
120
- <option value="something">Something goes here</option>
121
- </Select>
122
- )}
123
- </FormField> */}
124
- </Box>
125
- ),
126
- };
package/src/FormField.tsx DELETED
@@ -1,94 +0,0 @@
1
- import React, { useMemo, useState } from "react";
2
- import { useTextContent } from "@sproutsocial/seeds-react-hooks";
3
- import Box from "@sproutsocial/seeds-react-box";
4
- import Label from "@sproutsocial/seeds-react-label";
5
- import Text from "@sproutsocial/seeds-react-text";
6
- import { VisuallyHidden } from "@sproutsocial/seeds-react-visually-hidden";
7
- import type { TypeFormFieldProps } from "./FormFieldTypes";
8
-
9
- let idCounter = 0;
10
-
11
- const FormField = ({
12
- children,
13
- error,
14
- helperText,
15
- id: identifier,
16
- isInvalid = false,
17
- label,
18
- mb = 400,
19
- qa,
20
- isLabelHidden = false,
21
- required,
22
- ...rest
23
- }: TypeFormFieldProps) => {
24
- const [id] = useState(identifier || `FormField-${idCounter++}`);
25
- const errorId = `Error-${id}`;
26
- const helperTextId = `HelperText-${id}`;
27
- const containerText = useTextContent("");
28
- const errorContainerText = useTextContent("");
29
-
30
- const ariaDescribedby = useMemo(() => {
31
- const ids = [
32
- helperText && helperTextId,
33
- isInvalid && error && errorId,
34
- ].filter(Boolean);
35
- return ids.length > 0 ? ids.join(" ") : undefined;
36
- }, [helperText, helperTextId, isInvalid, error, errorId]);
37
-
38
- return (
39
- <Box
40
- {...rest}
41
- {...qa}
42
- mb={mb}
43
- data-qa-formfield={
44
- (qa && qa["data-qa-formfield"]) || id || containerText.current
45
- }
46
- data-qa-formfield-isinvalid={isInvalid === true}
47
- >
48
- {isLabelHidden ? (
49
- <VisuallyHidden data-testid="visually-hidden">
50
- <Label htmlFor={id} required={required}>
51
- {label}
52
- </Label>
53
- </VisuallyHidden>
54
- ) : (
55
- <Label mb={helperText ? 100 : 300} htmlFor={id} required={required}>
56
- {label}
57
- </Label>
58
- )}
59
- {helperText && (
60
- <Text
61
- as="p"
62
- fontSize={200}
63
- mb={300}
64
- color="text.subtext"
65
- id={helperTextId}
66
- >
67
- {helperText}
68
- </Text>
69
- )}
70
- {children({
71
- id,
72
- isInvalid,
73
- ariaDescribedby,
74
- ...(required !== undefined && { required }),
75
- })}
76
- {isInvalid && error && (
77
- <Text
78
- as="div"
79
- fontSize={200}
80
- color="text.error"
81
- mt={300}
82
- id={errorId}
83
- data-qa-formfield-error={
84
- (qa && qa["data-qa-formfield-error"]) || errorContainerText.current
85
- }
86
- >
87
- {error}
88
- </Text>
89
- )}
90
- </Box>
91
- );
92
- };
93
-
94
- export default FormField;
@@ -1,34 +0,0 @@
1
- import * as React from "react";
2
- import type { TypeBoxProps } from "@sproutsocial/seeds-react-box";
3
-
4
- export interface TypeFormFieldProps extends Omit<TypeBoxProps, "children"> {
5
- /** A function that receives props that need to be spread onto the child element */
6
- children: (options: {
7
- id: string;
8
- isInvalid: boolean;
9
- ariaDescribedby?: string;
10
- required?: boolean;
11
- }) => React.ReactNode;
12
-
13
- /** Text describing any error with the field's content */
14
- error?: React.ReactNode;
15
-
16
- /** Text acting as a description blurb below the main label **/
17
- helperText?: React.ReactNode;
18
-
19
- /** ID of the form element (will be auto-generated if not provided) */
20
- id?: string;
21
-
22
- /** Whether the current contents of the field are invalid */
23
- isInvalid?: boolean;
24
-
25
- /** Label text to display above the form field */
26
- label: React.ReactNode;
27
- qa?: Record<string, any>;
28
-
29
- /** Whether the label text should be visually hidden */
30
- isLabelHidden?: boolean;
31
-
32
- /** Whether the form element is required */
33
- required?: boolean;
34
- }
@@ -1,115 +0,0 @@
1
- import React from "react";
2
- import { render, screen } from "@sproutsocial/seeds-react-testing-library";
3
- import { Input } from "@sproutsocial/seeds-react-input";
4
- import FormField from "../FormField";
5
-
6
- describe("FormField", () => {
7
- const label = "Label";
8
- const inputVal = "value";
9
- it("passes the autogenerated id down", () => {
10
- const errorText = "There is an error associated with this input";
11
- render(
12
- <FormField label={label} error={errorText} isInvalid={true}>
13
- {(props) => (
14
- <Input
15
- {...props}
16
- placeholder="Enter a title"
17
- name="title"
18
- value={inputVal}
19
- />
20
- )}
21
- </FormField>
22
- );
23
- const input = screen.getByLabelText(label);
24
- expect(input).toHaveValue(inputVal);
25
- // Verify aria-describedby is set to error ID
26
- const describedBy = input.getAttribute("aria-describedby");
27
- expect(describedBy).toContain("Error-");
28
- expect(screen.getByText(errorText)).toHaveAttribute("id", describedBy);
29
- });
30
- it("passes the id passed in down to the input field", () => {
31
- const manualId = "manualId";
32
- render(
33
- <FormField
34
- id={manualId}
35
- label={label}
36
- error="There is an error associated with this input"
37
- isInvalid={true}
38
- >
39
- {(props) => (
40
- <Input {...props} placeholder="Enter a title" name="title" value="" />
41
- )}
42
- </FormField>
43
- );
44
- expect(screen.getByLabelText(label)).toHaveAttribute("id", manualId);
45
- });
46
- it("is accessible", async () => {
47
- const { runA11yCheck } = render(
48
- <FormField
49
- label="Title"
50
- error="There is an error associated with this input"
51
- isInvalid={true}
52
- >
53
- {(props) => (
54
- <Input {...props} placeholder="Enter a title" name="title" value="" />
55
- )}
56
- </FormField>
57
- );
58
- await runA11yCheck();
59
- });
60
- it("should visually hide label", () => {
61
- const manualId = "manualId";
62
- render(
63
- <FormField id={manualId} label={label} isLabelHidden={true}>
64
- {(props) => (
65
- <Input {...props} placeholder="Enter a title" name="title" value="" />
66
- )}
67
- </FormField>
68
- );
69
- expect(screen.getByTestId("visually-hidden")).toBeInTheDocument();
70
- // Verify aria-describedby is not set when no helper text or error
71
- expect(screen.getByLabelText(label)).not.toHaveAttribute(
72
- "aria-describedby"
73
- );
74
- });
75
- it("should be required when required is true", () => {
76
- render(
77
- <FormField label={label} required>
78
- {(props) => <Input {...props} name="title" />}
79
- </FormField>
80
- );
81
- expect(screen.getByLabelText(`${label}*`)).toBeRequired();
82
- });
83
- it("should set aria-describedby to helper text ID when helper text is provided", () => {
84
- const helperText = "This is helper text";
85
- render(
86
- <FormField label={label} helperText={helperText}>
87
- {(props) => <Input {...props} name="title" />}
88
- </FormField>
89
- );
90
- const input = screen.getByLabelText(label);
91
- const describedBy = input.getAttribute("aria-describedby");
92
- expect(describedBy).toContain("HelperText-");
93
- expect(screen.getByText(helperText)).toHaveAttribute("id", describedBy);
94
- });
95
- it("should set aria-describedby to both helper text and error IDs when both are provided", () => {
96
- const helperText = "This is helper text";
97
- const errorText = "This is an error";
98
- render(
99
- <FormField
100
- label={label}
101
- helperText={helperText}
102
- error={errorText}
103
- isInvalid={true}
104
- >
105
- {(props) => <Input {...props} name="title" />}
106
- </FormField>
107
- );
108
- const input = screen.getByLabelText(label);
109
- const describedBy = input.getAttribute("aria-describedby");
110
- const ids = describedBy!.split(" ");
111
- expect(ids).toHaveLength(2);
112
- expect(ids[0]).toContain("HelperText-");
113
- expect(ids[1]).toContain("Error-");
114
- });
115
- });