Skip to content
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

Input field components - text, checkbox, radio #1611

Merged
merged 74 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a23e32d
adds components and stories for basic usage
mperrotti Nov 12, 2021
779e5fe
supports checkbox and radio fields
mperrotti Nov 15, 2021
0ad2715
styles disabled label styles, adds stories, jsdocs props, cleanups
mperrotti Nov 16, 2021
f8668ce
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Nov 16, 2021
e0addd0
adds missing jsdoc comment
mperrotti Nov 16, 2021
0d3ae10
adds components to render groups of radios or checkboxes
mperrotti Nov 17, 2021
a67c80f
supports LeadingVisual for checkbox and radio inputs
mperrotti Nov 17, 2021
fe9696a
animate in field validation message
mperrotti Nov 17, 2021
dd08828
updates validation API
mperrotti Nov 19, 2021
6054f1c
creates text, checkbox, and radio input field components
mperrotti Nov 22, 2021
910ee68
makes InputField validation props smarter
mperrotti Nov 22, 2021
00ecaba
rm ChoiceFieldset from this changeset
mperrotti Nov 22, 2021
115bb4e
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Nov 22, 2021
fc84152
fixes ts errors
mperrotti Nov 22, 2021
f70f8ad
fixes bad imports
mperrotti Nov 22, 2021
793c00d
cleanup
mperrotti Nov 22, 2021
e50bde8
adds VisuallyHidden component
mperrotti Nov 22, 2021
e9bcee9
require label to be passed
mperrotti Nov 23, 2021
4533f20
fixes typo from last commit
mperrotti Nov 23, 2021
ad1c9e8
adds React component docs for TextInputField, RadioInputField, and Ch…
mperrotti Nov 23, 2021
024b5d3
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Nov 23, 2021
006e976
adds tests, fixes check for Label slot
mperrotti Nov 24, 2021
79c2286
warns if id, required, or disabled props are passed directly to the I…
mperrotti Nov 24, 2021
581b4ca
fix issue where the input still had a top margin when the label was h…
mperrotti Nov 24, 2021
54b43a4
marks new internal components as private
mperrotti Nov 24, 2021
7b7c1f8
adds changeset
mperrotti Nov 24, 2021
0a220ad
updates imports
mperrotti Nov 24, 2021
6ea5201
Merge github.com:primer/react into mp/form-field-component
mperrotti Nov 24, 2021
504a9d9
updates stories and docs
mperrotti Nov 24, 2021
d721895
Merge github.com:primer/react into mp/form-field-component
mperrotti Nov 24, 2021
e5a964f
adds React component docs to doc nav, updates docs
mperrotti Nov 24, 2021
15da266
updates CheckboxInputField to use new Checkbox component
mperrotti Nov 24, 2021
cbab1ae
updates snapshots from using checkbox component
mperrotti Nov 24, 2021
ec1312a
Merge branch 'main' into mp/form-field-component
mperrotti Nov 24, 2021
b092729
Merge github.com:primer/react into mp/form-field-component
mperrotti Nov 30, 2021
6577aa8
Merge branch 'main' into mp/form-field-component
mperrotti Nov 30, 2021
7424440
lightens caption when field is disabled
mperrotti Nov 30, 2021
69334dc
removes unusable export from checkbox and radio input fields
mperrotti Nov 30, 2021
2691adc
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Nov 30, 2021
4b20f1a
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 3, 2021
b137a07
updates Checkbox docs to point to CheckboxInputField
mperrotti Dec 3, 2021
3c18363
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 6, 2021
4e06ca7
uses new Radio component to render the input
mperrotti Dec 6, 2021
a179e92
Merge branch 'main' into mp/form-field-component
mperrotti Dec 8, 2021
73285ba
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 13, 2021
98a67e8
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 13, 2021
b6781f4
fixes bad import
mperrotti Dec 13, 2021
ff79a52
uses new package name
mperrotti Dec 13, 2021
f4ff5c8
replaces CheckboxInputField and RadioInputField with 1 component - Ch…
mperrotti Dec 13, 2021
58efa2b
replaces TextInputField component with InputField component
mperrotti Dec 13, 2021
c6c2062
updates documentation formatting
mperrotti Dec 13, 2021
e3f7a6e
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 13, 2021
e283cbe
more docs updates
mperrotti Dec 14, 2021
05f96dd
Merge branch 'main' into mp/form-field-component
mperrotti Dec 14, 2021
c1c4808
Update docs/content/Checkbox.md
mperrotti Dec 15, 2021
ce49a84
addresses PR feedback + misc cleanup
mperrotti Dec 15, 2021
6a7bb75
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 16, 2021
12d8047
TESTING DEPLOYMENT - revert InputField.mdx to last successful build
mperrotti Dec 16, 2021
fd269bf
Merge branch 'main' into mp/form-field-component
mperrotti Dec 16, 2021
73ad10c
attempting to get InputField docs to build
mperrotti Dec 16, 2021
5c56710
attempting to get InputField docs to build
mperrotti Dec 16, 2021
b42dc39
attempting to get InputField docs to build
mperrotti Dec 16, 2021
03156ef
probably fixed deployment
mperrotti Dec 16, 2021
00f5ff2
Merge branch 'main' into mp/form-field-component
mperrotti Dec 16, 2021
50a7f81
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 17, 2021
398e541
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 17, 2021
d6d3f03
Update docs/content/ChoiceInputField.mdx
mperrotti Dec 17, 2021
c17ec66
addresses more PR feedback
mperrotti Dec 17, 2021
a450bb8
Merge branch 'mp/form-field-component' of github.com:primer/react int…
mperrotti Dec 17, 2021
7e6da8a
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 17, 2021
4d04066
try adding componentchecklist import to fix deployment failure
mperrotti Dec 17, 2021
15bf95c
adds comopnentId to docs frontmatter
mperrotti Dec 17, 2021
709d5a9
Merge branch 'main' of github.com:primer/react into mp/form-field-com…
mperrotti Dec 17, 2021
ad9e954
Merge branch 'main' into mp/form-field-component
mperrotti Dec 17, 2021
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
5 changes: 5 additions & 0 deletions .changeset/afraid-tips-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

Adds TextInputField, CheckboxInputField, and RadioInputField components. Also adds a few internal (private to primer/react) components to support form fields
15 changes: 14 additions & 1 deletion docs/content/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ componentId: checkbox
title: Checkbox
description: Use checkboxes to toggle between checked and unchecked states in a list or as a standalone form field
status: Alpha
source: https://github.com/primer/react/blob/main/src/Checklist.tsx
source: https://github.com/primer/react/blob/main/src/Checkbox.tsx
storybook: '/react/storybook?path=/story/forms-checkbox--default'
---

import {ComponentChecklist} from '../src/component-checklist'

<Note variant="warning">

**Use [ChoiceInputField](/ChoiceInputField) to display an accessible checkbox form field**. This `Checkbox` component is intended only as an ingredient for other custom components, or as a drop-in replacement for native HTML checkboxes outside of form use-cases.


If you do use this component to build a custom checkbox, it should always be accompanied by a corresponding `<label>` to improve support for assistive technologies.

</Note>

## Default example

The `Checkbox` component can be used in controlled and uncontrolled modes.
Expand Down Expand Up @@ -117,3 +126,7 @@ items={{
hasFigmaComponent: false
}}
/>

## Related components

- [CheckboxInputField](/CheckboxInputField)
160 changes: 160 additions & 0 deletions docs/content/ChoiceInputField.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
title: ChoiceInputField
status: Alpha
mperrotti marked this conversation as resolved.
Show resolved Hide resolved
description: The ChoiceInputField component is used to render a labelled checkbox or radio inputs with optional hint text.
source: https://github.com/primer/react/blob/main/src/ChoiceInputField.tsx
storybook: '/react/storybook?path=/story/forms-choiceinputfield--checkbox-input-field'
---

import {ChoiceInputField, Checkbox, Radio} from '@primer/react'
import {MarkGithubIcon} from '@primer/octicons-react'
import {PropsTable} from '../src/props-table'
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these imports may not be needed anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see what I can get rid of. When I excluded the PropsTable import, it caused a deployment error in Vercel.

import {ComponentChecklist} from '../src/component-checklist'

## Examples

### Checkbox

```jsx live
<ChoiceInputField>
<ChoiceInputField.Label>Option one</ChoiceInputField.Label>
<Checkbox />
</ChoiceInputField>
```

### Radio

```jsx live
<fieldset style={{margin: 0, padding: 0, border: 0}}>
<ChoiceInputField>
<ChoiceInputField.Label>Option one</ChoiceInputField.Label>
<Radio name="radioExample" value="one" />
</ChoiceInputField>
<ChoiceInputField>
<ChoiceInputField.Label>Option two</ChoiceInputField.Label>
<Radio name="radioExample" value="two" />
</ChoiceInputField>
</fieldset>
```

### Disabled field

```jsx live
<ChoiceInputField disabled>
<ChoiceInputField.Label>Option one</ChoiceInputField.Label>
<Checkbox />
</ChoiceInputField>
```

### With a caption

```jsx live
<ChoiceInputField>
<ChoiceInputField.Label>Option One</ChoiceInputField.Label>
<Checkbox />
<ChoiceInputField.Caption>Hint: the first and only option</ChoiceInputField.Caption>
</ChoiceInputField>
```

### With a LeadingVisual

```jsx live
<>
<ChoiceInputField>
<ChoiceInputField.Label>Option one</ChoiceInputField.Label>
<ChoiceInputField.LeadingVisual>
<MarkGithubIcon />
</ChoiceInputField.LeadingVisual>
<Checkbox />
</ChoiceInputField>

<ChoiceInputField>
<ChoiceInputField.Label>Option two</ChoiceInputField.Label>
<ChoiceInputField.LeadingVisual>
<MarkGithubIcon />
</ChoiceInputField.LeadingVisual>
<Checkbox />
<ChoiceInputField.Caption>This one has a caption</ChoiceInputField.Caption>
</ChoiceInputField>
</>
```

## Props

### ChoiceInputField

The container that handles the layout and passes the relevant IDs and ARIA attributes it's children.

`ChoiceInputField.Label` and `ChoiceInputField.Input` are required children.

<PropsTable>
<PropsTable.Row
name="children"
type="ChoiceInputField.Label | ChoiceInputField.Caption | ChoiceInputField.LeadingVisual | Checkbox | Radio"
required
/>
<PropsTable.Row
name="disabled"
type="boolean"
defaultValue="false"
description="Whether the field is ready for user input"
/>
<PropsTable.Row
name="id"
type="string"
defaultValue="a generated string"
description="The unique identifier for this field. Used to associate the label, validation text, and caption text"
/>
</PropsTable>

### ChoiceInputField.Label

A `ChoiceInputField.Label` must be passed, but it may be visually hidden.

<PropsTable>
<PropsTable.Row name="children" type="React.ReactNode" description="The title that describes the choice input" />
</PropsTable>

### ChoiceInputField.Caption

If this field needs additional context, a `ChoiceInputField.Caption` may be used to render hint text.

<PropsTable>
<PropsTable.Row
name="children"
type="React.ReactNode"
description="The content (usually just text) that is rendered to give contextual info about the field"
/>
</PropsTable>

### ChoiceInputField.LeadingVisual

If the selectable option would be easier to understand with a visual, the `ChoiceInputField.LeadingVisual` component may be used.

<PropsTable>
<PropsTable.Row
name="children"
type="React.ReactNode"
description="The visual to render before the choice input's label"
/>
</PropsTable>

## Status

<ComponentChecklist
items={{
propsDocumented: true,
noUnnecessaryDeps: true,
adaptsToThemes: true,
adaptsToScreenSizes: true,
fullTestCoverage: true,
usedInProduction: false,
usageExamplesDocumented: true,
designReviewed: false,
a11yReviewed: true,
stableApi: false,
addressedApiFeedback: false,
hasDesignGuidelines: false,
hasFigmaComponent: false
}}
/>
Loading