Skip to content

Repository files navigation

@rc-component/checkbox

Ant Design Part of the Ant Design ecosystem.

☑️ A small, accessible checkbox primitive for React.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

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

importCheckboxfrom'@rc-component/checkbox';import'@rc-component/checkbox/assets/index.css';exportdefaultfunctionApp(){return(<CheckboxdefaultCheckedonChange={(event)=>{console.log(event.target.checked);}}/>);}

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Checkbox

PropertyDescriptionTypeDefault
checkedWhether the checkbox is checkedboolean-
classNameAdditional class namestring-
defaultCheckedWhether the checkbox is checked by defaultbooleanfalse
disabledWhether the checkbox is disabledbooleanfalse
nameSame as native checkbox input namestring-
prefixClsComponent class name prefixstringrc-checkbox
styleInline style for the wrapperReact.CSSProperties-
typeNative input typestringcheckbox
valueSame as native checkbox input valuestring | number | readonly string[]-
onChangeCallback when checked state changes(event: CheckboxChangeEvent) => void-

Other native input attributes are also supported.

Ref

PropertyDescriptionType
blurRemove focus from the checkbox() => void
focusFocus the checkbox(options?: FocusOptions) => void
inputNative input elementHTMLInputElement | null
nativeElementWrapper elementHTMLElement | 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

Stars

132 stars

Watchers

23 watching

Forks

Releases

Packages

Used by

Contributors

Languages