Skip to content

Commit f94dcd3

Browse files
authored
Deprecate components replaced by FormControl (#1888)
* moves InputField to deprecated package * adds jsdoc comments for deprecation * adds changeset * fixes bad autoformatting in changeset * fixes import path in test file * addresses PR feedback * fixes FormGroup import in test * addresses PR feedback * moves tests to depreacted directory * removes docs header image * fixes bad formatting in changelog markdown
1 parent 61404ae commit f94dcd3

File tree

19 files changed

+148
-33
lines changed

19 files changed

+148
-33
lines changed

.changeset/olive-bears-act.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
'@primer/react': major
3+
---
4+
5+
The `FormControl` component will be used to deprecate the `FormGroup`, `InputField`, and `ChoiceInputField` components. It has the ability to render contextual content with your inputs: labels, validation statuses, captions. It also handles the ARIA attributes that make the form controls accessible to assistive technology.
6+
7+
<table>
8+
<tr>
9+
<th> Before </th> <th> After </th>
10+
</tr>
11+
<tr>
12+
<td valign="top">
13+
14+
```jsx
15+
import {FormControl, Checkbox, TextInput} from "@primer/react"
16+
17+
18+
<FormGroup>
19+
<FormGroup.Label htmlFor="example-text">Example text</FormGroup.Label>
20+
<TextInput id="example-text" />
21+
</FormGroup>
22+
23+
// OR
24+
25+
<InputField>
26+
<InputField.Label>Example text</InputField.Label>
27+
<TextInput />
28+
</InputField>
29+
30+
// OR
31+
32+
<ChoiceInputField>
33+
<ChoiceInputField.Label>Example text</ChoiceInputField.Label>
34+
<Checkbox />
35+
</ChoiceInputField>
36+
37+
```
38+
39+
</td>
40+
<td valign="top">
41+
42+
```jsx
43+
import {FormGroup, TextInput} from "@primer/react"
44+
45+
<FormControl>
46+
<FormControl.Label>Example text</FormControl.Label>
47+
<TextInput />
48+
</FormControl>
49+
50+
// OR
51+
52+
<FormControl>
53+
<FormControl.Label>Example text</FormControl.Label>
54+
<Checkbox />
55+
</FormControl>
56+
57+
```
58+
59+
</td>
60+
</tr>
61+
<tr>
62+
<td valign="top">
63+
64+
```jsx
65+
import {InputField} from '@primer/react'
66+
<InputField>
67+
<InputField.Label>Example text</InputField.Label>
68+
<TextInput />
69+
</InputField>
70+
```
71+
72+
</td>
73+
<td valign="top">
74+
75+
```jsx
76+
import {FormControl} from '@primer/react'
77+
<FormControl>
78+
<FormControl.Label>Example Text</FormControl.Label>
79+
<TextInput />
80+
</FormControl>
81+
```
82+
83+
</td>
84+
</tr>
85+
</table>
86+
<table style="display: table">
87+
<tr><th>Migration steps to FormControl</th></tr>
88+
<tr>
89+
<td>
90+
91+
<strong>Upgrade to the new</strong> `FormControl` component by referring to the [examples in our documentation](https://primer.style/react/FormControl).
92+
93+
or
94+
95+
<strong>Continue using the deprecated</strong> `FormGroup`, `ChoiceInputField` or `InputField` :
96+
97+
```js
98+
import {FormGroup, ChoiceInputField, InputField} from '@primer/react/deprecated' // change your import statements
99+
```
100+
101+
Codemods:
102+
103+
- InputField codemod: https://github.com/primer/react-migrate/blob/main/src/use-deprecated-inputfield.js
104+
- ChoiceInputField https://github.com/primer/react-migrate/blob/main/src/use-deprecated-choiceinputfield.js
105+
- FormGroup codemod: https://github.com/primer/react-migrate/blob/main/src/use-deprecated-formgroup.js
106+
107+
</td>
108+
</tr>
109+
</table>

docs/content/FormGroup.md renamed to docs/content/deprecated/FormGroup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Use [FormControl](/FormControl) instead.
1212

1313
## Default example
1414

15-
```jsx live
15+
```jsx live deprecated
1616
<>
1717
<FormGroup>
1818
<FormGroup.Label htmlFor="example-text">Example text</FormGroup.Label>

docs/content/InputField.mdx renamed to docs/content/deprecated/InputField.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source: https://github.com/primer/react/blob/main/src/InputField/InputField.tsx
77
storybook: '/react/storybook?path=/story/forms-inputfield--text-input-field'
88
---
99

10-
import {InputField, TextInputWithTokens, Autocomplete, Select} from '@primer/react'
10+
import {TextInputWithTokens, Autocomplete, Select} from '@primer/react'
1111

1212
## Deprecation
1313

@@ -17,7 +17,7 @@ Use [FormControl](/FormControl) instead.
1717

1818
### Basic
1919

20-
```jsx live
20+
```jsx live deprecated
2121
<InputField>
2222
<InputField.Label>Name</InputField.Label>
2323
<TextInput />
@@ -26,7 +26,7 @@ Use [FormControl](/FormControl) instead.
2626

2727
### Required
2828

29-
```jsx live
29+
```jsx live deprecated
3030
<InputField required>
3131
<InputField.Label>Name</InputField.Label>
3232
<TextInput />
@@ -35,7 +35,7 @@ Use [FormControl](/FormControl) instead.
3535

3636
### Disabled
3737

38-
```jsx live
38+
```jsx live deprecated
3939
<InputField disabled>
4040
<InputField.Label>Name</InputField.Label>
4141
<TextInput />
@@ -44,7 +44,7 @@ Use [FormControl](/FormControl) instead.
4444

4545
### Using different input components
4646

47-
```javascript live noinline
47+
```javascript live noinline deprecated
4848
const TextInputWithTokensExample = () => {
4949
const [tokens, setTokens] = React.useState([
5050
{text: 'zero', id: 0},
@@ -115,7 +115,7 @@ Every input must have a corresponding label to be accessible to assistive techno
115115

116116
</Note>
117117

118-
```jsx live
118+
```jsx live deprecated
119119
<InputField>
120120
<InputField.Label visuallyHidden>Name</InputField.Label>
121121
<TextInput />
@@ -124,7 +124,7 @@ Every input must have a corresponding label to be accessible to assistive techno
124124

125125
### With a caption
126126

127-
```jsx live
127+
```jsx live deprecated
128128
<InputField>
129129
<InputField.Label>Name</InputField.Label>
130130
<TextInput />
@@ -134,7 +134,7 @@ Every input must have a corresponding label to be accessible to assistive techno
134134

135135
### With validation
136136

137-
```javascript live noinline
137+
```javascript live noinline deprecated
138138
const ValidationExample = () => {
139139
const [value, setValue] = React.useState('mona lisa')
140140
const [validationResult, setValidationResult] = React.useState()

docs/src/@primer/gatsby-theme-doctocat/nav.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@
164164
- title: Flex
165165
url: /deprecated/Flex
166166
- title: FormGroup
167-
url: /FormGroup
167+
url: /deprecated/FormGroup
168168
- title: Grid
169169
url: /deprecated/Grid
170+
- title: InputField
171+
url: /deprecated/InputField
170172
- title: Position
171173
url: /deprecated/Position
172174
- title: SelectMenu

src/ChoiceInputField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react'
22
import {Box, Checkbox, Radio, useSSRSafeId} from '.'
33
import {get} from './constants'
4-
import {Slots} from './InputField/slots'
4+
import {Slots} from './deprecated/InputField/slots'
55
import ChoiceInputLeadingVisual from './_ChoiceInputLeadingVisual'
6-
import InputField, {Props as InputFieldProps} from './InputField/InputField'
6+
import InputField, {Props as InputFieldProps} from './deprecated/InputField/InputField'
77
import {FormValidationStatus} from './utils/types/FormValidationStatus'
8-
import InputFieldCaption from './InputField/_InputFieldCaption'
8+
import InputFieldCaption from './deprecated/InputField/_InputFieldCaption'
99

1010
export interface Props extends Pick<InputFieldProps, 'disabled' | 'id'> {
1111
/**

src/_ChoiceInputLeadingVisual.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import {Slot} from './InputField/slots'
2+
import {Slot} from './deprecated/InputField/slots'
33

44
const ChoiceInputLeadingVisual: React.FC = ({children}) => <Slot name="LeadingVisual">{children}</Slot>
55

src/__tests__/FormGroup.types.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import FormGroup from '../FormGroup'
2+
import FormGroup from '../deprecated/FormGroup'
33

44
export function shouldAcceptCallWithNoProps() {
55
return <FormGroup />

src/__tests__/FormGroup.test.tsx renamed to src/__tests__/deprecated/FormGroup.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
2-
import {FormGroup} from '..'
3-
import {behavesAsComponent, checkExports} from '../utils/testing'
2+
import FormGroup from '../../deprecated/FormGroup'
3+
import {behavesAsComponent, checkExports} from '../../utils/testing'
44
import {render as HTMLRender, cleanup} from '@testing-library/react'
55
import {axe, toHaveNoViolations} from 'jest-axe'
66
import 'babel-polyfill'
@@ -9,7 +9,7 @@ expect.extend(toHaveNoViolations)
99
describe('FormGroup', () => {
1010
behavesAsComponent({Component: FormGroup})
1111

12-
checkExports('FormGroup', {
12+
checkExports('deprecated/FormGroup', {
1313
default: FormGroup
1414
})
1515

src/__tests__/InputField.test.tsx renamed to src/__tests__/deprecated/InputField.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react'
22
import {render, cleanup} from '@testing-library/react'
33
import {axe, toHaveNoViolations} from 'jest-axe'
44
import 'babel-polyfill'
5-
import {Autocomplete, InputField, SSRProvider, TextInput, TextInputWithTokens} from '..'
5+
import {Autocomplete, SSRProvider, TextInput, TextInputWithTokens} from '../../'
6+
import InputField from '../../deprecated/InputField'
67
expect.extend(toHaveNoViolations)
78

89
const TEXTINPUTFIELD_LABEL_TEXT = 'Name'
File renamed without changes.

0 commit comments

Comments
 (0)