Skip to content

react-component/checkbox

Repository files navigation

@rc-component/checkbox

Ant Design Part of the Ant Design ecosystem.

☑️ A small, accessible checkbox primitive for React.

NPM version npm downloads build status Codecov bundle size dumi

English | 简体中文

Highlights

  • Works as a controlled or uncontrolled checkbox.
  • Exposes an imperative ref for focus, blur, and DOM access.
  • Keeps native input attributes available while normalizing the change event.
  • Ships compiled JavaScript, TypeScript definitions, and a standalone CSS asset.

Install

npm install @rc-component/checkbox

Usage

import Checkbox from '@rc-component/checkbox';
import '@rc-component/checkbox/assets/index.css';

export default function App() {
  return (
    <Checkbox
      defaultChecked
      onChange={(event) => {
        console.log(event.target.checked);
      }}
    />
  );
}

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Checkbox

Property Description Type Default
checked Whether the checkbox is checked boolean -
className Additional class name string -
defaultChecked Whether the checkbox is checked by default boolean false
disabled Whether the checkbox is disabled boolean false
name Same as native checkbox input name string -
prefixCls Component class name prefix string rc-checkbox
style Inline style for the wrapper React.CSSProperties -
type Native input type string checkbox
value Same as native checkbox input value string | number | readonly string[] -
onChange Callback when checked state changes (event: CheckboxChangeEvent) => void -

Other native input attributes are also supported.

Ref

Property Description Type
blur Remove focus from the checkbox () => void
focus Focus the checkbox (options?: FocusOptions) => void
input Native input element HTMLInputElement | null
nativeElement Wrapper element HTMLElement | null

Development

npm install
npm start

The dumi site runs at http://localhost:8000 by default.

npm test
npm run tsc
npm run lint
npm run compile
npm run build

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/checkbox is released under the MIT license.

About

☑️ A small, accessible checkbox primitive for React.

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

 
 
 

Contributors