Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
107 changes: 107 additions & 0 deletions .changeset/olive-bears-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
'@primer/react': major
---

![image](https://user-images.githubusercontent.com/13340707/154948443-60d70cc7-4f26-444f-8366-7963336be53c.png)

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
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax highlighting looks a bit off in the snippet, might be this. could we turn this into a comment?


<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.


</td>
</tr>
</table>
16 changes: 8 additions & 8 deletions docs/content/InputField.mdx
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
2 changes: 2 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,7 @@
url: /deprecated/Dropdown
- title: FormGroup
url: /FormGroup
- 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: SelectMenu
url: /deprecated/SelectMenu
2 changes: 2 additions & 0 deletions src/FormGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'

/** @deprecated Use FormControl instead. See https://primer.style/react/FormControl for more details. */
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will apply the annotation correctly as the assignment is part of internal scope. I imagine we'd need to deprecate the following line instead on line 26.

export default Object.assign(FormGroup, {Label: FormGroupLabel})

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 Down
1 change: 1 addition & 0 deletions src/InputField/InputField.tsx
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion src/__tests__/InputField.test.tsx
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 '../InputField'
expect.extend(toHaveNoViolations)

const TEXTINPUTFIELD_LABEL_TEXT = 'Name'
Expand Down
1 change: 1 addition & 0 deletions src/deprecated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type {
DropdownItemProps,
DropdownMenuProps
} from '../Dropdown'
export {default as InputField} from '../InputField'
export {default as SelectMenu} from '../SelectMenu'
export type {
SelectMenuProps,
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ 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