Skip to content

Deprecate components replaced by FormControl #1888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .changeset/olive-bears-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
'@primer/react': major
---

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.

<table>
<tr>
<th> Before </th> <th> After </th>
</tr>
<tr>
<td valign="top">

```jsx
import {FormControl, Checkbox, TextInput} from "@primer/react"


<FormGroup>
<FormGroup.Label htmlFor="example-text">Example text</FormGroup.Label>
<TextInput id="example-text" />
</FormGroup>

// OR

<InputField>
<InputField.Label>Example text</InputField.Label>
<TextInput />
</InputField>

// OR

<ChoiceInputField>
<ChoiceInputField.Label>Example text</ChoiceInputField.Label>
<Checkbox />
</ChoiceInputField>

```

</td>
<td valign="top">

```jsx
import {FormGroup, TextInput} from "@primer/react"

<FormControl>
<FormControl.Label>Example text</FormControl.Label>
<TextInput />
</FormControl>

// OR

<FormControl>
<FormControl.Label>Example text</FormControl.Label>
<Checkbox />
</FormControl>

```

</td>
</tr>
<tr>
<td valign="top">

```jsx
import {InputField} from '@primer/react'
<InputField>
<InputField.Label>Example text</InputField.Label>
<TextInput />
</InputField>
```

</td>
<td valign="top">

```jsx
import {FormControl} from '@primer/react'
<FormControl>
<FormControl.Label>Example Text</FormControl.Label>
<TextInput />
</FormControl>
```

</td>
</tr>
</table>
<table style="display: table">
<tr><th>Migration steps to FormControl</th></tr>
<tr>
<td>

