Skip to content

Add Checkbox form component #1606

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 27 commits into from
Nov 24, 2021
Merged

Conversation

rezrah
Copy link
Contributor

@rezrah rezrah commented Nov 15, 2021

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

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

@changeset-bot
Copy link

changeset-bot bot commented Nov 15, 2021

🦋 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
Name Type
@primer/components Minor

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

github-actions bot commented Nov 15, 2021

size-limit report 📦

Path Size
dist/browser.esm.js 57.31 KB (+0.38% 🔺)
dist/browser.umd.js 57.72 KB (+0.41% 🔺)

@rezrah rezrah changed the title Feature/add native checkbox form component Add Checkbox form component Nov 15, 2021
@mperrotti mperrotti self-requested a review November 15, 2021 18:34
Copy link
Contributor

@mperrotti mperrotti left a comment

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.

@rezrah rezrah marked this pull request as ready for review November 19, 2021 17:45
@rezrah rezrah requested a review from a team November 19, 2021 17:45
aria-disabled={disabled ? 'true' : 'false'}
ref={ref || checkboxRef}
checked={indeterminate ? false : checked}
aria-checked={indeterminate ? 'mixed' : checked ? 'true' : 'false'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

/**
* An accessible, native checkbox component
*/
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
Copy link
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
Contributor Author

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.

@@ -169,4 +169,7 @@ export type {TruncateProps} from './Truncate'
export {default as UnderlineNav} from './UnderlineNav'
export type {UnderlineNavProps, UnderlineNavLinkProps} from './UnderlineNav'

export {default as Checkbox} from './Checkbox'
Copy link
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
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.


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
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
Contributor Author

Choose a reason for hiding this comment

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

Moved and content updated 👍

Copy link
Contributor

@colebemis colebemis left a comment

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 main Nov 24, 2021
@rezrah rezrah deleted the feature/add-native-checkbox-form-component branch November 24, 2021 09:52
@primer-css primer-css mentioned this pull request Nov 24, 2021
pksjce pushed a commit that referenced this pull request Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants