Socket
Socket
Sign inDemoInstall

svelte-radio

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    svelte-radio

Composed Radio button group component for Svelte


Version published
Maintainers
1
Install size
64.7 kB
Created

Changelog

Source

1.0.0 - 2020-12-20

  • remove default export; export Radio, RadioGroup individually
  • add TypeScript definitions

Readme

Source

svelte-radio

NPM Build

Composed Radio button group component for Svelte.

Install

yarn add -D svelte-radio
# OR
npm i -D svelte-radio

Usage

<script>
  import { RadioGroup, Radio } from "svelte-radio";

  let value = "1";
</script>

<RadioGroup bind:value label="Radio group legend">
  <Radio label="Label 1" value="1" />
  <Radio label="Label 2" value="2" />
  <Radio label="Label 3" value="3" />
</RadioGroup>

value:
{value}

<div>
  <button
    type="button"
    on:click={() => {
      value = '2';
    }}
  >Set value to "2"</button>
</div>

Styling

This component is unstyled by design. Use a global class selector to style the .svelte-radio-group and .svelte-radio classes.

<style>
  :global(.svelte-radio-group) {
    border: 2px solid #e0e0e0;
    padding: 1rem;
  }

  :global(.svelte-radio) {
    margin-bottom: 0.5rem;
  }

  :global(.svelte-radio label) {
    margin-left: 0.25rem;
  }
</style>

API

RadioGroup

Prop nameValue
legendstring
valuestring or number (default: undefined)
...$$restProps(forward to the top-level fieldset element)

Radio

Prop nameValue
labelstring
valuestring or number (default: undefined)
checkedboolean (default: false
...$$restProps(forward to the second-level input element)

Dispatched events

Radio.Group

Event nameDescription
on:changetriggered if the selection changes
<RadioGroup
  bind:value
  label="Radio group legend"
  on:change={(e) => {
    console.log(e.detail);
  }}
>
  <Radio label="Label 1" value="1" />
  <Radio label="Label 2" value="2" />
  <Radio label="Label 3" value="3" />
</RadioGroup>

TypeScript support

Svelte version 3.31 or greater is required to use this module with TypeScript.

Changelog

License

MIT

Keywords

FAQs

Last updated on 20 Dec 2020

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