Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@material/mwc-checkbox

Package Overview
Dependencies
Maintainers
20
Versions
721
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/mwc-checkbox

Material Design checkbox web component

  • 0.19.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3K
decreased by-57.71%
Maintainers
20
Weekly downloads
 
Created
Source

<mwc-checkbox> Published on npm

IMPORTANT: The Material Web Components are a work in progress and subject to major changes until 1.0 release.

Checkboxes allow the user to select one or more items from a set. Checkboxes can be used to turn an option on or off.

Material Design Guidelines: Checkboxes

Demo

Installation

npm install @material/mwc-checkbox

NOTE: The Material Web Components are distributed as ES2017 JavaScript Modules, and use the Custom Elements API. They are compatible with all modern browsers including Chrome, Firefox, Safari, Edge, and IE11, but an additional tooling step is required to resolve bare module specifiers, as well as transpilation and polyfills for IE11. See here for detailed instructions.

Example usage

Standard

<mwc-checkbox checked></mwc-checkbox>

<script type="module">
  import '@material/mwc-checkbox';

  const checkbox = document.body.querySelector('mwc-checkbox')
  checkbox.addEventListener('change', () => {
    console.log(`checkbox changed to ${checkbox.checked}`);
  });
</script>

Standard, disabled

<div>
  <mwc-checkbox></mwc-checkbox>
  <mwc-checkbox checked></mwc-checkbox>
  <mwc-checkbox indeterminate></mwc-checkbox>
</div>

<div>
  <mwc-checkbox disabled></mwc-checkbox>
  <mwc-checkbox disabled checked></mwc-checkbox>
  <mwc-checkbox disabled indeterminate></mwc-checkbox>
</div>

Styled standard, disabled

<style>
  body {
    background-color: #363636;

    --mdc-theme-secondary: #ff2929;
    --mdc-checkbox-unchecked-color: white;
    /* Required for unchecked focus ripple */
    --mdc-theme-on-surface: white;
    --mdc-checkbox-disabled-color: #adadad;
    --mdc-checkbox-ink-color: #363636;
  }
</style>

<div>
  <mwc-checkbox></mwc-checkbox>
  <mwc-checkbox checked></mwc-checkbox>
  <mwc-checkbox indeterminate></mwc-checkbox>
</div>

<div>
  <mwc-checkbox disabled></mwc-checkbox>
  <mwc-checkbox disabled checked></mwc-checkbox>
  <mwc-checkbox disabled indeterminate></mwc-checkbox>
</div>

With Form Field

Most applications should use <mwc-formfield> to associate an interactive label with the checkbox.

<style>
  mwc-formfield {
    display: block;
  }
  .child {
    margin-left: 20px;
  }
</style>

<mwc-formfield label="Additions">
  <mwc-checkbox indeterminate></mwc-checkbox>
</mwc-formfield>

<mwc-formfield label="Pickles">
  <mwc-checkbox class="child"></mwc-checkbox>
</mwc-formfield>

<mwc-formfield label="Tomato">
  <mwc-checkbox class="child" checked></mwc-checkbox>
</mwc-formfield>

<script type="module">
  import '@material/mwc-checkbox';
  import '@material/mwc-formfield';
</script>

API

Properties/Attributes

NameTypeDefaultDescription
checkedbooleanfalseWhether the checkbox is checked.
indeterminatebooleanfalseWhen a checkbox is the parent of a set of child checkboxes, the indeterminate state is used on the parent to indicate that some but not all of its children are checked.
disabledbooleanfalseWhen true, the checkbox cannot be interacted with, and renders in muted colors.
valuestring''The value that will be included if the checkbox is submitted in a form.
reducedTouchTargetbooleanfalseWhen true, the checkbox remove padding for touchscreens and increase density. Note, the checkbox will no longer meet accessibility guidelines for touch.

Methods

None

Events

Event NameTargetDetailDescription
changemwc-checkbox{}Fired when the user modifies the checkbox checked or indeterminate states from an input device interaction. Note that, like native <input>, the change event is not fired when the checked or indeterminate properties are set from JavaScript.

CSS Custom Properties

NameDefaultDescription
--mdc-checkbox-ink-color #fffColor of mark inside a checked or indeterminate checkbox (enabled or disabled).
--mdc-checkbox-unchecked-color rgba(0, 0, 0, 0.54)Color of the unchecked box.
--mdc-checkbox-disabled-color rgba(0, 0, 0, 0.38)Color of the checkbox box and fill when disabled.
Global Custom Properties

This component exposes the following global theming custom properties.

NameDescription
--mdc-theme-secondaryBackground color when the checkbox is checked or indeterminate, and the base color of the ripple effect and focus halo.
--mdc-theme-on-surfaceColor of mark inside a checked or indeterminate checkbox (enabled or disabled).

Additional references

Keywords

FAQs

Package last updated on 08 Oct 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc