@sproutsocial/seeds-react-form-field 1.1.20 → 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/dist/esm/index.js +179 -27
- package/dist/esm/index.js.map +1 -1
- package/dist/form-field.css +21 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +180 -28
- package/dist/index.js.map +1 -1
- package/package.json +15 -4
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -4
- package/.turbo/turbo-build.log +0 -21
- package/CHANGELOG.md +0 -288
- package/jest.config.js +0 -9
- package/src/FormField.stories.tsx +0 -126
- package/src/FormField.tsx +0 -94
- package/src/FormFieldTypes.ts +0 -34
- package/src/__tests__/FormField.test.tsx +0 -115
- package/src/__tests__/FormField.typetest.tsx +0 -84
- package/src/index.ts +0 -5
- package/src/styled.d.ts +0 -7
- package/tsconfig.json +0 -15
- package/tsup.config.ts +0 -12
package/CHANGELOG.md
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
# @sproutsocial/seeds-react-form-field
|
|
2
|
-
|
|
3
|
-
## 1.1.20
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [6611f6a]
|
|
8
|
-
- @sproutsocial/seeds-react-system-props@3.1.2
|
|
9
|
-
- @sproutsocial/seeds-react-box@1.1.24
|
|
10
|
-
- @sproutsocial/seeds-react-label@1.0.26
|
|
11
|
-
- @sproutsocial/seeds-react-text@1.5.1
|
|
12
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.25
|
|
13
|
-
|
|
14
|
-
## 1.1.19
|
|
15
|
-
|
|
16
|
-
### Patch Changes
|
|
17
|
-
|
|
18
|
-
- Updated dependencies [85f9728]
|
|
19
|
-
- Updated dependencies [fa7d859]
|
|
20
|
-
- @sproutsocial/seeds-react-theme@4.2.0
|
|
21
|
-
- @sproutsocial/seeds-react-box@1.1.23
|
|
22
|
-
- @sproutsocial/seeds-react-label@1.0.25
|
|
23
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.24
|
|
24
|
-
|
|
25
|
-
## 1.1.18
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- Updated dependencies [65b5879]
|
|
30
|
-
- @sproutsocial/seeds-react-text@1.5.0
|
|
31
|
-
- @sproutsocial/seeds-react-label@1.0.24
|
|
32
|
-
|
|
33
|
-
## 1.1.17
|
|
34
|
-
|
|
35
|
-
### Patch Changes
|
|
36
|
-
|
|
37
|
-
- Updated dependencies [a13a571]
|
|
38
|
-
- @sproutsocial/seeds-react-theme@4.1.1
|
|
39
|
-
- @sproutsocial/seeds-react-box@1.1.22
|
|
40
|
-
- @sproutsocial/seeds-react-label@1.0.23
|
|
41
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.23
|
|
42
|
-
|
|
43
|
-
## 1.1.16
|
|
44
|
-
|
|
45
|
-
### Patch Changes
|
|
46
|
-
|
|
47
|
-
- Updated dependencies [edc1819]
|
|
48
|
-
- @sproutsocial/seeds-react-text@1.4.3
|
|
49
|
-
- @sproutsocial/seeds-react-label@1.0.22
|
|
50
|
-
|
|
51
|
-
## 1.1.15
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- Updated dependencies [5892f44]
|
|
56
|
-
- @sproutsocial/seeds-react-system-props@3.1.1
|
|
57
|
-
- @sproutsocial/seeds-react-box@1.1.21
|
|
58
|
-
- @sproutsocial/seeds-react-label@1.0.21
|
|
59
|
-
- @sproutsocial/seeds-react-text@1.4.2
|
|
60
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.22
|
|
61
|
-
|
|
62
|
-
## 1.1.14
|
|
63
|
-
|
|
64
|
-
### Patch Changes
|
|
65
|
-
|
|
66
|
-
- Updated dependencies [5114a32]
|
|
67
|
-
- @sproutsocial/seeds-react-theme@4.1.0
|
|
68
|
-
- @sproutsocial/seeds-react-box@1.1.20
|
|
69
|
-
- @sproutsocial/seeds-react-label@1.0.20
|
|
70
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.21
|
|
71
|
-
|
|
72
|
-
## 1.1.13
|
|
73
|
-
|
|
74
|
-
### Patch Changes
|
|
75
|
-
|
|
76
|
-
- Updated dependencies [132ef9d]
|
|
77
|
-
- Updated dependencies [132ef9d]
|
|
78
|
-
- @sproutsocial/seeds-react-theme@4.0.0
|
|
79
|
-
- @sproutsocial/seeds-react-system-props@3.1.0
|
|
80
|
-
- @sproutsocial/seeds-react-box@1.1.19
|
|
81
|
-
- @sproutsocial/seeds-react-label@1.0.19
|
|
82
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.20
|
|
83
|
-
- @sproutsocial/seeds-react-text@1.4.1
|
|
84
|
-
|
|
85
|
-
## 1.1.12
|
|
86
|
-
|
|
87
|
-
### Patch Changes
|
|
88
|
-
|
|
89
|
-
- Updated dependencies [47c62b3]
|
|
90
|
-
- @sproutsocial/seeds-react-theme@3.7.1
|
|
91
|
-
- @sproutsocial/seeds-react-box@1.1.18
|
|
92
|
-
- @sproutsocial/seeds-react-label@1.0.18
|
|
93
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.19
|
|
94
|
-
|
|
95
|
-
## 1.1.11
|
|
96
|
-
|
|
97
|
-
### Patch Changes
|
|
98
|
-
|
|
99
|
-
- Updated dependencies [06da9c2]
|
|
100
|
-
- @sproutsocial/seeds-react-theme@3.7.0
|
|
101
|
-
- @sproutsocial/seeds-react-box@1.1.17
|
|
102
|
-
- @sproutsocial/seeds-react-label@1.0.17
|
|
103
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.18
|
|
104
|
-
|
|
105
|
-
## 1.1.10
|
|
106
|
-
|
|
107
|
-
### Patch Changes
|
|
108
|
-
|
|
109
|
-
- Updated dependencies [4ba8720]
|
|
110
|
-
- @sproutsocial/seeds-react-theme@3.6.2
|
|
111
|
-
- @sproutsocial/seeds-react-box@1.1.16
|
|
112
|
-
- @sproutsocial/seeds-react-label@1.0.16
|
|
113
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.17
|
|
114
|
-
|
|
115
|
-
## 1.1.9
|
|
116
|
-
|
|
117
|
-
### Patch Changes
|
|
118
|
-
|
|
119
|
-
- Updated dependencies [1f9a473]
|
|
120
|
-
- @sproutsocial/seeds-react-theme@3.6.1
|
|
121
|
-
- @sproutsocial/seeds-react-box@1.1.15
|
|
122
|
-
- @sproutsocial/seeds-react-label@1.0.15
|
|
123
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.16
|
|
124
|
-
|
|
125
|
-
## 1.1.8
|
|
126
|
-
|
|
127
|
-
### Patch Changes
|
|
128
|
-
|
|
129
|
-
- Updated dependencies [17d4f12]
|
|
130
|
-
- @sproutsocial/seeds-react-theme@3.6.0
|
|
131
|
-
- @sproutsocial/seeds-react-box@1.1.14
|
|
132
|
-
- @sproutsocial/seeds-react-label@1.0.14
|
|
133
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.15
|
|
134
|
-
|
|
135
|
-
## 1.1.7
|
|
136
|
-
|
|
137
|
-
### Patch Changes
|
|
138
|
-
|
|
139
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.14
|
|
140
|
-
|
|
141
|
-
## 1.1.6
|
|
142
|
-
|
|
143
|
-
### Patch Changes
|
|
144
|
-
|
|
145
|
-
- Updated dependencies [118e300]
|
|
146
|
-
- @sproutsocial/seeds-react-theme@3.5.1
|
|
147
|
-
- @sproutsocial/seeds-react-box@1.1.13
|
|
148
|
-
- @sproutsocial/seeds-react-label@1.0.13
|
|
149
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.13
|
|
150
|
-
|
|
151
|
-
## 1.1.5
|
|
152
|
-
|
|
153
|
-
### Patch Changes
|
|
154
|
-
|
|
155
|
-
- Updated dependencies [db6ce39]
|
|
156
|
-
- Updated dependencies [20bb01b]
|
|
157
|
-
- @sproutsocial/seeds-react-theme@3.5.0
|
|
158
|
-
- @sproutsocial/seeds-react-box@1.1.12
|
|
159
|
-
- @sproutsocial/seeds-react-label@1.0.12
|
|
160
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.12
|
|
161
|
-
|
|
162
|
-
## 1.1.4
|
|
163
|
-
|
|
164
|
-
### Patch Changes
|
|
165
|
-
|
|
166
|
-
- Updated dependencies [29ced53]
|
|
167
|
-
- @sproutsocial/seeds-react-text@1.4.0
|
|
168
|
-
- @sproutsocial/seeds-react-label@1.0.11
|
|
169
|
-
|
|
170
|
-
## 1.1.3
|
|
171
|
-
|
|
172
|
-
### Patch Changes
|
|
173
|
-
|
|
174
|
-
- Updated dependencies [7716e16]
|
|
175
|
-
- @sproutsocial/seeds-react-theme@3.4.0
|
|
176
|
-
- @sproutsocial/seeds-react-box@1.1.11
|
|
177
|
-
- @sproutsocial/seeds-react-label@1.0.10
|
|
178
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.11
|
|
179
|
-
|
|
180
|
-
## 1.1.2
|
|
181
|
-
|
|
182
|
-
### Patch Changes
|
|
183
|
-
|
|
184
|
-
- @sproutsocial/seeds-react-theme@3.3.2
|
|
185
|
-
- @sproutsocial/seeds-react-box@1.1.10
|
|
186
|
-
- @sproutsocial/seeds-react-label@1.0.9
|
|
187
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.10
|
|
188
|
-
|
|
189
|
-
## 1.1.1
|
|
190
|
-
|
|
191
|
-
### Patch Changes
|
|
192
|
-
|
|
193
|
-
- @sproutsocial/seeds-react-theme@3.3.1
|
|
194
|
-
- @sproutsocial/seeds-react-box@1.1.9
|
|
195
|
-
- @sproutsocial/seeds-react-label@1.0.8
|
|
196
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.9
|
|
197
|
-
|
|
198
|
-
## 1.1.0
|
|
199
|
-
|
|
200
|
-
### Minor Changes
|
|
201
|
-
|
|
202
|
-
- 81584cb: Add helper text to input element's `aria-describedby`
|
|
203
|
-
Bug fix: only add `aria-describedby` if error or helper text exists
|
|
204
|
-
|
|
205
|
-
## 1.0.7
|
|
206
|
-
|
|
207
|
-
### Patch Changes
|
|
208
|
-
|
|
209
|
-
- Updated dependencies [750d1ea]
|
|
210
|
-
- @sproutsocial/seeds-react-theme@3.3.0
|
|
211
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.8
|
|
212
|
-
- @sproutsocial/seeds-react-box@1.1.8
|
|
213
|
-
- @sproutsocial/seeds-react-label@1.0.7
|
|
214
|
-
|
|
215
|
-
## 1.0.6
|
|
216
|
-
|
|
217
|
-
### Patch Changes
|
|
218
|
-
|
|
219
|
-
- Updated dependencies [fa7579a]
|
|
220
|
-
- @sproutsocial/seeds-react-theme@3.2.1
|
|
221
|
-
- @sproutsocial/seeds-react-box@1.1.7
|
|
222
|
-
- @sproutsocial/seeds-react-label@1.0.6
|
|
223
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.7
|
|
224
|
-
|
|
225
|
-
## 1.0.5
|
|
226
|
-
|
|
227
|
-
### Patch Changes
|
|
228
|
-
|
|
229
|
-
- Updated dependencies [8f6ba8d]
|
|
230
|
-
- @sproutsocial/seeds-react-theme@3.2.0
|
|
231
|
-
- @sproutsocial/seeds-react-box@1.1.6
|
|
232
|
-
- @sproutsocial/seeds-react-label@1.0.5
|
|
233
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.6
|
|
234
|
-
|
|
235
|
-
## 1.0.4
|
|
236
|
-
|
|
237
|
-
### Patch Changes
|
|
238
|
-
|
|
239
|
-
- Updated dependencies [b1c3b44]
|
|
240
|
-
- @sproutsocial/seeds-react-theme@3.1.1
|
|
241
|
-
- @sproutsocial/seeds-react-box@1.1.5
|
|
242
|
-
- @sproutsocial/seeds-react-label@1.0.4
|
|
243
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.5
|
|
244
|
-
|
|
245
|
-
## 1.0.3
|
|
246
|
-
|
|
247
|
-
### Patch Changes
|
|
248
|
-
|
|
249
|
-
- Updated dependencies [47580c4]
|
|
250
|
-
- @sproutsocial/seeds-react-theme@3.1.0
|
|
251
|
-
- @sproutsocial/seeds-react-box@1.1.4
|
|
252
|
-
- @sproutsocial/seeds-react-label@1.0.3
|
|
253
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.4
|
|
254
|
-
|
|
255
|
-
## 1.0.2
|
|
256
|
-
|
|
257
|
-
### Patch Changes
|
|
258
|
-
|
|
259
|
-
- Updated dependencies [22e1111]
|
|
260
|
-
- @sproutsocial/seeds-react-text@1.3.2
|
|
261
|
-
- @sproutsocial/seeds-react-theme@3.0.1
|
|
262
|
-
- @sproutsocial/seeds-react-box@1.1.3
|
|
263
|
-
- @sproutsocial/seeds-react-label@1.0.2
|
|
264
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.3
|
|
265
|
-
|
|
266
|
-
## 1.0.1
|
|
267
|
-
|
|
268
|
-
### Patch Changes
|
|
269
|
-
|
|
270
|
-
- 9fd8bac: Update dependencies to use semantic package version instead of wildcards
|
|
271
|
-
- Updated dependencies [9fd8bac]
|
|
272
|
-
- @sproutsocial/seeds-react-visually-hidden@1.0.2
|
|
273
|
-
- @sproutsocial/seeds-react-system-props@3.0.2
|
|
274
|
-
- @sproutsocial/seeds-react-label@1.0.1
|
|
275
|
-
- @sproutsocial/seeds-react-theme@2.2.1
|
|
276
|
-
- @sproutsocial/seeds-react-text@1.3.1
|
|
277
|
-
- @sproutsocial/seeds-react-box@1.1.2
|
|
278
|
-
|
|
279
|
-
## 1.0.0
|
|
280
|
-
|
|
281
|
-
### Major Changes
|
|
282
|
-
|
|
283
|
-
- 8ca97dd: Migrated FormField, Fieldset, and Label to their own seeds-react component
|
|
284
|
-
|
|
285
|
-
### Patch Changes
|
|
286
|
-
|
|
287
|
-
- Updated dependencies [8ca97dd]
|
|
288
|
-
- @sproutsocial/seeds-react-label@1.0.0
|
package/jest.config.js
DELETED
|
@@ -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;
|
package/src/FormFieldTypes.ts
DELETED
|
@@ -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
|
-
});
|