Skip to content

Add Checkbox form component - #1606

Merged
rezrah merged 27 commits into
mainfrom
feature/add-native-checkbox-form-component
Nov 24, 2021
Merged

Add Checkbox form component#1606
rezrah merged 27 commits into
mainfrom
feature/add-native-checkbox-form-component

Conversation

@rezrah

@rezrahrezrah commented Nov 15, 2021

Copy link
Copy Markdown
Contributor

Checkbox ✅

Adds a native Checkbox component that provides a react abstraction over a native HTML checkbox input

Adapted from the Primer design guidelines for checkboxes

Before:
<input type="checkbox" />

After:
<Checkbox />

Try it here

Docs: https://primer-components-eo45yjh4t-primer.vercel.app/react/Checkbox
Storybook: https://primer-components-eo45yjh4t-primer.vercel.app/react/storybook?path=/story/forms-checkbox--default

Screenshots

Screenshot 2021-11-19 at 15 22 01

Screenshot 2021-11-19 at 15 21 08

Screenshot 2021-11-19 at 15 21 44

Screenshot 2021-11-19 at 15 20 51

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Resolveshttps://github.com/github/primer/issues/467
Contributes towards: https://github.com/github/primer/issues/432

@changeset-bot

changeset-botBot commented Nov 15, 2021

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3f1f8b8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
@primer/componentsMinor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actionsBot commented Nov 15, 2021

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js57.31 KB (+0.38% 🔺)
dist/browser.umd.js57.72 KB (+0.41% 🔺)

@rezrahrezrah changed the title Feature/add native checkbox form componentAdd Checkbox form componentNov 15, 2021
@mperrotti
mperrotti self-requested a review November 15, 2021 18:34

@mperrottimperrotti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is still in progress, I kept my feedback limited to the visual design and component API.

I'll review the code once we're further along.

Comment threadsrc/Checkbox.tsx Outdated
Comment threadsrc/Checkbox.tsx Outdated
Comment threadsrc/Checkbox.tsx Outdated
Comment threadsrc/Checkbox.tsx Outdated
Comment threadsrc/Checkbox.tsx Outdated
Comment threaddocs/content/Checkbox.md Outdated
Comment threadsrc/Checkbox.tsx Outdated
@rezrah
rezrah marked this pull request as ready for review November 19, 2021 17:45
@rezrah
rezrah requested a review from a teamNovember 19, 2021 17:45
Comment threadsrc/Checkbox.tsx Outdated
Comment threadsrc/Checkbox.tsx
aria-disabled={disabled ? 'true' : 'false'}
ref={ref || checkboxRef}
checked={indeterminate ? false : checked}
aria-checked={indeterminate ? 'mixed' : checked ? 'true' : 'false'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice

Comment threadsrc/Checkbox.tsx
Comment threadsrc/Checkbox.tsx
/**
* An accessible, native checkbox component
*/
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need to use forwardRef?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It's there to make the checkbox more flexible when used in uncontrolled mode.

Comment threadsrc/index.ts
export {default as UnderlineNav} from './UnderlineNav'
export type {UnderlineNavProps, UnderlineNavLinkProps} from './UnderlineNav'

export {default as Checkbox} from './Checkbox'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any ideas how we could guard against engineers rendering a <Checkbox /> without a corresponding <label />?

I have some ideas, but it would be much easier to show over Zoom instead of text and pseudocode. Let me know if you want to chat on Monday.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Chatted with @rezrah about this: we're just going to check for an associated label with a linter instead of doing anything in the runtime.

Comment threaddocs/content/Checkbox.md Outdated
Comment threadsrc/Checkbox.tsx Outdated
Comment threadsrc/Checkbox.tsx Outdated
Comment threaddocs/content/Checkbox.md Outdated
Comment threaddocs/content/Checkbox.md
Comment threaddocs/content/Checkbox.md Outdated
Comment threaddocs/content/Checkbox.md Outdated

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

`Checkbox` is a form component that applies Primer design language to a native HTML checkbox input element.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we move this into the description frontmatter and reword it to be a little more actionable (see other component descriptions):

---
title: Checkbox
description: Use checkboxes to ...
---

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Moved and content updated 👍

Comment threaddocs/content/Checkbox.md Outdated

@colebemiscolebemis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@rezrah
rezrah merged commit 985120a into mainNov 24, 2021
@rezrah
rezrah deleted the feature/add-native-checkbox-form-component branch November 24, 2021 09:52
@primer-cssprimer-css mentioned this pull request Nov 24, 2021
pksjce pushed a commit that referenced this pull request Dec 20, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@rezrah@mperrotti@colebemis