Socket
Socket
Sign inDemoInstall

@material/mwc-radio

Package Overview
Dependencies
20
Maintainers
15
Versions
721
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @material/mwc-radio

Material Design radio web component


Version published
Weekly downloads
8.4K
decreased by-25.52%
Maintainers
15
Install size
4.56 MB
Created
Weekly downloads
 

Readme

Source

<mwc-radio> Published on npm

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

Radio buttons allow the user to select one option from a set. Use radio buttons when the user needs to see all available options.

Material Design Guidelines: Radio buttons

Installation

npm install @material/mwc-radio

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-radio name="myGroup" value="value1"></mwc-radio>
<mwc-radio name="myGroup" value="value2" checked></mwc-radio>

<script type="module">
  import '@material/mwc-radio/mwc-radio.js';
</script>

Custom color

<style>
mwc-radio {
  background-color: #363636;

  --mdc-theme-secondary: #ff2929;
  --mdc-radio-unchecked-color: white;
}
</style>

<mwc-radio name="myGroup" checked></mwc-radio>
<mwc-radio name="myGroup"></mwc-radio>

Disabled custom color

<style>
mwc-radio {
  background-color: #363636;

  --mdc-radio-disabled-color: #adadad;
}
</style>

<mwc-radio disabled name="myGroup"></mwc-radio>
<mwc-radio disabled name="myGroup" checked></mwc-radio>

With Form Field

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

<style>
  mwc-formfield {
    display: block;
  }
</style>

<mwc-formfield label="Home">
  <mwc-radio name="location"></mwc-radio>
</mwc-formfield>

<mwc-formfield label="Work">
  <mwc-radio name="location"></mwc-radio>
</mwc-formfield>

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

API

Slots

None

Properties/Attributes

NameTypeDefaultDescription
checkedbooleanfalseWhether this radio button is the currently-selected one in its group. Maps to the native checked attribute.
disabledbooleanfalseIf true, this radio button cannot be selected or de-selected. Maps to the native disabled attribute.
namestring''Name of the input for form submission, and identifier for the selection group. Only one radio button can be checked for a given selection group. Maps to the native name attribute.
valuestring''Value of the input for form submission. Maps to the native value attribute.
globalbooleanfalseIf true, this radio button will use a global, document-level scope for its selection group rather than its local shadow root.
reducedTouchTargetbooleanfalseWhen true, the radio removes touch target that extends beyond visual boundary of the component. Set to false by default to meet Material accessibility guidelines.

Methods

None

Events

NameDetailDescription
change{}Fired when the user modifies the radio checked state from an input device interaction on this radio. Note that, like native <input>, the change event is not fired when the checked property is set from JavaScript, nor is it fired when another radio in the same group becomes checked.

CSS Custom Properties

NameDefaultDescription
--mdc-radio-unchecked-color rgba(0, 0, 0, 0.54)Color of the ring of an unchecked radio.
--mdc-radio-disabled-color rgba(0, 0, 0, 0.38)Color of the ring and circle of a disabled radio.
Global Custom Properties

This component exposes the following global theming custom properties.

NameDescription
--mdc-theme-secondaryColor of the radio button.

Additional references

Keywords

FAQs

Last updated on 12 Aug 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc