npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jb-checkbox

v1.3.0

Published

checkbox web component

Downloads

570

Readme

jb-checkbox

Published on webcomponents.org GitHub license NPM Version GitHub Created At

Checkbox web component with smooth check animation.

  • Customizable UI with CSS variables and CSS parts.
  • Form-associated checkbox value.
  • Built-in required and external error validation.
  • Custom validation through jb-validation.

demo

When to use

Use jb-checkbox for a single boolean option that needs JB Design System styling, validation, form association, disabled state, or custom label markup.

For multiple related choices, render a list of jb-checkbox elements with different name or value handling based on your form model.

Demo

Using With JS Frameworks

Installation

npm i jb-checkbox
import 'jb-checkbox';
<jb-checkbox label="Accept terms"></jb-checkbox>

Use the label slot when the label needs custom markup:

<jb-checkbox>
  <span slot="label">Accept <a href="/terms">terms</a></span>
</jb-checkbox>

API reference

Attributes

| name | type | default | description | | --- | --- | --- | --- | | value | boolean | false | Initial checked value attribute. Use value="true" for checked markup; omit the attribute or use the boolean value property for false/programmatic updates. | | label | string | "" | Text label. Use slot="label" for custom markup. | | message | string | "" | Helper text shown below the label when no validation error is visible. | | name | string | "" | Form field name. | | disabled | boolean | false | Disables user toggling and sets the disabled custom state. | | required | boolean \| string | false | Enables required validation. A string value is used as the required error message. | | error | string | "" | External validation error message used as a custom error. | | size | 'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl' | md style defaults | Visual size variant. |

Properties

| name | type | readonly | description | | --- | --- | --- | --- | | value | boolean | no | Boolean checked value. The native form value is set to "true" or "false". | | checked | boolean | yes | true when value is true. | | disabled | boolean | no | Disables user toggling and updates accessibility/custom state. | | required | boolean | no | Enables required validation. | | validation | ValidationHelper<boolean> | yes | Validation helper from jb-validation; set validation.list for custom rules. | | name | string | yes | Current name attribute value. | | initialValue | boolean | no | Baseline value used by isDirty. | | isDirty | boolean | yes | true when current value differs from initialValue. | | isAutoValidationDisabled | boolean | no | Compatibility flag for form input standards. | | validationMessage | string | yes | Current native validation message from ElementInternals. |

Methods

| name | returns | description | | --- | --- | --- | | checkValidity() | boolean | Runs validation without showing the error message. | | reportValidity() | boolean | Runs validation and shows the first error message. | | focus(options?) | void | Focuses the checkbox control when it is not disabled. |

Events

| event | detail | description | | --- | --- | --- | | before-change | none | Cancelable event dispatched before toggling. During this event, event.target.value exposes the next value. | | change | none | Cancelable event dispatched after value changes. Prevent default to revert the toggle. | | load | none | Dispatched from connectedCallback before initProp. | | init | none | Dispatched from connectedCallback after initProp. |

Get and set value

Use the value property for controlled updates.

const checkbox = document.querySelector('jb-checkbox');

checkbox.value = true;
console.log(checkbox.checked); // true
checkbox.addEventListener('change', (event) => {
  console.log(event.target.value);
});

Disable checkbox

document.querySelector('jb-checkbox').disabled = true;
<jb-checkbox disabled></jb-checkbox>

Validation

jb-checkbox uses jb-validation. Built-in validation covers required and error; custom validations can be added with validation.list.

const checkbox = document.querySelector('jb-checkbox');

checkbox.validation.list = [
  {
    validator: (value) => value === true,
    message: 'You must check this before continuing',
  },
];

const isValid = checkbox.reportValidity();

Required Validation

<jb-checkbox required label="Accept terms"></jb-checkbox>
<jb-checkbox required="Please accept terms" label="Accept terms"></jb-checkbox>

External error

Set the error attribute when an external validation system owns the error state.

<jb-checkbox error="Please accept terms" label="Accept terms"></jb-checkbox>

Sizes

<jb-checkbox size="sm" label="Small checkbox"></jb-checkbox>

Supported size values are xs, sm, md, lg, and xl.

Slots

| slot | description | | --- | --- | | label | Custom label content rendered next to the checkbox. |

CSS parts and states

| part | description | | --- | --- | | checkbox | The checkbox SVG element. | | check-bg | The checkbox background rectangle. | | check-mark | The animated check mark path. | | label | The label slot. | | message | The helper or validation message. |

| custom state | description | | --- | --- | | checked | Applied when value is true. | | disabled | Applied when disabled is true. | | invalid | Applied while a validation error is visible. |

jb-checkbox::part(label) {
  font-weight: 600;
}

jb-checkbox:state(checked)::part(label) {
  color: var(--jb-text-primary);
}

jb-checkbox:state(invalid)::part(message) {
  font-weight: 600;
}

Custom style

For complete styling guidance, live examples, CSS parts, custom states, variables, and copyable style recipes, see Styling.

Accessibility notes

  • The component uses ElementInternals.role = "checkbox" where supported.
  • The label attribute is exposed as ariaLabel.
  • ariaChecked is synchronized with the current checked value.
  • disabled, checked, and invalid states are synchronized with ElementInternals custom states where supported.
  • The form property returns the associated form from ElementInternals.
  • The shadow root uses delegatesFocus; calling focus() focuses the internal checkbox wrapper when the component is not disabled.
  • Pressing Space toggles the checkbox when it is focused and not disabled.
  • Disabled checkboxes are removed from the internal tab order.
  • The component is form-associated and sets its form value to the string "true" or "false".

Related Docs

AI agent notes

  • Import jb-checkbox once before using <jb-checkbox>.
  • Use the boolean value property for controlled state. Avoid relying on value="false" as an HTML attribute.
  • Read event.target.value in before-change for the next value and in change for the committed value.
  • Use required, error, and validation.list for validation.
  • Use slot="label" for custom label markup.
  • Style with CSS variables, ::part(...), and :state(checked|disabled|invalid).
  • This package includes custom-elements.json and points to it with the package.json customElements field. The field is documented by the Custom Elements Manifest project in Referencing manifests from npm packages.
  • In custom-elements.json, exports.kind: "js" describes the JavaScript/TypeScript class export and exports.kind: "custom-element-definition" maps the jb-checkbox tag name to that class.