Socket
Socket
Sign inDemoInstall

@accessible/checkbox

Package Overview
Dependencies
7
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @accessible/checkbox

🅰 An accessible and versatile checkbox component for React


Version published
Weekly downloads
218
increased by18.48%
Maintainers
1
Install size
165 kB
Created
Weekly downloads
 

Changelog

Source

4.0.2 (2021-01-20)

Bug Fixes

  • update switch package to fix bug in controlled checkbox (e643429)

Readme

Source

<Checkbox>

Bundlephobia Types Code coverage Build status NPM Version MIT License

npm i @accessible/checkbox

An accessible checkbox component for React. This library allows you to create your own a checkbox with your own styles while maintaining the ability to focus and update a checkbox input with the keyboard.

Quick Start

Check out the example on CodeSandbox

import {Checkbox, Checkmark} from '@accessible/checkbox'

const MyCheckbox = () => (
  <label className='my-checkbox'>
    <Checkbox name='my-field-name'>
      <span className='my-checkbox'>
        <Checkmark checkedClass='checked' uncheckedClass='unchecked'>
          <span className='checkmark' />
        </Checkmark>
      </span>
    </Checkbox>
    Check me!
  </label>
)

API

<Checkbox>

Creates a visually hidden checkbox input that is focusable and accessible via keyboard navigation. All props passed to this component are applied to the <input>. This also creates a context provider enabling the other components in this library to access the checkbox's state deep in the tree.

Props
PropTypeDefaultRequired?Description
checkedbooleanundefinedNoMakes the checkbox a controlled component which can no longer be updated with check, uncheck, and toggle controls.
defaultCheckedbooleanundefinedNoSet this to true to make the checkbox checked by default.
onChange(checked: boolean) => anyundefinedNoCalled each time the checked state changes.
childrenReact.ReactNodeundefinedNoYour custom styled checkbox.

<Checkmark>

A convenient component for conditionally adding class names and styles when the component is checked/unchecked.

Props
PropTypeDefaultRequired?Description
uncheckedClassstringundefinedNoThis class name will be applied to the child element when the checkbox is unchecked.
checkedClassstringundefinedNoThis class name will be applied to the child element when the checkbox is checked.
uncheckedStyleReact.CSSPropertiesundefinedNoThese styles will be applied to the child element when the checkbox is unchecked.
checkedStyleReact.CSSPropertiesundefinedNoThese styles name will be applied to the child element when the checkbox is checked.
childrenReact.ReactNodeundefinedYesThe child you wish to render when the checkbox is checked.

<Checked>

The child of this component will only render when the <Checkbox> is in a checked state. It must be a child of a <Checkbox>.

Props
PropTypeDefaultRequired?Description
childrenReact.ReactNodeundefinedYesThe child you wish to render when the checkbox is checked.

<Unchecked>

The child of this component will only render when the <Checkbox> is in an unchecked state. It must be a child of a <Checkbox>.

Props
PropTypeDefaultRequired?Description
childrenReact.ReactNodeundefinedYesThe child you wish to render when the checkbox is unchecked.

<Toggle>

This component clones its child and adds an onClick handler to toggle the <Checkbox> between checked and unchecked states. It must be a child of a <Checkbox>.

Props
PropTypeDefaultRequired?Description
childrenReact.ReactNodeundefinedYesThe child you wish to render when the checkbox is unchecked.

useCheckbox()

A React hook that returns the CheckboxContextValue for the nearest <Checkbox> parent.

CheckboxContextValue

interface CheckboxContextValue {
  // Does the checkbox have a `checked` property?
  checked: boolean
  // Is the checkbox currently focused?
  focused: boolean
  // Is the checkbox currently disabled?
  disabled: boolean
  // Checks the checkbox
  check: () => void
  // Unchecks the checkbox
  uncheck: () => void
  // Toggles the checkbox `checked` property
  toggle: () => void
}

LICENSE

MIT

Keywords

FAQs

Last updated on 20 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc