Skip to content

Latest commit

 

History

History
128 lines (98 loc) · 4.64 KB

File metadata and controls

128 lines (98 loc) · 4.64 KB

@rc-component/checkbox

☑️ A small, accessible checkbox primitive for React.

Ant Design

Part of the Ant Design ecosystem.

NPM version npm download build status Codecov bundle size dumi

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

npm install
npm start

Then open http://localhost:8000.

Online demo: https://react-component.github.io/checkbox/

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
npm test
npm run tsc
npm run lint
npm run compile
npm run build

Release

npm run prepublishOnly

The release script compiles the package and runs rc-np.

License

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