<strong>Upgrade to the new</strong> `FormControl` component by referring to the [examples in our documentation](https://primer.style/react/FormControl).

or

<strong>Continue using the deprecated</strong> `FormGroup`, `ChoiceInputField` or `InputField` :

```js
import {FormGroup, ChoiceInputField, InputField} from '@primer/react/deprecated' // change your import statements
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TODO for later.. but @siddharthkp has done the codemod for these, which we can mention here too.


Codemods:

- InputField codemod: https://github.com/primer/react-migrate/blob/main/src/use-deprecated-inputfield.js
- ChoiceInputField https://github.com/primer/react-migrate/blob/main/src/use-deprecated-choiceinputfield.js
- FormGroup codemod: https://github.com/primer/react-migrate/blob/main/src/use-deprecated-formgroup.js

</td>
</tr>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Use [FormControl](/FormControl) instead.

## Default example

```jsx live
```jsx live deprecated
<>
<FormGroup>
<FormGroup.Label htmlFor="example-text">Example text</FormGroup.Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source: https://github.com/primer/react/blob/main/src/InputField/InputField.tsx
storybook: '/react/storybook?path=/story/forms-inputfield--text-input-field'
---

import {InputField, TextInputWithTokens, Autocomplete, Select} from '@primer/react'
import {TextInputWithTokens, Autocomplete, Select} from '@primer/react'

## Deprecation

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

### Basic

```jsx live
```jsx live deprecated
<InputField>
<InputField.Label>Name</InputField.Label>
<TextInput />
Expand All @@ -26,7 +26,7 @@ Use [FormControl](/FormControl) instead.

### Required

```jsx live
```jsx live deprecated
<InputField required>
<InputField.Label>Name</InputField.Label>
<TextInput />
Expand All @@ -35,7 +35,7 @@ Use [FormControl](/FormControl) instead.

### Disabled

```jsx live
```jsx live deprecated
<InputField disabled>
<InputField.Label>Name</InputField.Label>
<TextInput />
Expand All @@ -44,7 +44,7 @@ Use [FormControl](/FormControl) instead.

### Using different input components

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

</Note>

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

### With a caption

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

### With validation

```javascript live noinline
```javascript live noinline deprecated
const ValidationExample = () => {
const [value, setValue] = React.useState('mona lisa')
const [validationResult, setValidationResult] = React.useState()
Expand Down
4 changes: 3 additions & 1 deletion docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@
- title: Flex
url: /deprecated/Flex
- title: FormGroup
url: /FormGroup
url: /deprecated/FormGroup
- title: Grid
url: /deprecated/Grid
- title: InputField
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General feedback about the docs for these deprecated components:

I think you'll need to move the .md files to `docs/content/deprecated as otherwise they will 404 based on the path below 👇

url: /deprecated/InputField
- title: Position
url: /deprecated/Position
- title: SelectMenu
Expand Down
6 changes: 3 additions & 3 deletions src/ChoiceInputField.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import {Box, Checkbox, Radio, useSSRSafeId} from '.'
import {get} from './constants'
import {Slots} from './InputField/slots'
import {Slots} from './deprecated/InputField/slots'
import ChoiceInputLeadingVisual from './_ChoiceInputLeadingVisual'
import InputField, {Props as InputFieldProps} from './InputField/InputField'
import InputField, {Props as InputFieldProps} from './deprecated/InputField/InputField'
import {FormValidationStatus} from './utils/types/FormValidationStatus'
import InputFieldCaption from './InputField/_InputFieldCaption'
import InputFieldCaption from './deprecated/InputField/_InputFieldCaption'

export interface Props extends Pick<InputFieldProps, 'disabled' | 'id'> {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/_ChoiceInputLeadingVisual.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {Slot} from './InputField/slots'
import {Slot} from './deprecated/InputField/slots'

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

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/FormGroup.types.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import FormGroup from '../FormGroup'
import FormGroup from '../deprecated/FormGroup'

export function shouldAcceptCallWithNoProps() {
return <FormGroup />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import {FormGroup} from '..'
import {behavesAsComponent, checkExports} from '../utils/testing'
import FormGroup from '../../deprecated/FormGroup'
import {behavesAsComponent, checkExports} from '../../utils/testing'
import {render as HTMLRender, cleanup} from '@testing-library/react'
import {axe, toHaveNoViolations} from 'jest-axe'
import 'babel-polyfill'
Expand All @@ -9,7 +9,7 @@ expect.extend(toHaveNoViolations)
describe('FormGroup', () => {
behavesAsComponent({Component: FormGroup})

checkExports('FormGroup', {
checkExports('deprecated/FormGroup', {
default: FormGroup
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react'
import {render, cleanup} from '@testing-library/react'
import {axe, toHaveNoViolations} from 'jest-axe'
import 'babel-polyfill'
import {Autocomplete, InputField, SSRProvider, TextInput, TextInputWithTokens} from '..'
import {Autocomplete, SSRProvider, TextInput, TextInputWithTokens} from '../../'
import InputField from '../../deprecated/InputField'
expect.extend(toHaveNoViolations)

const TEXTINPUTFIELD_LABEL_TEXT = 'Name'
Expand Down
8 changes: 5 additions & 3 deletions src/FormGroup.tsx → src/deprecated/FormGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import styled from 'styled-components'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'

const FormGroup = styled.div<SxProp>`
margin: ${get('space.3')} 0;
font-weight: ${get('fontWeights.normal')};
${sx};
`

/** @deprecated Use FormControl instead. See https://primer.style/react/FormControl for more details. */
const FormGroupLabel = styled.label<SxProp>`
display: block;
margin: 0 0 ${get('space.2')};
Expand All @@ -21,4 +22,5 @@ FormGroupLabel.displayName = 'FormGroup.Label'

export type FormGroupProps = ComponentProps<typeof FormGroup>
export type FormGroupLabelProps = ComponentProps<typeof FormGroupLabel>
/** @deprecated Use FormControl instead. See https://primer.style/react/FormControl for more details. */
export default Object.assign(FormGroup, {Label: FormGroupLabel})
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import {Autocomplete, Box, Select, TextInput, TextInputWithTokens, useSSRSafeId} from '..'
import InputValidation from '../_InputValidation'
import {ComponentProps} from '../utils/types'
import {FormValidationStatus} from '../utils/types/FormValidationStatus'
import {Autocomplete, Box, Select, TextInput, TextInputWithTokens, useSSRSafeId} from '../../'
import InputValidation from '../../_InputValidation'
import {ComponentProps} from '../../utils/types'
import {FormValidationStatus} from '../../utils/types/FormValidationStatus'
import InputFieldCaption from './_InputFieldCaption'
import InputFieldLabel from './_InputFieldLabel'
import InputFieldValidation from './_InputFieldValidation'
import {Slots} from './slots'
import ValidationAnimationContainer from '../_ValidationAnimationContainer'
import ValidationAnimationContainer from '../../_ValidationAnimationContainer'
export interface Props<T = Record<string, FormValidationStatus>> {
children?: React.ReactNode
/**
Expand Down Expand Up @@ -40,6 +40,7 @@ export interface InputFieldContext
validationMessageId: string
}

/** @deprecated Use FormControl instead. See https://primer.style/react/FormControl for more details. */
const InputField = <T extends Record<string, FormValidationStatus>>({
children,
disabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import InputCaption from '../_InputCaption'
import InputCaption from '../../_InputCaption'
import {InputFieldContext} from './InputField'
import {Slot} from './slots'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import InputLabel from '../_InputLabel'
import InputLabel from '../../_InputLabel'
import {InputFieldContext} from './InputField'
import {Slot} from './slots'

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import createSlots from '../utils/create-slots'
import createSlots from '../../utils/create-slots'

export const {Slots, Slot} = createSlots(['Caption', 'Input', 'Label', 'LeadingVisual'])
3 changes: 3 additions & 0 deletions src/deprecated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export type {
DropdownItemProps,
DropdownMenuProps
} from '../Dropdown'
export {default as FormGroup} from './FormGroup'
export type {FormGroupProps, FormGroupLabelProps} from './FormGroup'
export {default as InputField} from './InputField'
export {default as SelectMenu} from '../SelectMenu'
export type {
SelectMenuProps,
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ export type {FilterListProps, FilterListItemProps} from './FilterList'
export {default as Flash} from './Flash'
export type {FlashProps} from './Flash'
export {default as FormControl} from './FormControl'
export {default as FormGroup} from './FormGroup'
export type {FormGroupProps, FormGroupLabelProps} from './FormGroup'
export {default as Header} from './Header'
export type {HeaderProps, HeaderItemProps, HeaderLinkProps} from './Header'
export {default as Heading} from './Heading'
export type {HeadingProps} from './Heading'
export {default as InputField} from './InputField'
export {default as LabelGroup} from './LabelGroup'
export type {LabelGroupProps} from './LabelGroup'
export {default as Label} from './Label'
Expand Down